Skip to content

Commit

Permalink
#1102@minor: Uses vm.Script for setting globals instead of a string t…
Browse files Browse the repository at this point in the history
…o improve performance.
  • Loading branch information
capricorn86 committed Sep 29, 2023
1 parent c68e51a commit 9700666
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/happy-dom/src/window/VMGlobalPropertyScript.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default `
import { Script } from 'vm';

export default new Script(`
this.ArrayBuffer = globalThis.ArrayBuffer;
this.Boolean = globalThis.Boolean;
this.DataView = globalThis.DataView;
Expand Down Expand Up @@ -57,4 +59,4 @@ this.AbortSignal = globalThis.AbortSignal;
this.Array = globalThis.Array;
this.Object = globalThis.Object;
this.Function = globalThis.Function;
`;
`);
2 changes: 1 addition & 1 deletion packages/happy-dom/src/window/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ export default class Window extends EventTarget implements IWindow {

// Sets global properties from the VM to the Window object.
// Otherwise "this.Array" will be undefined for example.
VM.runInContext(VMGlobalPropertyScript, this);
VMGlobalPropertyScript.runInContext(this);
}
}
}

0 comments on commit 9700666

Please sign in to comment.