From e1f5317437550e0302c25d4f79fb35b6e7476d33 Mon Sep 17 00:00:00 2001 From: Sergey Chernyshev Date: Thu, 25 Apr 2024 00:14:37 +0200 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/ PR-URL: https://github.com/nodejs/node/pull/46425 Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: Yagiz Nizipli --- graal-nodejs/test/common/wpt.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/graal-nodejs/test/common/wpt.js b/graal-nodejs/test/common/wpt.js index 976668b69bf..048850a5be3 100644 --- a/graal-nodejs/test/common/wpt.js +++ b/graal-nodejs/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; }