diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-08-24 15:19:28 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-08-30 16:55:25 +0200 |
commit | bf32163059811c822c46e2e17142f517cf9a0bac (patch) | |
tree | c20510bc95748dfa6d00c8c1244f90c34e3ed18e /source/tools/murun.c | |
parent | d88fc90e806a72f90667ec780f3370794cbc0c42 (diff) | |
download | mupdf-bf32163059811c822c46e2e17142f517cf9a0bac.tar.xz |
js: Add PDFObject.length and PDFObject.push() to handle arrays.
Diffstat (limited to 'source/tools/murun.c')
-rw-r--r-- | source/tools/murun.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c index 12c274d1..0d208cad 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -2723,7 +2723,16 @@ static int ffi_pdf_obj_has(js_State *J, void *obj, const char *key) { fz_context *ctx = js_getcontext(J); pdf_obj *val; - int idx; + int idx, len; + + if (!strcmp(key, "length")) { + fz_try(ctx) + len = pdf_array_len(ctx, obj); + fz_catch(ctx) + rethrow(J); + js_pushnumber(J, len); + return 1; + } if (is_number(key, &idx)) { fz_try(ctx) @@ -3225,6 +3234,20 @@ static void ffi_PDFObject_delete(js_State *J) ffi_pdf_obj_delete(J, obj, key); } +static void ffi_PDFObject_push(js_State *J) +{ + fz_context *ctx = js_getcontext(J); + pdf_obj *obj = js_touserdata(J, 0, "pdf_obj"); + pdf_document *pdf = pdf_get_bound_document(ctx, obj); + pdf_obj *item = ffi_toobj(J, pdf, 1); + fz_try(ctx) + pdf_array_push(ctx, obj, item); + fz_always(ctx) + pdf_drop_obj(ctx, item); + fz_catch(ctx) + rethrow(J); +} + static void ffi_PDFObject_resolve(js_State *J) { fz_context *ctx = js_getcontext(J); @@ -3758,6 +3781,7 @@ int murun_main(int argc, char **argv) { jsB_propfun(J, "PDFObject.get", ffi_PDFObject_get, 0); jsB_propfun(J, "PDFObject.put", ffi_PDFObject_put, 0); + jsB_propfun(J, "PDFObject.push", ffi_PDFObject_push, 0); jsB_propfun(J, "PDFObject.delete", ffi_PDFObject_delete, 0); jsB_propfun(J, "PDFObject.resolve", ffi_PDFObject_resolve, 0); jsB_propfun(J, "PDFObject.toString", ffi_PDFObject_toString, 1); |