summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-01-06 14:02:33 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-01-06 14:02:33 +0100
commit46235ec8cfad7f4b601a19ac7874727bfac8a84b (patch)
tree613fcd5573b341f6d1e186c381bfb308b7aeea97 /source
parenta135e87d96bcf33c27f633f0ecfc5d158a4e0571 (diff)
downloadmupdf-46235ec8cfad7f4b601a19ac7874727bfac8a84b.tar.xz
js: Fix error handling bugs and one scoping bug.
js_pcall was leaving crap on the stack in case of errors. AFSimple_Calculate needs access to the doc object, but cannot use the usual 'this' binding since it's a function. Add a global reference to the doc object MuPDF_Doc.
Diffstat (limited to 'source')
-rw-r--r--source/pdf/js/pdf-js.c15
-rw-r--r--source/pdf/js/pdf-util.js2
2 files changed, 14 insertions, 3 deletions
diff --git a/source/pdf/js/pdf-js.c b/source/pdf/js/pdf-js.c
index c03429a7..bc9fcae0 100644
--- a/source/pdf/js/pdf-js.c
+++ b/source/pdf/js/pdf-js.c
@@ -541,6 +541,9 @@ static void declare_dom(pdf_js *js)
addmethod(J, "Doc.mailDoc", doc_mailDoc, 6);
}
js_setregistry(J, "Doc");
+
+ js_getregistry(J, "Doc");
+ js_setglobal(J, "MuPDF_Doc"); /* for pdf-util.js use */
}
static void preload_helpers(pdf_js *js)
@@ -676,11 +679,19 @@ void pdf_js_execute(pdf_js *js, char *source)
{
if (js)
{
- puts(source);
if (js_ploadstring(js->imp, "[pdf]", source))
+ {
+ fz_warn(js->ctx, "%s", js_tostring(js->imp, -1));
+ js_pop(js->imp, 1);
return;
+ }
js_getregistry(js->imp, "Doc"); /* set 'this' to the Doc object */
- js_pcall(js->imp, 0);
+ if (js_pcall(js->imp, 0))
+ {
+ fz_warn(js->ctx, "%s", js_tostring(js->imp, -1));
+ js_pop(js->imp, 1);
+ return;
+ }
js_pop(js->imp, 1);
}
}
diff --git a/source/pdf/js/pdf-util.js b/source/pdf/js/pdf-util.js
index 9a62add0..299f80ac 100644
--- a/source/pdf/js/pdf-util.js
+++ b/source/pdf/js/pdf-util.js
@@ -819,7 +819,7 @@ function AFSimple_Calculate(op, list)
for (i = 0; i < list.length; i++)
{
- var field = getField(list[i]);
+ var field = MuPDF_Doc.getField(list[i]);
var value = Number(field.value);
switch (op)