JS - QuickJS sandbox initialization must be the last evaluated string (#12914)

- aims to fix issue #12912
This commit is contained in:
calixteman 2021-01-26 05:56:01 -08:00 committed by GitHub
parent a3f6882b06
commit 465697eb10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,21 +61,22 @@ class Sandbox {
if (TESTING) {
this._module.ccall("nukeSandbox", null, []);
}
const sandboxData = JSON.stringify(data);
const code = [
PDFJSDev.eval("PDF_SCRIPTING_JS_SOURCE"),
`pdfjsScripting.initSandbox({ data: ${sandboxData} })`,
];
const code = [PDFJSDev.eval("PDF_SCRIPTING_JS_SOURCE")];
if (!TESTING) {
code.push("delete dump;");
} else {
code.unshift(
code.push(
`globalThis.sendResultForTesting = callExternalFunction.bind(null, "send");`
);
}
let success = false;
try {
const sandboxData = JSON.stringify(data);
// "pdfjsScripting.initSandbox..." MUST be the last line to be evaluated
// since the returned value is used for the communication.
code.push(`pdfjsScripting.initSandbox({ data: ${sandboxData} })`);
success = !!this._module.ccall(
"init",
"number",