From 8d5ee1a2b1034652fba56ca620d8120a13cb0034 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 26 Nov 2024 22:46:47 +0000 Subject: [PATCH] Bug 1930534 [wpt PR 49108] - Run ShadowRealm tests in multiple scopes, a=testonly Automatic update from web-platform-tests Change 'shadowrealm' global into a shorthand for all possible ShadowRealm scopes In order to automatically run tests not only in a ShadowRealm created in a window scope, but also in ShadowRealms created in other realms, change the 'shadowrealm' global type to a collection, and rename the existing ShadowRealm handler to 'shadowrealm-in-window'. -- Remove monkeypatch of globalThis.self in ShadowRealm As per https://github.com/whatwg/html/pull/9893, ShadowRealmGlobalScope should have a `self` attribute already. There is no need to monkeypatch it for the test harness. -- Factor out JS code that will be common to multiple ShadowRealm handlers We will add multiple ShadowRealm handlers, and they will all need to set up certain global properties. Avoid repeating this code in each handler as well as in idlharness-shadowrealm.js. This should also increase readability, which is good since the ShadowRealm setup code can be confusing. -- Add 'shadowrealm-in-shadowrealm' global This will add to any test with global=shadowrealm in its metadata, an .any.shadowrealm-in-shadowrealm.html variant. The test wrapper creates an outer ShadowRealm, which creates an inner ShadowRealm and runs the tests inside that, relaying the results through the outer ShadowRealm. -- Add 'shadowrealm-in-dedicatedworker' global This will add to any test with global=shadowrealm in its metadata, an .any.shadowrealm-in-dedicatedworker.html variant. The test loads an intermediate .any.worker-shadowrealm.js wrapper into a Worker, and forwards the message port to the Worker's message port so that fetch_tests_from_worker can receive the results. -- Add 'shadowrealm-in-sharedworker' global This will add to any test with global=shadowrealm in its metadata, an .any.shadowrealm-in-sharedworker.html variant. The test loads the same intermediate .any.worker-shadowrealm.js wrapper as .any.shadowrealm-in-dedicatedworker.html, but populates a 'port' variable with the port received from the connect event, instead of calling the global postMessage since that won't work in a SharedWorker. -- Add 'shadowrealm-in-serviceworker' global This will add to any test with global=shadowrealm in its metadata, an .any.shadowrealm-in-serviceworker.html variant. We have to use a slightly different .any.serviceworker-shadowrealm.js wrapper from the wrapper used for the other types of workers, because dynamic import() is forbidden in ServiceWorker scopes. Instead, add a utility function to set up a fakeDynamicImport() function inside the ShadowRealm which uses the fetch adaptor to get the module's source text and evaluate it in the shadowRealm. Also add a case for ServiceWorkers to getPostMessageFunc(), which returns a postMessage() drop-in replacement that broadcasts the message to all clients, since test result messages from the ShadowRealm are not in response to any particular message received by the ServiceWorker. Note '.https.' needs to be added to the test path. -- Add 'shadowrealm-in-audioworklet' global This will add to any test with global=shadowrealm in its metadata, an .any.shadowrealm-in-audioworklet.html variant. The wrapper here is similar to the one for ServiceWorkers, since dynamic import() is also forbidden in worklet scopes. But additionally fetch() is not exposed, so we add a utility function to set up the ability to call the window realm's fetch() through the AudioWorklet's message port. We also add /resources/testharness-shadowrealm-audioworkletprocessor.js to contain most of the AudioWorklet setup boilerplate, so that it isn't written inline in serve.py. Note '.https.' needs to be added to the test path. -- wpt-commits: 9c8db8af89efbe0f67b215af2a6b49e9564e2971, 65a205aea5d02ff5bea7b1a0579287035d02d6c4, eb9c8e7259ef8bd5cca5019c1ca15ccd430e81dc, 3a20c56893472783b5e20c0d61cbb7b7b278cc6d, 7d8458ed291b139307430a102180c9a617d7876e, 42160ae827c863ac6787c8451fe377901c8f0652, 59367bb21d053abb9ed6de3cca5409486816acc9, 60d6c48e5fa76876bc3924b9d6185dfb56c9ab1c wpt-pr: 49108 UltraBlame original commit: 0a625225a525e60a048bbd6f3a94e2605c7e375b --- .../tests/docs/writing-tests/testharness.md | 287 ++- .../tests/resources/idlharness-shadowrealm.js | 121 +- ...rness-shadowrealm-audioworkletprocessor.js | 235 ++ .../testharness-shadowrealm-inner.js | 101 + .../testharness-shadowrealm-outer.js | 535 ++++ .../tests/tools/manifest/sourcefile.py | 173 ++ .../web-platform/tests/tools/serve/serve.py | 2292 ++++++++++++++--- 7 files changed, 3244 insertions(+), 500 deletions(-) create mode 100644 testing/web-platform/tests/resources/testharness-shadowrealm-audioworkletprocessor.js create mode 100644 testing/web-platform/tests/resources/testharness-shadowrealm-inner.js create mode 100644 testing/web-platform/tests/resources/testharness-shadowrealm-outer.js diff --git a/testing/web-platform/tests/docs/writing-tests/testharness.md b/testing/web-platform/tests/docs/writing-tests/testharness.md index 8bcf8df09259..4841b8a7b8bc 100644 --- a/testing/web-platform/tests/docs/writing-tests/testharness.md +++ b/testing/web-platform/tests/docs/writing-tests/testharness.md @@ -1544,6 +1544,10 @@ worker scopes * shadowrealm +- +in +- +window : runs the @@ -1596,30 +1600,294 @@ var any . shadowrealm +- +in +- +window +. +html +< +/ +code +> +* +shadowrealm +- +in +- +shadowrealm +: +runs +the +test +code +in +a +ShadowRealm +context +hosted +in +another +ShadowRealm +context +; +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +any +. +shadowrealm +- +in +- +shadowrealm +. +html +< +/ +code +> +* +shadowrealm +- +in +- +dedicatedworker +: +runs +the +test +code +in +a +ShadowRealm +context +hosted +in +a +dedicated +worker +; +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +any +. +shadowrealm +- +in +- +dedicatedworker . html < / code > +* +shadowrealm +- +in +- +sharedworker +: +runs +the +test +code +in +a +ShadowRealm +context +hosted +in +a +shared +worker +; +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +any +. +shadowrealm +- +in +- +sharedworker +. +html +< +/ +code +> +* +shadowrealm +- +in +- +serviceworker +: +runs +the +test +code +in +a +ShadowRealm +context +hosted +in +a +service +worker +; +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +https +. +any +. +shadowrealm +- +in +- +serviceworker +. +html +< +/ +code +> +* +shadowrealm +- +in +- +audioworklet +: +runs +the +test +code +in +a +ShadowRealm +context +hosted +in +an +AudioWorklet +processor +; +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +https +. +any +. +shadowrealm +- +in +- +audioworklet +. +html +< +/ +code +> +* +shadowrealm +: +shorthand +for +all +of +the +ShadowRealm +scopes To check -if +what +scope your test is run from -a -window -or -worker you can use the following -two methods that will @@ -1644,6 +1912,13 @@ GLOBAL isWorker ( ) +self +. +GLOBAL +. +isShadowRealm +( +) Although [ the diff --git a/testing/web-platform/tests/resources/idlharness-shadowrealm.js b/testing/web-platform/tests/resources/idlharness-shadowrealm.js index c0b3edee9037..94bbd30cc316 100644 --- a/testing/web-platform/tests/resources/idlharness-shadowrealm.js +++ b/testing/web-platform/tests/resources/idlharness-shadowrealm.js @@ -75,69 +75,6 @@ ShadowRealm ( ) ; -realm -. -evaluate -( -" -globalThis -. -self -= -globalThis -; -undefined -; -" -) -; -realm -. -evaluate -( -globalThis -. -self -. -GLOBAL -= -{ -isWindow -: -function -( -) -{ -return -false -; -} -isWorker -: -function -( -) -{ -return -false -; -} -isShadowRealm -: -function -( -) -{ -return -true -; -} -} -; -undefined -; -) -; const specs = @@ -191,27 +128,26 @@ specs ) ; await -new -Promise +shadowRealmEvalAsync ( realm -. -evaluate -( -( -resolve -reject -) -= -> -{ -( -async +await +import ( +" +/ +resources +/ +testharness +- +shadowrealm +- +inner +. +js +" ) -= -> -{ +; await import ( @@ -342,31 +278,6 @@ test ( ) ; -} -) -( -) -. -then -( -resolve -( -e -) -= -> -reject -( -e -. -toString -( -) -) -) -; -} -) ) ; await diff --git a/testing/web-platform/tests/resources/testharness-shadowrealm-audioworkletprocessor.js b/testing/web-platform/tests/resources/testharness-shadowrealm-audioworkletprocessor.js new file mode 100644 index 000000000000..0ae359f13bed --- /dev/null +++ b/testing/web-platform/tests/resources/testharness-shadowrealm-audioworkletprocessor.js @@ -0,0 +1,235 @@ +globalThis +. +TestRunner += +class +TestRunner +extends +AudioWorkletProcessor +{ +constructor +( +) +{ +super +( +) +; +this +. +createShadowRealmAndStartTests +( +) +; +} +fetchOverPortExecutor +( +resource +) +{ +return +( +resolve +reject +) += +> +{ +const +listener += +( +event +) += +> +{ +if +( +typeof +event +. +data +! += += +" +string +" +| +| +! +event +. +data +. +startsWith +( +" +fetchResult +: +: +" +) +) +{ +return +; +} +const +result += +event +. +data +. +slice +( +" +fetchResult +: +: +" +. +length +) +; +if +( +result +. +startsWith +( +" +success +: +: +" +) +) +{ +resolve +( +result +. +slice +( +" +success +: +: +" +. +length +) +) +; +} +else +{ +reject +( +result +. +slice +( +" +fail +: +: +" +. +length +) +) +; +} +this +. +port +. +removeEventListener +( +" +message +" +listener +) +; +} +this +. +port +. +addEventListener +( +" +message +" +listener +) +; +this +. +port +. +start +( +) +; +this +. +port +. +postMessage +( +fetchRequest +: +: +{ +resource +} +) +; +} +} +async +createShadowRealmAndStartTests +( +) +{ +throw +new +Error +( +" +Forgot +to +overwrite +this +method +! +" +) +; +} +process +( +) +{ +return +false +; +} +} +; +registerProcessor +( +" +test +- +runner +" +TestRunner +) +; diff --git a/testing/web-platform/tests/resources/testharness-shadowrealm-inner.js b/testing/web-platform/tests/resources/testharness-shadowrealm-inner.js new file mode 100644 index 000000000000..474c87df6d93 --- /dev/null +++ b/testing/web-platform/tests/resources/testharness-shadowrealm-inner.js @@ -0,0 +1,101 @@ +globalThis +. +setShadowRealmGlobalProperties += +function +( +queryString +fetchAdaptor +) +{ +globalThis +. +fetch_json += +( +resource +) += +> +{ +const +executor += +fetchAdaptor +( +resource +) +; +return +new +Promise +( +executor +) +. +then +( +( +s +) += +> +JSON +. +parse +( +s +) +) +; +} +; +globalThis +. +location += +{ +search +: +queryString +} +; +} +; +globalThis +. +GLOBAL += +{ +isWindow +: +function +( +) +{ +return +false +; +} +isWorker +: +function +( +) +{ +return +false +; +} +isShadowRealm +: +function +( +) +{ +return +true +; +} +} +; diff --git a/testing/web-platform/tests/resources/testharness-shadowrealm-outer.js b/testing/web-platform/tests/resources/testharness-shadowrealm-outer.js new file mode 100644 index 000000000000..cbc1a4c6ff56 --- /dev/null +++ b/testing/web-platform/tests/resources/testharness-shadowrealm-outer.js @@ -0,0 +1,535 @@ +globalThis +. +shadowRealmEvalAsync += +function +( +realm +asyncBody +) +{ +return +new +Promise +( +realm +. +evaluate +( +( +resolve +reject +) += +> +{ +( +async +( +) += +> +{ +{ +asyncBody +} +} +) +( +) +. +then +( +resolve +( +e +) += +> +reject +( +e +. +toString +( +) +) +) +; +} +) +) +; +} +; +globalThis +. +fetchAdaptor += +( +resource +) += +> +( +resolve +reject +) += +> +{ +fetch +( +resource +) +. +then +( +res += +> +res +. +text +( +) +) +. +then +( +resolve +( +e +) += +> +reject +( +e +. +toString +( +) +) +) +; +} +; +let +sharedWorkerMessagePortPromise +; +globalThis +. +getPostMessageFunc += +async +function +( +) +{ +if +( +typeof +postMessage += += += +" +function +" +) +{ +return +postMessage +; +} +if +( +typeof +clients += += += +" +object +" +) +{ +const +allClients += +await +clients +. +matchAll +( +{ +includeUncontrolled +: +true +} +) +; +return +function +broadcast +( +msg +) +{ +allClients +. +map +( +client += +> +client +. +postMessage +( +msg +) +) +; +} +} +if +( +sharedWorkerMessagePortPromise +) +{ +return +await +sharedWorkerMessagePortPromise +; +} +throw +new +Error +( +" +getPostMessageFunc +is +intended +for +Worker +scopes +" +) +; +} +let +savedResolver +; +if +( +globalThis +. +constructor +. +name += += += +" +SharedWorkerGlobalScope +" +) +{ +sharedWorkerMessagePortPromise += +new +Promise +( +( +resolve +) += +> +{ +savedResolver += +resolve +; +} +) +; +addEventListener +( +" +connect +" +function +( +event +) +{ +const +port += +event +. +ports +[ +0 +] +; +savedResolver +( +port +. +postMessage +. +bind +( +port +) +) +; +} +) +; +} +globalThis +. +setupFakeDynamicImportInShadowRealm += +function +( +realm +adaptor +) +{ +function +fetchModuleTextExecutor +( +url +) +{ +return +( +resolve +reject +) += +> +{ +new +Promise +( +adaptor +( +url +) +) +. +then +( +text += +> +realm +. +evaluate +( +text ++ +" +; +\ +nundefined +" +) +) +. +then +( +resolve +( +e +) += +> +reject +( +e +. +toString +( +) +) +) +; +} +} +realm +. +evaluate +( +( +fetchModuleTextExecutor +) += +> +{ +globalThis +. +fakeDynamicImport += +function +( +url +) +{ +return +new +Promise +( +fetchModuleTextExecutor +( +url +) +) +; +} +} +) +( +fetchModuleTextExecutor +) +; +} +; +globalThis +. +setupFakeFetchOverMessagePort += +function +( +port +) +{ +port +. +addEventListener +( +" +message +" +( +event +) += +> +{ +if +( +typeof +event +. +data +! += += +" +string +" +| +| +! +event +. +data +. +startsWith +( +" +fetchRequest +: +: +" +) +) +{ +return +; +} +fetch +( +event +. +data +. +slice +( +" +fetchRequest +: +: +" +. +length +) +) +. +then +( +res += +> +res +. +text +( +) +) +. +then +( +text += +> +port +. +postMessage +( +fetchResult +: +: +success +: +: +{ +text +} +) +error += +> +port +. +postMessage +( +fetchResult +: +: +fail +: +: +{ +error +} +) +) +; +} +) +; +port +. +start +( +) +; +} diff --git a/testing/web-platform/tests/tools/manifest/sourcefile.py b/testing/web-platform/tests/tools/manifest/sourcefile.py index aec055f46624..db45347254dd 100644 --- a/testing/web-platform/tests/tools/manifest/sourcefile.py +++ b/testing/web-platform/tests/tools/manifest/sourcefile.py @@ -606,11 +606,184 @@ { } +" +shadowrealm +- +in +- +window +" +: +{ +} + +" +shadowrealm +- +in +- +shadowrealm +" +: +{ +} + +" +shadowrealm +- +in +- +dedicatedworker +" +: +{ +} + +" +shadowrealm +- +in +- +sharedworker +" +: +{ +} + +" +shadowrealm +- +in +- +serviceworker +" +: +{ + +" +force_https +" +: +True + +" +suffix +" +: +" +. +https +. +any +. +shadowrealm +- +in +- +serviceworker +. +html +" + +} + +" +shadowrealm +- +in +- +audioworklet +" +: +{ + +" +force_https +" +: +True + +" +suffix +" +: +" +. +https +. +any +. +shadowrealm +- +in +- +audioworklet +. +html +" + +} + " shadowrealm " : { +" +longhand +" +: +{ + +" +shadowrealm +- +in +- +window +" + +" +shadowrealm +- +in +- +shadowrealm +" + +" +shadowrealm +- +in +- +dedicatedworker +" + +" +shadowrealm +- +in +- +sharedworker +" + +" +shadowrealm +- +in +- +serviceworker +" + +" +shadowrealm +- +in +- +audioworklet +" + +} } " diff --git a/testing/web-platform/tests/tools/serve/serve.py b/testing/web-platform/tests/tools/serve/serve.py index b203551a2dac..789709542d74 100644 --- a/testing/web-platform/tests/tools/serve/serve.py +++ b/testing/web-platform/tests/tools/serve/serve.py @@ -3293,7 +3293,7 @@ " " class -ShadowRealmHandler +ShadowRealmInWindowHandler ( HtmlWrapperHandler ) @@ -3303,6 +3303,10 @@ = " shadowrealm +- +in +- +window " path_replace @@ -3314,6 +3318,10 @@ any . shadowrealm +- +in +- +window . html " @@ -3385,6 +3393,27 @@ > < script +src += +" +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js +" +> +< +/ +script +> +< +script > ( async @@ -3402,127 +3431,43 @@ ) ; -r -. -evaluate +await +shadowRealmEvalAsync ( -" -globalThis -. -self -= -globalThis -; -undefined -; -" -) -; - r -. -evaluate -( -func -= -> -{ -globalThis -. -fetch_json -= -( -resource -) -= -> -{ - -const -thenMethod -= -func -( -resource -) -; - -return -new -Promise -( -( -resolve -reject -) -= -> -thenMethod -( -( -s -) -= -> -resolve +await +import ( -JSON +" +/ +resources +/ +testharness +- +shadowrealm +- +inner . -parse -( -s -) -) -reject -) +js +" ) ; -} -; - -} -) -( -( -resource -) -= -> -function -( -resolve -reject -) -{ - -fetch -( -resource -) -. -then -( -res -= -> -res -. -text +await +import ( -) -String -) +" +/ +resources +/ +testharness . -then -( -resolve -reject +js +" ) ; -} ) ; @@ -3530,120 +3475,29 @@ . evaluate ( -s -= -> -{ - -globalThis -. -location -= -{ -search -: -s -} -; - -} +" +setShadowRealmGlobalProperties +" ) ( location . search +fetchAdaptor ) ; await -new -Promise +shadowRealmEvalAsync ( r -. -evaluate -( -( -resolve -reject -) -= -> -{ - -( -async -( -) -= -> -{ - -globalThis -. -self -. -GLOBAL -= -{ - -isWindow -: -function -( -) -{ -return -false -; -} - -isWorker -: -function -( -) -{ -return -false -; -} - -isShadowRealm -: -function -( -) -{ -return -true -; -} - -} -; - -await -import -( -" -/ -resources -/ -testharness -. -js -" -) -; - % ( script ) s - + await import ( @@ -3656,34 +3510,7 @@ " ) ; - -} -) -( -) -. -then -( -resolve -( -e -) -= -> -reject -( -e -. -toString -( -) -) -) -; - -} -) ) ; @@ -3747,44 +3574,1212 @@ return None class -BaseWorkerHandler +ShadowRealmInShadowRealmHandler ( -WrapperHandler +HtmlWrapperHandler ) : -headers +global_type = -[ -( +" +shadowrealm +- +in +- +shadowrealm +" + +path_replace += +[ +( +" +. +any +. +shadowrealm +- +in +- +shadowrealm +. +html +" +" +. +any +. +js +" +) +] + +wrapper += +" +" +" +< +! +doctype +html +> +< +meta +charset += +utf +- +8 +> +% +( +meta +) +s +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js +" +> +< +/ +script +> +< +script +> +( +async +function +( +) +{ + +const +outer += +new +ShadowRealm +( +) +; + +outer +. +evaluate +( + +var +inner += +new +ShadowRealm +( +) +; + +) +; + +await +shadowRealmEvalAsync +( +outer + +await +import +( +" +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js +" +) +; + +await +shadowRealmEvalAsync +( +inner +\ +\ + +await +import +( +" +/ +resources +/ +testharness +- +shadowrealm +- +inner +. +js +" +) +; + +await +import +( +" +/ +resources +/ +testharness +. +js +" +) +; + +\ +\ +) +; + +) +; + +outer +. +evaluate +( + +inner +. +evaluate +( +" +setShadowRealmGlobalProperties +" +) + +) +( +location +. +search +fetchAdaptor +) +; + +await +shadowRealmEvalAsync +( +outer + +await +shadowRealmEvalAsync +( +inner +\ +\ + +% +( +script +) +s + +await +import +( +" +% +( +path +) +s +" +) +; + +\ +\ +) +; + +) +; + +outer +. +evaluate +( + +function +begin_shadow_realm_tests +( +windowCallback +) +{ + +inner +. +evaluate +( +" +begin_shadow_realm_tests +" +) +( +windowCallback +) +; + +} + +) +; + +await +fetch_tests_from_shadow_realm +( +outer +) +; + +done +( +) +; +} +) +( +) +; +< +/ +script +> +" +" +" + +def +_script_replacement +( +self +key +value +) +: + +if +key += += +" +script +" +: + +return +' +await +import +( +" +% +s +" +) +; +' +% +value + +return +None +class +ShadowRealmInDedicatedWorkerHandler +( +WorkersHandler +) +: + +global_type += +" +shadowrealm +- +in +- +dedicatedworker +" + +path_replace += +[ +( +" +. +any +. +shadowrealm +- +in +- +dedicatedworker +. +html +" + +" +. +any +. +js +" + +" +. +any +. +worker +- +shadowrealm +. +js +" +) +] +class +ShadowRealmInSharedWorkerHandler +( +SharedWorkersHandler +) +: + +global_type += +" +shadowrealm +- +in +- +sharedworker +" + +path_replace += +[ +( +" +. +any +. +shadowrealm +- +in +- +sharedworker +. +html +" + +" +. +any +. +js +" + +" +. +any +. +worker +- +shadowrealm +. +js +" +) +] +class +ShadowRealmInServiceWorkerHandler +( +ServiceWorkersHandler +) +: + +global_type += +" +shadowrealm +- +in +- +serviceworker +" + +path_replace += +[ +( +" +. +https +. +any +. +shadowrealm +- +in +- +serviceworker +. +html +" + +" +. +any +. +js +" + +" +. +any +. +serviceworker +- +shadowrealm +. +js +" +) +] +class +ShadowRealmInAudioWorkletHandler +( +HtmlWrapperHandler +) +: + +global_type += +" +shadowrealm +- +in +- +audioworklet +" + +path_replace += +[ +( +" +. +https +. +any +. +shadowrealm +- +in +- +audioworklet +. +html +" +" +. +any +. +js +" + +" +. +any +. +audioworklet +- +shadowrealm +. +js +" +) +] + +wrapper += +" +" +" +< +! +doctype +html +> +< +meta +charset += +utf +- +8 +> +% +( +meta +) +s +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js +" +> +< +/ +script +> +< +script +> +( +async +function +( +) +{ + +const +context += +new +AudioContext +( +) +; + +await +context +. +audioWorklet +. +addModule +( + +" +/ +resources +/ +testharness +- +shadowrealm +- +outer +. +js +" +) +; + +await +context +. +audioWorklet +. +addModule +( + +" +/ +resources +/ +testharness +- +shadowrealm +- +audioworkletprocessor +. +js +" +) +; + +await +context +. +audioWorklet +. +addModule +( +" +% +( +path +) +s +% +( +query +) +s +" +) +; + +const +node += +new +AudioWorkletNode +( +context +" +test +- +runner +" +) +; + +setupFakeFetchOverMessagePort +( +node +. +port +) +; + +fetch_tests_from_worker +( +node +. +port +) +; +} +) +( +) +; +< +/ +script +> +" +" +" +class +BaseWorkerHandler +( +WrapperHandler +) +: + +headers += +[ +( +' +Content +- +Type +' +' +text +/ +javascript +' +) +] + +def +_meta_replacement +( +self +key +value +) +: + +return +None + +abc +. +abstractmethod + +def +_create_script_import +( +self +attribute +) +: + +pass + +def +_script_replacement +( +self +key +value +) +: + +if +key += += +" +script +" +: + +attribute += +value +. +replace +( +" +\ +\ +" +" +\ +\ +\ +\ +" +) +. +replace +( +' +" +' +' +\ +\ +" +' +) + +return +self +. +_create_script_import +( +attribute +) + +if +key += += +" +title +" +: + +value += +value +. +replace +( +" +\ +\ +" +" +\ +\ +\ +\ +" +) +. +replace +( ' -Content -- -Type +" ' ' -text -/ -javascript +\ +\ +" +' +) + +return +' +self +. +META_TITLE += +" +% +s +" +; ' +% +value + +return +None +class +ClassicWorkerHandler +( +BaseWorkerHandler +) +: + +path_replace += +[ +( +" +. +any +. +worker +. +js +" +" +. +any +. +js +" ) ] +wrapper += +" +" +" +% +( +meta +) +s +self +. +GLOBAL += +{ + +isWindow +: +function +( +) +{ +return +false +; +} + +isWorker +: +function +( +) +{ +return +true +; +} + +isShadowRealm +: +function +( +) +{ +return +false +; +} +} +; +importScripts +( +" +/ +resources +/ +testharness +. +js +" +) +; +% +( +script +) +s +importScripts +( +" +% +( +path +) +s +" +) +; +done +( +) +; +" +" +" + def -_meta_replacement +_create_script_import +( +self +attribute +) +: + +return +' +importScripts +( +" +% +s +" +) +' +% +attribute +class +ModuleWorkerHandler +( +BaseWorkerHandler +) +: + +path_replace += +[ +( +" +. +any +. +worker +- +module +. +js +" +" +. +any +. +js +" +) +] + +wrapper += +" +" +" +% +( +meta +) +s +self +. +GLOBAL += +{ + +isWindow +: +function +( +) +{ +return +false +; +} + +isWorker +: +function ( -self -key -value ) +{ +return +true +; +} + +isShadowRealm : - +function +( +) +{ return -None - -abc +false +; +} +} +; +import +" +/ +resources +/ +testharness . -abstractmethod +js +" +; +% +( +script +) +s +import +" +% +( +path +) +s +" +; +done +( +) +; +" +" +" def _create_script_import @@ -3794,122 +4789,250 @@ ) : -pass - -def -_script_replacement +return +' +import +" +% +s +" +; +' +% +attribute +class +ShadowRealmWorkerWrapperHandler ( -self -key -value +BaseWorkerHandler ) : - -if -key -= + +path_replace = +[ +( " -script +. +any +. +worker +- +shadowrealm +. +js " -: - -attribute +" +. +any +. +js +" +) +] + +wrapper = -value +" +" +" +% +( +meta +) +s +importScripts +( +" +/ +resources +/ +testharness +- +shadowrealm +- +outer . -replace +js +" +) +; +( +async +function +( +) +{ + +const +r += +new +ShadowRealm +( +) +; + +await +shadowRealmEvalAsync +( +r + +await +import ( " -\ -\ +/ +resources +/ +testharness +- +shadowrealm +- +inner +. +js " +) +; + +await +import +( " -\ -\ -\ -\ +/ +resources +/ +testharness +. +js " ) +; + +) +; + +r . -replace +evaluate ( -' " -' -' -\ -\ +setShadowRealmGlobalProperties " -' ) - -return -self -. -_create_script_import ( -attribute +" +% +( +query ) - -if -key -= -= +s " -title +fetchAdaptor +) +; + +await +shadowRealmEvalAsync +( +r + +% +( +script +) +s + +await +import +( " -: - -value +% +( +path +) +s +" +) +; + +) +; + +const +postMessageFunc = -value +await +getPostMessageFunc +( +) +; + +function +forwardMessage +( +msgJSON +) +{ + +postMessageFunc +( +JSON . -replace +parse ( -" -\ -\ -" -" -\ -\ -\ -\ -" +msgJSON ) +) +; + +} + +r . -replace +evaluate ( ' -" -' +begin_shadow_realm_tests ' -\ -\ +) +( +forwardMessage +) +; +} +) +( +) +; " -' +" +" + +def +_create_script_import +( +self +attribute ) - +: + return ' -self -. -META_TITLE -= +await +import +( " % s " +) ; ' % -value - -return -None +attribute class -ClassicWorkerHandler +ShadowRealmServiceWorkerWrapperHandler ( BaseWorkerHandler ) @@ -3923,7 +5046,9 @@ . any . -worker +serviceworker +- +shadowrealm . js " @@ -3946,47 +5071,70 @@ meta ) s -self +importScripts +( +" +/ +resources +/ +testharness +- +shadowrealm +- +outer . -GLOBAL -= -{ - -isWindow -: +js +" +) +; +( +async function ( ) { -return -false -; -} -isWorker -: -function +const +r += +new +ShadowRealm ( ) -{ -return -true ; -} -isShadowRealm -: -function +setupFakeDynamicImportInShadowRealm ( +r +fetchAdaptor ) -{ -return -false ; -} -} + +await +shadowRealmEvalAsync +( +r + +await +fakeDynamicImport +( +" +/ +resources +/ +testharness +- +shadowrealm +- +inner +. +js +" +) ; -importScripts + +await +fakeDynamicImport ( " / @@ -3998,12 +5146,43 @@ " ) ; + +) +; + +r +. +evaluate +( +" +setShadowRealmGlobalProperties +" +) +( +" +% +( +query +) +s +" +fetchAdaptor +) +; + +await +shadowRealmEvalAsync +( +r + % ( script ) s -importScripts + +await +fakeDynamicImport ( " % @@ -4014,7 +5193,53 @@ " ) ; -done + +) +; + +const +postMessageFunc += +await +getPostMessageFunc +( +) +; + +function +forwardMessage +( +msgJSON +) +{ + +postMessageFunc +( +JSON +. +parse +( +msgJSON +) +) +; + +} + +r +. +evaluate +( +" +begin_shadow_realm_tests +" +) +( +forwardMessage +) +; +} +) ( ) ; @@ -4032,18 +5257,20 @@ return ' -importScripts +await +fakeDynamicImport ( " % s " ) +; ' % attribute class -ModuleWorkerHandler +ShadowRealmAudioWorkletWrapperHandler ( BaseWorkerHandler ) @@ -4057,9 +5284,9 @@ . any . -worker +audioworklet - -module +shadowrealm . js " @@ -4082,47 +5309,108 @@ meta ) s -self +TestRunner . -GLOBAL +prototype +. +createShadowRealmAndStartTests = +async +function +( +) { -isWindow +const +queryPart += +import +. +meta +. +url +. +split +( +' +? +' +) +[ +1 +] +; + +const +locationSearch += +queryPart +? +' +? +' ++ +queryPart : -function +' +' +; + +const +r += +new +ShadowRealm +( +) +; + +const +adaptor += +this +. +fetchOverPortExecutor +. +bind ( +this ) -{ -return -false ; -} -isWorker -: -function +setupFakeDynamicImportInShadowRealm ( +r +adaptor ) -{ -return -true ; -} -isShadowRealm -: -function +await +shadowRealmEvalAsync +( +r + +await +fakeDynamicImport ( +" +/ +resources +/ +testharness +- +shadowrealm +- +inner +. +js +" ) -{ -return -false -; -} -} ; -import + +await +fakeDynamicImport +( " / resources @@ -4131,13 +5419,40 @@ . js " +) +; + +) +; + +r +. +evaluate +( +" +setShadowRealmGlobalProperties +" +) +( +locationSearch +adaptor +) ; + +await +shadowRealmEvalAsync +( +r + % ( script ) s -import + +await +fakeDynamicImport +( " % ( @@ -4145,11 +5460,49 @@ ) s " +) ; -done + +) +; + +const +forwardMessage += +( +msgJSON +) += +> + +this +. +port +. +postMessage +( +JSON +. +parse +( +msgJSON +) +) +; + +r +. +evaluate +( +" +begin_shadow_realm_tests +" +) ( +forwardMessage ) ; +} " " " @@ -4164,11 +5517,14 @@ return ' -import +await +fakeDynamicImport +( " % s " +) ; ' % @@ -4715,10 +6071,114 @@ any . shadowrealm +- +in +- +window +. +html +" +ShadowRealmInWindowHandler +) + +( +" +GET +" +" +* +. +any +. +shadowrealm +- +in +- +shadowrealm +. +html +" +ShadowRealmInShadowRealmHandler +) + +( +" +GET +" +" +* +. +any +. +shadowrealm +- +in +- +dedicatedworker +. +html +" +ShadowRealmInDedicatedWorkerHandler +) + +( +" +GET +" +" +* +. +any +. +shadowrealm +- +in +- +sharedworker +. +html +" +ShadowRealmInSharedWorkerHandler +) + +( +" +GET +" +" +* +. +any +. +shadowrealm +- +in +- +serviceworker +. +html +" +ShadowRealmInServiceWorkerHandler +) + +( +" +GET +" +" +* +. +any +. +shadowrealm +- +in +- +audioworklet . html " -ShadowRealmHandler +ShadowRealmInAudioWorkletHandler ) ( @@ -4773,6 +6233,60 @@ ModuleWorkerHandler ) +( +" +GET +" +" +* +. +any +. +serviceworker +- +shadowrealm +. +js +" +ShadowRealmServiceWorkerWrapperHandler +) + +( +" +GET +" +" +* +. +any +. +worker +- +shadowrealm +. +js +" +ShadowRealmWorkerWrapperHandler +) + +( +" +GET +" +" +* +. +any +. +audioworklet +- +shadowrealm +. +js +" +ShadowRealmAudioWorkletWrapperHandler +) + ( " GET