Fix #1531 - Remove overall need for globalThis pollution (#1543)

This commit is contained in:
Andrea Giammarchi
2023-06-19 18:05:45 +02:00
committed by GitHub
parent d6b1c393f6
commit 0a7e1ce0d7
20 changed files with 83 additions and 124 deletions

View File

@@ -54,18 +54,15 @@ const execute = async (script, source, XWorker, isAsync) => {
try {
// temporarily override inherited document.currentScript in a non writable way
// but it deletes it right after to preserve native behavior (as it's sync: no trouble)
defineProperty(globalThis, "XWorker", {
configurable: true,
get: () => XWorker,
});
defineProperty(document, "currentScript", {
configurable: true,
get: () => script,
});
module.setGlobal(interpreter, "XWorker", XWorker);
return module[isAsync ? "runAsync" : "run"](interpreter, content);
} finally {
delete globalThis.XWorker;
delete document.currentScript;
module.deleteGlobal(interpreter, "XWorker");
}
};