Skip to content

Commit

Permalink
fix(factory): not overwrite context global Instance
Browse files Browse the repository at this point in the history
Avoid instanceof not work.
  • Loading branch information
chemzqm committed Feb 25, 2025
1 parent 0ecf54c commit f15cc37
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/util/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export function getProtoWithCompile(mod: Function): IModule {
const ModuleProto = getProtoWithCompile(Module)

export function copyGlobalProperties(sandbox: ISandbox, globalObj: any): ISandbox {
for (const key of Reflect.ownKeys(globalObj)) {
// Use Reflect.ownKeys affect instanceof of extensions, instanceof Error and instanceof TypeError won't work
for (const key of Object.keys(globalObj)) {
const value = sandbox[key]
if (value === undefined) {
sandbox[key] = globalObj[key]
Expand Down Expand Up @@ -155,6 +156,7 @@ export function createSandbox(filename: string, logger: ILogger, name?: string,
module,
Buffer,
URL: globalThis.URL,
WebAssembly: globalThis.WebAssembly,
console: createConsole(console, logger)
}, { name }) as ISandbox

Expand Down

0 comments on commit f15cc37

Please sign in to comment.