Merge pull request #13364 from Snuffleupagus/sandbox-TESTING-define

Clean-up usage of the `TESTING`-define in `src/pdf.sandbox.js`
This commit is contained in:
calixteman 2021-05-11 12:56:45 +02:00 committed by GitHub
commit dda1a9a7b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,9 +21,6 @@ const pdfjsVersion = PDFJSDev.eval("BUNDLE_VERSION");
/* eslint-disable-next-line no-unused-vars */
const pdfjsBuild = PDFJSDev.eval("BUNDLE_BUILD");
const TESTING =
typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || TESTING");
class SandboxSupport extends SandboxSupportBase {
exportValueToSandbox(val) {
// The communication with the Quickjs sandbox is based on strings
@ -58,16 +55,17 @@ class Sandbox {
}
create(data) {
if (TESTING) {
if (PDFJSDev.test("!PRODUCTION || TESTING")) {
this._module.ccall("nukeSandbox", null, []);
}
const code = [PDFJSDev.eval("PDF_SCRIPTING_JS_SOURCE")];
if (!TESTING) {
code.push("delete dump;");
} else {
if (PDFJSDev.test("!PRODUCTION || TESTING")) {
code.push(
`globalThis.sendResultForTesting = callExternalFunction.bind(null, "send");`
);
} else {
code.push("delete dump;");
}
let success = false;
@ -124,7 +122,7 @@ class Sandbox {
}
evalForTesting(code, key) {
if (TESTING) {
if (PDFJSDev.test("!PRODUCTION || TESTING")) {
this._module.ccall(
"evalInSandbox",
null,
@ -138,6 +136,8 @@ class Sandbox {
this._alertOnError,
]
);
} else {
throw new Error("Not implemented: evalForTesting");
}
}
}