aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core.js23
-rw-r--r--test/data/event/syncReady.html2
-rw-r--r--test/data/longLoadScript.php (renamed from test/data/event/longLoadScript.php)0
-rw-r--r--test/unit/ajax.js10
-rw-r--r--test/unit/core.js13
-rw-r--r--test/unit/manipulation.js40
6 files changed, 41 insertions, 47 deletions
diff --git a/src/core.js b/src/core.js
index da6aa833a..15e2077aa 100644
--- a/src/core.js
+++ b/src/core.js
@@ -256,25 +256,10 @@ jQuery.extend({
// Evaluates a script in a global context
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 );
- }
- }
+ var script = document.createElement( "script" );
+
+ script.text = code;
+ document.head.appendChild( script ).parentNode.removeChild( script );
},
// Convert dashed to camelCase; used by the css and data modules
diff --git a/test/data/event/syncReady.html b/test/data/event/syncReady.html
index e0885707e..dfa9ac337 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...-->
-<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>
diff --git a/test/data/event/longLoadScript.php b/test/data/longLoadScript.php
index ba47168b4..ba47168b4 100644
--- a/test/data/event/longLoadScript.php
+++ b/test/data/longLoadScript.php
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 0f6de4696..0132085c8 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1433,15 +1433,7 @@ module( "ajax", {
jQuery.ajax({
url: "data/badjson.js",
dataType: "script",
- throws: true,
- // Global events get confused by the exception
- global: false,
- success: function() {
- ok( false, "Success." );
- },
- error: function() {
- ok( false, "Error." );
- }
+ throws: true
});
});
diff --git a/test/unit/core.js b/test/unit/core.js
index a266d9d9d..3205f6d8d 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -222,6 +222,19 @@ test( "globalEval with 'use strict'", function() {
equal( window.strictEvalTest, 1, "Test variable declarations are global (strict mode)" );
});
+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);
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 057ddd56d..b9d59fc4d 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -2194,28 +2194,32 @@ 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() {
+ var onerror = window.onerror;
- expect( 3 );
+ setTimeout(function() {
+ window.onerror = onerror;
- throws(function() {
- jQuery("#qunit-fixture").html("<script>undefined(); ok( false, 'Exception not thrown' );</script>");
- ok( false, "Exception ignored" );
- }, "Exception bubbled from inline script" );
+ start();
+ }, 1000 );
- if ( jQuery.ajax ) {
- var onerror = window.onerror;
- window.onerror = function() {
- ok( true, "Exception thrown in remote script" );
- };
+ window.onerror = function() {
+ ok( true, "Exception thrown" );
- jQuery("#qunit-fixture").html("<script src='data/badcall.js'></script>");
- ok( true, "Exception ignored" );
- window.onerror = onerror;
- } else {
- ok( true, "No jQuery.ajax" );
- ok( true, "No jQuery.ajax" );
- }
+ 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() {