diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2012-09-06 15:10:26 +0100 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2012-09-18 14:59:55 +0100 |
commit | e6ed164c3935160d3d42aa15017abe2863bbdaac (patch) | |
tree | f8f3c4dd1b61b55d41c7300a1e3c2b67f58671f5 /pdf | |
parent | c06c3f6183eb6e7955749c060abe99e0b91ea1f7 (diff) | |
download | mupdf-e6ed164c3935160d3d42aa15017abe2863bbdaac.tar.xz |
Forms: support property access in the javascript engine
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/mupdf-internal.h | 2 | ||||
-rw-r--r-- | pdf/pdf_jsimp_cpp.c | 10 | ||||
-rw-r--r-- | pdf/pdf_jsimp_cpp.h | 1 | ||||
-rw-r--r-- | pdf/pdf_jsimp_v8.cpp | 16 |
4 files changed, 24 insertions, 5 deletions
diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h index 347f74b5..1d1fd4e7 100644 --- a/pdf/mupdf-internal.h +++ b/pdf/mupdf-internal.h @@ -690,6 +690,8 @@ double pdf_jsimp_to_number(pdf_jsimp *imp, pdf_jsimp_obj *obj); int pdf_jsimp_array_len(pdf_jsimp *imp, pdf_jsimp_obj *obj); pdf_jsimp_obj *pdf_jsimp_array_item(pdf_jsimp *imp, pdf_jsimp_obj *obj, int i); +pdf_jsimp_obj *pdf_jsimp_property(pdf_jsimp *imp, pdf_jsimp_obj *obj, char *prop); + void pdf_jsimp_execute(pdf_jsimp *imp, char *code); void pdf_jsimp_execute_count(pdf_jsimp *imp, char *code, int count); diff --git a/pdf/pdf_jsimp_cpp.c b/pdf/pdf_jsimp_cpp.c index 90f2a6e8..d47ffc8d 100644 --- a/pdf/pdf_jsimp_cpp.c +++ b/pdf/pdf_jsimp_cpp.c @@ -153,6 +153,16 @@ pdf_jsimp_obj *pdf_jsimp_array_item(pdf_jsimp *imp, pdf_jsimp_obj *obj, int i) return item; } +pdf_jsimp_obj *pdf_jsimp_property(pdf_jsimp *imp, pdf_jsimp_obj *obj, char *prop) +{ + pdf_jsimp_obj *pobj = NULL; + const char *err = pdf_jsimp_property_cpp(imp, obj, prop, &pobj); + if (err != NULL) + fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + + return pobj; +} + void pdf_jsimp_execute(pdf_jsimp *imp, char *code) { const char *err = pdf_jsimp_execute_cpp(imp, code); diff --git a/pdf/pdf_jsimp_cpp.h b/pdf/pdf_jsimp_cpp.h index 01b87edd..a35e9733 100644 --- a/pdf/pdf_jsimp_cpp.h +++ b/pdf/pdf_jsimp_cpp.h @@ -19,6 +19,7 @@ const char *pdf_jsimp_from_number_cpp(pdf_jsimp *imp, double num, pdf_jsimp_obj const char *pdf_jsimp_to_number_cpp(pdf_jsimp *imp, pdf_jsimp_obj *obj, double *num); const char *pdf_jsimp_array_len_cpp(pdf_jsimp *imp, pdf_jsimp_obj *obj, int *len); const char *pdf_jsimp_array_item_cpp(pdf_jsimp *imp, pdf_jsimp_obj *obj, int i, pdf_jsimp_obj **item); +const char *pdf_jsimp_property_cpp(pdf_jsimp *imp, pdf_jsimp_obj *obj, char *prop, pdf_jsimp_obj **pobj); const char *pdf_jsimp_execute_cpp(pdf_jsimp *imp, char *code); const char *pdf_jsimp_execute_count_cpp(pdf_jsimp *imp, char *code, int count); diff --git a/pdf/pdf_jsimp_v8.cpp b/pdf/pdf_jsimp_v8.cpp index 78a14eac..47fab860 100644 --- a/pdf/pdf_jsimp_v8.cpp +++ b/pdf/pdf_jsimp_v8.cpp @@ -411,17 +411,23 @@ extern "C" const char *pdf_jsimp_to_number_cpp(pdf_jsimp *imp, pdf_jsimp_obj *ob extern "C" const char *pdf_jsimp_array_len_cpp(pdf_jsimp *imp, pdf_jsimp_obj *obj, int *len) { - Local<Value> val = reinterpret_cast<PDFJSImpObject *>(obj)->toValue()->ToObject(); - Local<Array> arr = Local<Array>::Cast(val); + Local<Object> jsobj = reinterpret_cast<PDFJSImpObject *>(obj)->toValue()->ToObject(); + Local<Array> arr = Local<Array>::Cast(jsobj); *len = arr->Length(); return NULL; } extern "C" const char *pdf_jsimp_array_item_cpp(pdf_jsimp *imp, pdf_jsimp_obj *obj, int i, pdf_jsimp_obj **item) { - Local<Value> val = reinterpret_cast<PDFJSImpObject *>(obj)->toValue()->ToObject(); - Local<Array> arr = Local<Array>::Cast(val); - *item = reinterpret_cast<pdf_jsimp_obj *>(new PDFJSImpObject(arr->Get(Number::New(i)))); + Local<Object> jsobj = reinterpret_cast<PDFJSImpObject *>(obj)->toValue()->ToObject(); + *item = reinterpret_cast<pdf_jsimp_obj *>(new PDFJSImpObject(jsobj->Get(Number::New(i)))); + return NULL; +} + +extern "C" const char *pdf_jsimp_property_cpp(pdf_jsimp *imp, pdf_jsimp_obj *obj, char *prop, pdf_jsimp_obj **pobj) +{ + Local<Object> jsobj = reinterpret_cast<PDFJSImpObject *>(obj)->toValue()->ToObject(); + *pobj = reinterpret_cast<pdf_jsimp_obj *>(new PDFJSImpObject(jsobj->Get(String::New(prop)))); return NULL; } |