global.mjs 619 B

1234567891011121314151617181920
  1. /**
  2. * @license
  3. * SPDX-License-Identifier: Apache-2.0
  4. */
  5. import { unwrapScript } from '../../internals/script_impl';
  6. /**
  7. * Evaluates a SafeScript value in the given scope using eval.
  8. *
  9. * Strongly consider avoiding this, as eval blocks CSP adoption and does not
  10. * benefit from compiler optimizations.
  11. */
  12. export function globalEval(win, script) {
  13. const trustedScript = unwrapScript(script);
  14. let result = win.eval(trustedScript);
  15. if (result === trustedScript) {
  16. // https://crbug.com/1024786 manifesting in workers.
  17. result = win.eval(trustedScript.toString());
  18. }
  19. return result;
  20. }