Skip to content

Commit 09aebfc

Browse files
committed
test: use an array for WPT gloablThis initialization scripts
So that we can add multiple initialization scripts in the test runner. Refs: nodejs#44483
1 parent d04e2d5 commit 09aebfc

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

test/common/wpt.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class WPTRunner {
298298
this.resource = new ResourceLoader(path);
299299

300300
this.flags = [];
301-
this.dummyGlobalThisScript = null;
301+
this.globalThisInitScripts = [];
302302
this.initScript = null;
303303

304304
this.status = new StatusLoader(path);
@@ -340,17 +340,17 @@ class WPTRunner {
340340
}
341341

342342
get fullInitScript() {
343-
if (this.initScript === null && this.dummyGlobalThisScript === null) {
344-
return null;
343+
if (this.globalThisInitScripts.length === null) {
344+
return this.initScript;
345345
}
346346

347+
const globalThisInitScript = this.globalThisInitScripts.join('\n\n//===\n');
348+
347349
if (this.initScript === null) {
348-
return this.dummyGlobalThisScript;
349-
} else if (this.dummyGlobalThisScript === null) {
350-
return this.initScript;
350+
return globalThisInitScript;
351351
}
352352

353-
return `${this.dummyGlobalThisScript}\n\n//===\n${this.initScript}`;
353+
return `${globalThisInitScript}\n\n//===\n${this.initScript}`;
354354
}
355355

356356
/**
@@ -361,8 +361,9 @@ class WPTRunner {
361361
pretendGlobalThisAs(name) {
362362
switch (name) {
363363
case 'Window': {
364-
this.dummyGlobalThisScript =
365-
'global.Window = Object.getPrototypeOf(globalThis).constructor;';
364+
this.globalThisInitScripts.push(
365+
`global.Window = Object.getPrototypeOf(globalThis).constructor;
366+
self.GLOBAL.isWorker = () => false;`);
366367
break;
367368
}
368369

0 commit comments

Comments
 (0)