11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci/* Whether the browser is Chromium-based with MojoJS enabled */
41cb0ef41Sopenharmony_ciconst isChromiumBased = 'MojoInterfaceInterceptor' in self;
51cb0ef41Sopenharmony_ci/* Whether the browser is WebKit-based with internal test-only API enabled */
61cb0ef41Sopenharmony_ciconst isWebKitBased = !isChromiumBased && 'internals' in self;
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci/**
91cb0ef41Sopenharmony_ci * Loads a script in a window or worker.
101cb0ef41Sopenharmony_ci *
111cb0ef41Sopenharmony_ci * @param {string} path - A script path
121cb0ef41Sopenharmony_ci * @returns {Promise}
131cb0ef41Sopenharmony_ci */
141cb0ef41Sopenharmony_cifunction loadScript(path) {
151cb0ef41Sopenharmony_ci  if (typeof document === 'undefined') {
161cb0ef41Sopenharmony_ci    // Workers (importScripts is synchronous and may throw.)
171cb0ef41Sopenharmony_ci    importScripts(path);
181cb0ef41Sopenharmony_ci    return Promise.resolve();
191cb0ef41Sopenharmony_ci  } else {
201cb0ef41Sopenharmony_ci    // Window
211cb0ef41Sopenharmony_ci    const script = document.createElement('script');
221cb0ef41Sopenharmony_ci    script.src = path;
231cb0ef41Sopenharmony_ci    script.async = false;
241cb0ef41Sopenharmony_ci    const p = new Promise((resolve, reject) => {
251cb0ef41Sopenharmony_ci      script.onload = () => { resolve(); };
261cb0ef41Sopenharmony_ci      script.onerror = e => { reject(`Error loading ${path}`); };
271cb0ef41Sopenharmony_ci    })
281cb0ef41Sopenharmony_ci    document.head.appendChild(script);
291cb0ef41Sopenharmony_ci    return p;
301cb0ef41Sopenharmony_ci  }
311cb0ef41Sopenharmony_ci}
32