Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testharness.js: fix shadow realm detection #33668

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions resources/testharness.js
Expand Up @@ -537,13 +537,11 @@
}
/* Shadow realm global objects are _ordinary_ objects (i.e. their prototype is
* Object) so we don't have a nice `instanceof` test to use; instead, we
* can look for the presence of web APIs that wouldn't be available in
* environments not listed above:
*
* As long as, within the shadow realm, we load the testharness before
* other libraries, this won't have any false positives, even in e.g. node
* check if the there is a TESTHARNESSJS_IS_INSIDE_SHADOW_REALM property
* on the global object. that was set by the test harness when it
* created the ShadowRealm.
*/
if ('AbortController' in global_scope) {
if (global_scope.TESTHARNESSJS_IS_INSIDE_SHADOW_REALM) {
return new ShadowRealmTestEnvironment();
}

Expand Down
1 change: 1 addition & 0 deletions tools/serve/serve.py
Expand Up @@ -360,6 +360,7 @@ class ShadowRealmHandler(HtmlWrapperHandler):
await new Promise(r.evaluate(`
(resolve, reject) => {
(async () => {
globalThis.TESTHARNESSJS_IS_INSIDE_SHADOW_REALM = true;
lucacasonato marked this conversation as resolved.
Show resolved Hide resolved
await import("/resources/testharness.js");
%(script)s
globalThis.self.GLOBAL = {
Expand Down