mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Revert "Ajax: Always use script injection in globalEval"
This reverts commit bbdfbb4ee8
.
This commit is contained in:
parent
9d1d4c272a
commit
91acd85b16
22
src/core.js
22
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;
|
||||
|
||||
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;
|
||||
context.head.appendChild( script ).parentNode.removeChild( script );
|
||||
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
|
||||
|
@ -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...-->
|
||||
<script type="text/javascript" src="../longLoadScript.php?sleep=1"></script>
|
||||
<script type="text/javascript" src="longLoadScript.php?sleep=1"></script>
|
||||
<div id="container" style="height: 300px"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1624,7 +1624,15 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
|
||||
jQuery.ajax( {
|
||||
url: "data/badjson.js",
|
||||
dataType: "script",
|
||||
throws: true
|
||||
throws: true,
|
||||
// Global events get confused by the exception
|
||||
global: false,
|
||||
success: function() {
|
||||
ok( false, "Success." );
|
||||
},
|
||||
error: function() {
|
||||
ok( false, "Error." );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -170,21 +170,6 @@ QUnit.test( "globalEval with 'use strict'", function( assert ) {
|
||||
assert.equal( window.strictEvalTest, 1, "Test variable declarations are global (strict mode)" );
|
||||
} );
|
||||
|
||||
QUnit.test( "globalEval execution after script injection (#7862)", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
var now,
|
||||
script = document.createElement( "script" );
|
||||
|
||||
script.src = "data/longLoadScript.php?sleep=2";
|
||||
|
||||
now = jQuery.now();
|
||||
document.body.appendChild( script );
|
||||
|
||||
jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";" );
|
||||
assert.ok( window.strictEvalTest - now < 500, "Code executed synchronously" );
|
||||
} );
|
||||
|
||||
// This is not run in AMD mode
|
||||
if ( jQuery.noConflict ) {
|
||||
QUnit.test( "noConflict", function( assert ) {
|
||||
|
@ -2297,44 +2297,27 @@ QUnit.test( "Ensure oldIE creates a new set on appendTo (#8894)", function( asse
|
||||
assert.strictEqual( jQuery( "<p/>" ).appendTo( "<div/>" ).end().length, jQuery( "<p>test</p>" ).appendTo( "<div/>" ).end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" );
|
||||
} );
|
||||
|
||||
QUnit.asyncTest( "html() - script exceptions bubble (#11743)", 2, function( assert ) {
|
||||
QUnit.test( "html() - script exceptions bubble (#11743)", function( assert ) {
|
||||
assert.expect( 3 );
|
||||
|
||||
// Support: Android 2.3 only
|
||||
// Android 2.3 doesn't fire the window.onerror handler, just accept the reality there.
|
||||
if ( /android 2\.3/i.test( navigator.userAgent ) ) {
|
||||
assert.ok( true, "Test skipped, Android 2.3 doesn't fire window.onerror for " +
|
||||
"errors in dynamically included scripts" );
|
||||
assert.ok( true, "Test skipped, Android 2.3 doesn't fire window.onerror for " +
|
||||
"errors in dynamically included scripts" );
|
||||
QUnit.start();
|
||||
return;
|
||||
}
|
||||
|
||||
var onerror = window.onerror;
|
||||
|
||||
setTimeout( function() {
|
||||
window.onerror = onerror;
|
||||
|
||||
QUnit.start();
|
||||
}, 1000 );
|
||||
|
||||
window.onerror = function() {
|
||||
assert.ok( true, "Exception thrown" );
|
||||
assert.throws(function() {
|
||||
jQuery("#qunit-fixture").html("<script>undefined(); ok( false, 'Exception not thrown' );</script>");
|
||||
assert.ok( false, "Exception ignored" );
|
||||
}, "Exception bubbled from inline script" );
|
||||
|
||||
if ( jQuery.ajax ) {
|
||||
var onerror = window.onerror;
|
||||
window.onerror = function() {
|
||||
assert.ok( true, "Exception thrown in remote script" );
|
||||
ok( true, "Exception thrown in remote script" );
|
||||
};
|
||||
|
||||
jQuery("#qunit-fixture").html("<script src='data/badcall.js'></script>");
|
||||
assert.ok( true, "Exception ignored" );
|
||||
window.onerror = onerror;
|
||||
} else {
|
||||
assert.ok( true, "No jQuery.ajax" );
|
||||
assert.ok( true, "No jQuery.ajax" );
|
||||
}
|
||||
};
|
||||
|
||||
jQuery( "#qunit-fixture" ).html( "<script>undefined();</script>" );
|
||||
});
|
||||
|
||||
QUnit.test( "checked state is cloned with clone()", function( assert ) {
|
||||
|
Loading…
Reference in New Issue
Block a user