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 authored and targos committed Oct 28, 2023
1 parent 10f5974 commit 3076119
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 @@ -408,7 +408,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 @@ -463,17 +463,17 @@ class WPTRunner {
initScript = `${initScript}\n\n//===\nglobalThis.location.search = "${locationSearchString}";`;
}

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

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

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

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

/**
Expand All @@ -484,8 +484,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 3076119

Please sign in to comment.