JS -- Add a sandbox based on quickjs

* quickjs-eval.js has been generated using https://github.com/mozilla/pdf.js.quickjs/
 * lazy load of sandbox code
 * Rewrite tests to use the sandbox
 * Add a task `watch-sandbox` which update bundle pdf.sandbox.js on change in the sandbox code
This commit is contained in:
Calixte Denizet 2020-11-09 14:45:02 +01:00
parent d3936ac9d2
commit c7974e9996
15 changed files with 886 additions and 245 deletions

View file

@ -14,6 +14,8 @@
*/
import { DefaultExternalServices, PDFViewerApplication } from "./app.js";
import { loadScript, shadow } from "pdfjs-lib";
import { AppOptions } from "./app_options.js";
import { BasePreferences } from "./preferences.js";
import { DownloadManager } from "./download_manager.js";
import { GenericL10n } from "./genericl10n.js";
@ -49,6 +51,25 @@ class GenericExternalServices extends DefaultExternalServices {
static createL10n({ locale = "en-US" }) {
return new GenericL10n(locale);
}
static get scripting() {
const promise = loadScript(AppOptions.get("scriptingSrc")).then(() => {
return window.pdfjsSandbox.QuickJSSandbox();
});
const sandbox = {
createSandbox(data) {
promise.then(sbx => sbx.create(data));
},
dispatchEventInSandbox(event) {
promise.then(sbx => sbx.dispatchEvent(event));
},
destroySandbox() {
promise.then(sbx => sbx.nukeSandbox());
},
};
return shadow(this, "scripting", sandbox);
}
}
PDFViewerApplication.externalServices = GenericExternalServices;