Debian Codegraph @

testing/web-platform/tests/resources/testharness-shadowrealm-inner.js

raw
1 // testharness file with ShadowRealm utilities to be imported inside ShadowRealm
2
3 /**
4 * Set up all properties on the ShadowRealm's global object that tests will
5 * expect to be present.
6 *
7 * @param {string} queryString - string to use as value for location.search,
8 * used for subsetting some tests
9 * @param {function} fetchAdaptor - a function that takes a resource URI and
10 * returns a function which itself takes a (resolve, reject) pair from the
11 * hosting realm, and calls resolve with the text result of fetching the
12 * resource, or reject with a string indicating the error that occurred
13 */
14 globalThis.setShadowRealmGlobalProperties = function (queryString, fetchAdaptor) {
15 globalThis.fetch_json = (resource) => {
16 const executor = fetchAdaptor(resource);
17 return new Promise(executor).then((s) => JSON.parse(s));
18 };
19
20 // Used only by idlharness.js
21 globalThis.fetch_spec = (spec) => {
22 const resource = `/interfaces/${spec}.idl`;
23 const executor = fetchAdaptor(resource);
24 return new Promise(executor).then(
25 idl => ({ spec, idl }),
26 () => {
27 throw new IdlHarnessError(`Error fetching ${resource}.`);
28 });
29 }
30
31 globalThis.location = { search: queryString };
32 };
33
34 globalThis.GLOBAL = {
35 isWindow: function() { return false; },
36 isWorker: function() { return false; },
37 isShadowRealm: function() { return true; },
38 };