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/node#44483
PR-URL: nodejs/node#46425
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
  • Loading branch information
sercher committed Apr 25, 2024
1 parent 2ef4d1a commit fe19c9a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions graal-nodejs/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 fe19c9a

Please sign in to comment.