summaryrefslogtreecommitdiffstats
path: root/test/wpt/tests/resources/idlharness-shadowrealm.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
commit0b6210cd37b68b94252cb798598b12974a20e1c1 (patch)
treee371686554a877842d95aa94f100bee552ff2a8e /test/wpt/tests/resources/idlharness-shadowrealm.js
parentInitial commit. (diff)
downloadnode-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz
node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/wpt/tests/resources/idlharness-shadowrealm.js')
-rw-r--r--test/wpt/tests/resources/idlharness-shadowrealm.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/wpt/tests/resources/idlharness-shadowrealm.js b/test/wpt/tests/resources/idlharness-shadowrealm.js
new file mode 100644
index 0000000..9484ca6
--- /dev/null
+++ b/test/wpt/tests/resources/idlharness-shadowrealm.js
@@ -0,0 +1,61 @@
+// TODO: it would be nice to support `idl_array.add_objects`
+function fetch_text(url) {
+ return fetch(url).then(function (r) {
+ if (!r.ok) {
+ throw new Error("Error fetching " + url + ".");
+ }
+ return r.text();
+ });
+}
+
+/**
+ * idl_test_shadowrealm is a promise_test wrapper that handles the fetching of the IDL, and
+ * running the code in a `ShadowRealm`, avoiding repetitive boilerplate.
+ *
+ * @see https://github.com/tc39/proposal-shadowrealm
+ * @param {String[]} srcs Spec name(s) for source idl files (fetched from
+ * /interfaces/{name}.idl).
+ * @param {String[]} deps Spec name(s) for dependency idl files (fetched
+ * from /interfaces/{name}.idl). Order is important - dependencies from
+ * each source will only be included if they're already know to be a
+ * dependency (i.e. have already been seen).
+ */
+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; },
+ }; undefined;
+ `);
+ const specs = await Promise.all(srcs.concat(deps).map(spec => {
+ return fetch_text("/interfaces/" + spec + ".idl");
+ }));
+ const idls = JSON.stringify(specs);
+ await new Promise(
+ realm.evaluate(`(resolve,reject) => {
+ (async () => {
+ await import("/resources/testharness.js");
+ await import("/resources/WebIDLParser.js");
+ await import("/resources/idlharness.js");
+ const idls = ${idls};
+ const idl_array = new IdlArray();
+ for (let i = 0; i < ${srcs.length}; i++) {
+ idl_array.add_idls(idls[i]);
+ }
+ for (let i = ${srcs.length}; i < ${srcs.length + deps.length}; i++) {
+ idl_array.add_dependency_idls(idls[i]);
+ }
+ idl_array.test();
+ })().then(resolve, (e) => reject(e.toString()));
+ }`)
+ );
+ await fetch_tests_from_shadow_realm(realm);
+ });
+}
+// vim: set expandtab shiftwidth=4 tabstop=4 foldmarker=@{,@} foldmethod=marker: