From 3076119c190b4cd6a9aca8a4a53f81374a49c840 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 976668b69bfde3..048850a5be32b5 100644 --- a/test/common/wpt.js +++ b/test/common/wpt.js @@ -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); @@ -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}`; } /** @@ -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; }