Files
tubestation/testing/web-platform/tests/resources/test-only-api.js
Ken Rockot edc98f091b Bug 1690075 [wpt PR 27429] - Migrate remaining WPT to Mojo JS modules, a=testonly
Automatic update from web-platform-tests
Migrate remaining WPT to Mojo JS modules

All remaining WPT using Mojo bindings are migrated to newer module-based
bindings here. Support for loading older bindings variants in WPT is
removed.

Bug: 1004256
Change-Id: I630a6ddb0e5b89f5b7e6c538a273c3725a485aae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2664907
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: Stephen McGruer <smcgruer@chromium.org>
Reviewed-by: Michael Moss <mmoss@chromium.org>
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#849713}

--

wpt-commits: e3b2fa58ec722818ab212125275f89f3c8f40d32
wpt-pr: 27429
2021-02-08 22:55:28 +00:00

32 lines
932 B
JavaScript

'use strict';
/* Whether the browser is Chromium-based with MojoJS enabled */
const isChromiumBased = 'MojoInterfaceInterceptor' in self;
/* Whether the browser is WebKit-based with internal test-only API enabled */
const isWebKitBased = !isChromiumBased && 'internals' in self;
/**
* Loads a script in a window or worker.
*
* @param {string} path - A script path
* @returns {Promise}
*/
function loadScript(path) {
if (typeof document === 'undefined') {
// Workers (importScripts is synchronous and may throw.)
importScripts(path);
return Promise.resolve();
} else {
// Window
const script = document.createElement('script');
script.src = path;
script.async = false;
const p = new Promise((resolve, reject) => {
script.onload = () => { resolve(); };
script.onerror = e => { reject(`Error loading ${path}`); };
})
document.head.appendChild(script);
return p;
}
}