mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
JS -- Actions must be evaluated in global scope
* All the public properties of doc are injected into globalThis, in order to make them available through `this` * Put event in the global scope too.
This commit is contained in:
parent
c366390f6b
commit
167ff1a7fc
7 changed files with 178 additions and 53 deletions
|
@ -72,6 +72,7 @@ function initSandbox(params) {
|
|||
obj.send = send;
|
||||
obj.globalEval = globalEval;
|
||||
obj.doc = _document.wrapped;
|
||||
obj.globalEval = globalEval;
|
||||
const field = new Field(obj);
|
||||
const wrapped = new Proxy(field, proxyHandler);
|
||||
doc._addField(name, wrapped);
|
||||
|
@ -81,7 +82,6 @@ function initSandbox(params) {
|
|||
globalThis.event = null;
|
||||
globalThis.global = Object.create(null);
|
||||
globalThis.app = new Proxy(app, proxyHandler);
|
||||
globalThis.doc = _document.wrapped;
|
||||
globalThis.color = new Proxy(new Color(), proxyHandler);
|
||||
globalThis.console = new Proxy(new Console({ send }), proxyHandler);
|
||||
globalThis.util = new Proxy(util, proxyHandler);
|
||||
|
@ -103,6 +103,26 @@ function initSandbox(params) {
|
|||
}
|
||||
}
|
||||
|
||||
// The doc properties must live in the global scope too
|
||||
const properties = Object.create(null);
|
||||
for (const name of Object.getOwnPropertyNames(Doc.prototype)) {
|
||||
if (name === "constructor" || name.startsWith("_")) {
|
||||
continue;
|
||||
}
|
||||
const descriptor = Object.getOwnPropertyDescriptor(Doc.prototype, name);
|
||||
if (descriptor.get) {
|
||||
properties[name] = {
|
||||
get: descriptor.get.bind(doc),
|
||||
set: descriptor.set.bind(doc),
|
||||
};
|
||||
} else {
|
||||
properties[name] = {
|
||||
value: Doc.prototype[name].bind(doc),
|
||||
};
|
||||
}
|
||||
}
|
||||
Object.defineProperties(globalThis, properties);
|
||||
|
||||
const functions = {
|
||||
dispatchEvent: app._dispatchEvent.bind(app),
|
||||
timeoutCb: app._evalCallback.bind(app),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue