-
Notifications
You must be signed in to change notification settings - Fork 16
fix: only merge non-enumerable global properties that are not in VM scope #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 looks like a better solution to me, and can confirm it works for Docusaurus
would still be useful to allow excluding some globals?
for (var k, i = 0, n = keys.length; i < n; i++) { | ||
k = keys[i] | ||
a[k] = b[k] | ||
} | ||
return a | ||
} | ||
|
||
var vmGlobals = new vm.Script('vmGlobals = Object.getOwnPropertyNames(globalThis)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review hint:
-
👍 eager call but only takes < 1ms for my mac
-
List is:
[
"Object",
"Function",
"Array",
"Number",
"parseFloat",
"parseInt",
"Infinity",
"NaN",
"undefined",
"Boolean",
"String",
"Symbol",
"Date",
"Promise",
"RegExp",
"Error",
"AggregateError",
"EvalError",
"RangeError",
"ReferenceError",
"SyntaxError",
"TypeError",
"URIError",
"globalThis",
"JSON",
"Math",
"console",
"Intl",
"ArrayBuffer",
"Uint8Array",
"Int8Array",
"Uint16Array",
"Int16Array",
"Uint32Array",
"Int32Array",
"Float32Array",
"Float64Array",
"Uint8ClampedArray",
"BigUint64Array",
"BigInt64Array",
"DataView",
"Map",
"BigInt",
"Set",
"WeakMap",
"WeakSet",
"Proxy",
"Reflect",
"FinalizationRegistry",
"WeakRef",
"decodeURI",
"decodeURIComponent",
"encodeURI",
"encodeURIComponent",
"escape",
"unescape",
"eval",
"isFinite",
"isNaN",
"SharedArrayBuffer",
"Atomics",
"WebAssembly",
];
if (!vmGlobals.includes(name)) { | ||
sandbox[name] = global[name] | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review hint
New globals automatically forwarded:
[
"global",
"process",
"Buffer",
"atob",
"btoa",
"URL",
"URLSearchParams",
"TextEncoder",
"TextDecoder",
"AbortController",
"AbortSignal",
"EventTarget",
"Event",
"MessageChannel",
"MessagePort",
"MessageEvent",
"clearInterval",
"clearTimeout",
"setInterval",
"setTimeout",
"queueMicrotask",
"performance",
"clearImmediate",
"setImmediate",
"__extends",
"__assign",
"__rest",
"__decorate",
"__param",
"__metadata",
"__awaiter",
"__generator",
"__exportStar",
"__createBinding",
"__values",
"__read",
"__spread",
"__spreadArrays",
"__spreadArray",
"__await",
"__asyncGenerator",
"__asyncDelegator",
"__asyncValues",
"__makeTemplateObject",
"__importStar",
"__importDefault",
"__classPrivateFieldGet",
"__classPrivateFieldSet",
"consola",
"regeneratorRuntime",
];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of these globals are injected by the transpiler. Only stuff like URL
process
TextDecoder
etc. are of our interest.
I don't think that's necessarily the goal of this module and I frankly can't see how that's useful after this bug is fixed😅 Since we have a forked SSG plugin, if you really want to exclude some globals, just use |
Follow-up of #27. Fix #29
Case as where #27 failed:
Because the
globalThis
in this case is an exotic object, the latterPrism
isn't actually made a "global".Logs
false
becauseObject
is exotic. RemovingObject
from the scope causes it to logtrue
.The resolution is to filter out anything that's already in the VM scope.
cc @pierrec This is a hotfix.
cc @slorber FYI