Skip to content

Commit

Permalink
Revert "testharness.js: fix shadow realm detection (#33668)"
Browse files Browse the repository at this point in the history
This reverts commit ce3cb95.
  • Loading branch information
lucacasonato committed Apr 19, 2022
1 parent ce3cb95 commit 9e8baee
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 22 deletions.
1 change: 0 additions & 1 deletion cookie-store/serviceworker_cookieStore_cross_origin.js
@@ -1,7 +1,6 @@
self.GLOBAL = {
isWindow: () => false,
isWorker: () => false,
isShadowRealm: () => false,
};

self.addEventListener('message', async event => {
Expand Down
10 changes: 1 addition & 9 deletions resources/idlharness-shadowrealm.js
Expand Up @@ -29,15 +29,7 @@ function idl_test_shadowrealm(srcs, deps) {
promise_setup(async t => {
const realm = new ShadowRealm();
// https://github.com/web-platform-tests/wpt/issues/31996
realm.evaluate("globalThis.self = globalThis; undefined;");

realm.evaluate(`
globalThis.self.GLOBAL = {
isWindow: function() { return false; },
isWorker: function() { return false; },
isShadowRealm: function() { return true; },
};
`);
realm.evaluate("globalThis.self = globalThis; undefined");

const ss = await Promise.all(script_urls.map(url => fetch_text(url)));
for (const s of ss) {
Expand Down
10 changes: 6 additions & 4 deletions resources/testharness.js
Expand Up @@ -537,11 +537,13 @@
}
/* 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
* check if the there is a GLOBAL.isShadowRealm() property
* on the global object. that was set by the test harness when it
* created the ShadowRealm.
* 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
*/
if (global_scope.GLOBAL.isShadowRealm()) {
if ('AbortController' in global_scope) {
return new ShadowRealmTestEnvironment();
}

Expand Down
8 changes: 2 additions & 6 deletions tools/serve/serve.py
Expand Up @@ -259,7 +259,6 @@ class AnyHtmlHandler(HtmlWrapperHandler):
self.GLOBAL = {
isWindow: function() { return true; },
isWorker: function() { return false; },
isShadowRealm: function() { return false; },
};
</script>
<script src="/resources/testharness.js"></script>
Expand Down Expand Up @@ -361,13 +360,12 @@ class ShadowRealmHandler(HtmlWrapperHandler):
await new Promise(r.evaluate(`
(resolve, reject) => {
(async () => {
await import("/resources/testharness.js");
%(script)s
globalThis.self.GLOBAL = {
isWindow: function() { return false; },
isWorker: function() { return false; },
isShadowRealm: function() { return true; },
};
await import("/resources/testharness.js");
%(script)s
await import("%(path)s");
})().then(resolve, (e) => reject(e.toString()));
}
Expand Down Expand Up @@ -413,7 +411,6 @@ class ClassicWorkerHandler(BaseWorkerHandler):
self.GLOBAL = {
isWindow: function() { return false; },
isWorker: function() { return true; },
isShadowRealm: function() { return false; },
};
importScripts("/resources/testharness.js");
%(script)s
Expand All @@ -431,7 +428,6 @@ class ModuleWorkerHandler(BaseWorkerHandler):
self.GLOBAL = {
isWindow: function() { return false; },
isWorker: function() { return true; },
isShadowRealm: function() { return false; },
};
import "/resources/testharness.js";
%(script)s
Expand Down
1 change: 0 additions & 1 deletion tools/wptserve/tests/functional/docroot/bar.any.worker.js
Expand Up @@ -2,7 +2,6 @@
self.GLOBAL = {
isWindow: function() { return false; },
isWorker: function() { return true; },
isShadowRealm: function() { return false; },
};
importScripts("/resources/testharness.js");

Expand Down
1 change: 0 additions & 1 deletion tools/wptserve/tests/functional/docroot/foo.any.html
Expand Up @@ -5,7 +5,6 @@
self.GLOBAL = {
isWindow: function() { return true; },
isWorker: function() { return false; },
isShadowRealm: function() { return false; },
};
</script>
<script src="/resources/testharness.js"></script>
Expand Down

0 comments on commit 9e8baee

Please sign in to comment.