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: #44483
PR-URL: #46425
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
joyeecheung authored and targos committed Nov 10, 2023
1 parent a0d4b69 commit f0e8ff9
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 f0e8ff9

Please sign in to comment.