Ajax: Always use script injection in globalEval

Fixes #14757
Ref bbdfbb4ee8
This commit is contained in:
Oleg Gaidarenko
2014-06-16 01:45:24 +04:00
parent 76294e1e9e
commit 37f0f7f42c
6 changed files with 62 additions and 44 deletions

View File

@@ -1468,24 +1468,18 @@ module( "ajax", {
}
});
test( "#11743 - jQuery.ajax() - script, throws exception", 1, function() {
throws(function() {
jQuery.ajax({
url: "data/badjson.js",
dataType: "script",
"throws": true,
// TODO find a way to test this asynchronously, too
async: false,
// Global events get confused by the exception
global: false,
success: function() {
ok( false, "Success." );
},
error: function() {
ok( false, "Error." );
}
});
}, "exception bubbled" );
asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function() {
var onerror = window.onerror;
window.onerror = function() {
ok( true, "Exception thrown" );
window.onerror = onerror;
start();
};
jQuery.ajax({
url: "data/badjson.js",
dataType: "script",
"throws": true
});
});
jQuery.each( [ "method", "type" ], function( _, globalOption ) {

View File

@@ -214,6 +214,19 @@ test( "globalEval", function() {
equal( window.globalEvalTest, 3, "Test context (this) is the window object" );
});
test( "globalEval execution after script injection (#7862)", 1, function() {
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() + ";");
ok( window.strictEvalTest - now < 500, "Code executed synchronously" );
});
test("noConflict", function() {
expect(7);

View File

@@ -2263,23 +2263,33 @@ test( "Ensure oldIE creates a new set on appendTo (#8894)", function() {
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" );
});
test( "html() - script exceptions bubble (#11743)", function() {
asyncTest( "html() - script exceptions bubble (#11743)", 2, function() {
expect( 2 );
var onerror = window.onerror;
throws(function() {
jQuery("#qunit-fixture").html("<script>undefined(); ok( false, 'Exception not thrown' );</script>");
ok( false, "Exception ignored" );
}, "Exception bubbled from inline script" );
setTimeout(function() {
window.onerror = onerror;
if ( jQuery.ajax ) {
throws(function() {
jQuery("#qunit-fixture").html("<script src='data/badcall.js'></script>");
ok( false, "Exception ignored" );
}, "Exception thrown in remote script" );
} else {
ok( true, "No jQuery.ajax" );
}
start();
}, 1000 );
window.onerror = function() {
ok( true, "Exception thrown" );
if ( jQuery.ajax ) {
window.onerror = function() {
ok( true, "Exception thrown in remote script" );
};
jQuery( "#qunit-fixture" ).html( "<script src='data/badcall.js'></script>" );
ok( true, "Exception ignored" );
} else {
ok( true, "No jQuery.ajax" );
ok( true, "No jQuery.ajax" );
}
};
jQuery( "#qunit-fixture" ).html( "<script>undefined();</script>" );
});
test( "checked state is cloned with clone()", function() {