Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: use an array for WPT gloablThis initialization scripts
So that we can add multiple initialization scripts in the test runner.

Refs: #44483
  • Loading branch information
joyeecheung authored and targos committed Oct 28, 2023
commit 3076119c190b4cd6a9aca8a4a53f81374a49c840
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