diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2015-11-13 19:48:45 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2015-11-13 20:04:54 +0300 |
commit | 91acd85b167e39e05e8f4fb1be6f75cdcac9c466 (patch) | |
tree | 48c6ab809fdbfb90834563046b9096b455f4a826 /src/core.js | |
parent | 9d1d4c272a58ced36242d90b3f0462c2bbb972a3 (diff) | |
download | jquery-91acd85b167e39e05e8f4fb1be6f75cdcac9c466.tar.gz jquery-91acd85b167e39e05e8f4fb1be6f75cdcac9c466.zip |
Revert "Ajax: Always use script injection in globalEval"
This reverts commit bbdfbb4ee859fe9319b348d88120ddc2c9efbd63.
Diffstat (limited to 'src/core.js')
-rw-r--r-- | src/core.js | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/core.js b/src/core.js index 72f4de2a0..d3c08c636 100644 --- a/src/core.js +++ b/src/core.js @@ -262,12 +262,26 @@ jQuery.extend( { }, // Evaluates a script in a global context - globalEval: function( code, context ) { - context = context || document; - var script = context.createElement( "script" ); - - script.text = code; - context.head.appendChild( script ).parentNode.removeChild( script ); + globalEval: function( code ) { + var script, + indirect = eval; + + code = jQuery.trim( code ); + + if ( code ) { + // If the code includes a valid, prologue position + // strict mode pragma, execute code by injecting a + // script tag into the document. + if ( code.indexOf("use strict") === 1 ) { + script = document.createElement("script"); + script.text = code; + document.head.appendChild( script ).parentNode.removeChild( script ); + } else { + // Otherwise, avoid the DOM node creation, insertion + // and removal by using an indirect global eval + indirect( code ); + } + } }, // Convert dashed to camelCase; used by the css and data modules |