From 09aebfc2e8d2499611c82c50b6ae574c8db8634d Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 30 Jan 2023 14:43:04 +0100 Subject: [PATCH] test: use an array for WPT gloablThis initialization scripts So that we can add multiple initialization scripts in the test runner. Refs: https://github.com/nodejs/node/pull/44483/ --- test/common/wpt.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/common/wpt.js b/test/common/wpt.js index b5e74f4290e197..d5f09685226ecb 100644 --- a/test/common/wpt.js +++ b/test/common/wpt.js @@ -298,7 +298,7 @@ class WPTRunner { this.resource = new ResourceLoader(path); this.flags = []; - this.dummyGlobalThisScript = null; + this.globalThisInitScripts = []; this.initScript = null; this.status = new StatusLoader(path); @@ -340,17 +340,17 @@ class WPTRunner { } get fullInitScript() { - if (this.initScript === null && this.dummyGlobalThisScript === null) { - return null; + if (this.globalThisInitScripts.length === null) { + return this.initScript; } + const globalThisInitScript = this.globalThisInitScripts.join('\n\n//===\n'); + if (this.initScript === null) { - return this.dummyGlobalThisScript; - } else if (this.dummyGlobalThisScript === null) { - return this.initScript; + return globalThisInitScript; } - return `${this.dummyGlobalThisScript}\n\n//===\n${this.initScript}`; + return `${globalThisInitScript}\n\n//===\n${this.initScript}`; } /** @@ -361,8 +361,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; }