a0fe72b8e1f6eaf857148297b4ccda43b26623cb14b0828946f0fe7c0949d5168b1f518330568ca584dee60a317dea789911952ccdef617ceae7933cf5abd4 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. define( [
  2. "../var/document"
  3. ], function( document ) {
  4. "use strict";
  5. var preservedScriptAttributes = {
  6. type: true,
  7. src: true,
  8. nonce: true,
  9. noModule: true
  10. };
  11. function DOMEval( code, node, doc ) {
  12. doc = doc || document;
  13. var i, val,
  14. script = doc.createElement( "script" );
  15. script.text = code;
  16. if ( node ) {
  17. for ( i in preservedScriptAttributes ) {
  18. // Support: Firefox 64+, Edge 18+
  19. // Some browsers don't support the "nonce" property on scripts.
  20. // On the other hand, just using `getAttribute` is not enough as
  21. // the `nonce` attribute is reset to an empty string whenever it
  22. // becomes browsing-context connected.
  23. // See https://github.com/whatwg/html/issues/2369
  24. // See https://html.spec.whatwg.org/#nonce-attributes
  25. // The `node.getAttribute` check was added for the sake of
  26. // `jQuery.globalEval` so that it can fake a nonce-containing node
  27. // via an object.
  28. val = node[ i ] || node.getAttribute && node.getAttribute( i );
  29. if ( val ) {
  30. script.setAttribute( i, val );
  31. }
  32. }
  33. }
  34. doc.head.appendChild( script ).parentNode.removeChild( script );
  35. }
  36. return DOMEval;
  37. } );