global.js 768 B

123456789101112131415161718192021222324
  1. "use strict";
  2. /**
  3. * @license
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. exports.globalEval = void 0;
  8. var script_impl_1 = require("../../internals/script_impl");
  9. /**
  10. * Evaluates a SafeScript value in the given scope using eval.
  11. *
  12. * Strongly consider avoiding this, as eval blocks CSP adoption and does not
  13. * benefit from compiler optimizations.
  14. */
  15. function globalEval(win, script) {
  16. var trustedScript = (0, script_impl_1.unwrapScript)(script);
  17. var result = win.eval(trustedScript);
  18. if (result === trustedScript) {
  19. // https://crbug.com/1024786 manifesting in workers.
  20. result = win.eval(trustedScript.toString());
  21. }
  22. return result;
  23. }
  24. exports.globalEval = globalEval;