Skip to content

Commit

Permalink
test: use an array for WPT gloablThis initialization scripts
Browse files Browse the repository at this point in the history
So that we can add multiple initialization scripts in the test runner.

Refs: nodejs#44483
  • Loading branch information
joyeecheung committed Jan 30, 2023
1 parent d04e2d5 commit 09aebfc
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions test/common/wpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class WPTRunner {
this.resource = new ResourceLoader(path);

this.flags = [];
this.dummyGlobalThisScript = null;
this.globalThisInitScripts = [];
this.initScript = null;

this.status = new StatusLoader(path);
Expand Down Expand Up @@ -340,17 +340,17 @@ class WPTRunner {
}

get fullInitScript() {
if (this.initScript === null && this.dummyGlobalThisScript === null) {
return null;
if (this.globalThisInitScripts.length === null) {
return this.initScript;
}

const globalThisInitScript = this.globalThisInitScripts.join('\n\n//===\n');

if (this.initScript === null) {
return this.dummyGlobalThisScript;
} else if (this.dummyGlobalThisScript === null) {
return this.initScript;
return globalThisInitScript;
}

return `${this.dummyGlobalThisScript}\n\n//===\n${this.initScript}`;
return `${globalThisInitScript}\n\n//===\n${this.initScript}`;
}

/**
Expand All @@ -361,8 +361,9 @@ class WPTRunner {
pretendGlobalThisAs(name) {
switch (name) {
case 'Window': {
this.dummyGlobalThisScript =
'global.Window = Object.getPrototypeOf(globalThis).constructor;';
this.globalThisInitScripts.push(
`global.Window = Object.getPrototypeOf(globalThis).constructor;
self.GLOBAL.isWorker = () => false;`);
break;
}

Expand Down

0 comments on commit 09aebfc

Please sign in to comment.