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" ); + globalEval: function( code ) { + var script, + indirect = eval; - script.text = code; - context.head.appendChild( script ).parentNode.removeChild( script ); + 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 diff --git a/test/data/longLoadScript.php b/test/data/event/longLoadScript.php similarity index 100% rename from test/data/longLoadScript.php rename to test/data/event/longLoadScript.php diff --git a/test/data/event/syncReady.html b/test/data/event/syncReady.html index dfa9ac337..e0885707e 100644 --- a/test/data/event/syncReady.html +++ b/test/data/event/syncReady.html @@ -17,7 +17,7 @@ jQuery( document ).ready(function () { oldIE into thinking the dom is ready, but it's not... leaving this check here for future trailblazers to attempt fixing this...--> - +