Debian Codegraph @

testing/web-platform/tests/resources/test-only-api.js

raw
1 'use strict';
2
3 /* Whether the browser is Chromium-based with MojoJS enabled */
4 const isChromiumBased = 'MojoInterfaceInterceptor' in self;
5 /* Whether the browser is WebKit-based with internal test-only API enabled */
6 const isWebKitBased = !isChromiumBased && 'internals' in self;
7
8 /**
9 * Loads a script in a window or worker.
10 *
11 * @param {string} path - A script path
12 * @returns {Promise}
13 */
14 function loadScript(path) {
15 if (typeof document === 'undefined') {
16 // Workers (importScripts is synchronous and may throw.)
17 importScripts(path);
18 return Promise.resolve();
19 } else {
20 // Window
21 const script = document.createElement('script');
22 script.src = path;
23 script.async = false;
24 const p = new Promise((resolve, reject) => {
25 script.onload = () => { resolve(); };
26 script.onerror = e => { reject(`Error loading ${path}`); };
27 })
28 document.head.appendChild(script);
29 return p;
30 }
31 }