},
// Evaluates a script in a global context
+ // Workarounds based on findings by Jim Driscoll
+ // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval: function( data ) {
-
- // Inspired by code by Andrea Giammarchi
- // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
- var head = document.head || jQuery( "head" )[ 0 ] || document.documentElement,
- script = document.createElement( "script" );
-
- script.text = data;
-
- head.appendChild( script );
- head.removeChild( script );
+ if ( data && jQuery.trim( data ) ) {
+ // We use execScript on Internet Explorer
+ // We use an anonymous function so that context is window
+ // rather than jQuery in Firefox
+ ( window.execScript || function( data ) {
+ window[ "eval" ].call( window, data );
+ } )( data );
+ }
},
// Convert dashed to camelCase; used by the css and data modules
jQuery.fx.start = function() {
if ( !timerId ) {
- timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
+ timerId = window.setInterval( jQuery.fx.tick, jQuery.fx.interval );
}
};
jQuery.fx.stop = function() {
- clearInterval( timerId );
+ window.clearInterval( timerId );
timerId = null;
};
--- /dev/null
+<?php
+sleep((int)$_GET['sleep']);
+header('Content-type: text/javascript');
+?>
\ No newline at end of file
<body>
<script type="text/javascript">
-jQuery( document ).ready(function() {
+jQuery( document ).ready(function () {
window.parent.iframeCallback( jQuery('#container').length === 1 );
});
</script>
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>
+++ /dev/null
-<?php
-sleep((int)$_GET['sleep']);
-header('Content-type: text/javascript');
-?>
\ No newline at end of file
};
} );
- QUnit.asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function( assert ) {
-
- // 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" );
- QUnit.start();
- return;
- }
-
- var onerror = window.onerror;
- window.onerror = function() {
- assert.ok( true, "Exception thrown" );
- window.onerror = onerror;
- QUnit.start();
- };
- jQuery.ajax( {
- url: "data/badjson.js",
- dataType: "script",
- throws: true
- } );
- } );
+ 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" );
+ });
jQuery.each( [ "method", "type" ], function( _, globalOption ) {
function request( assert, option ) {
assert.equal( window.globalEvalTest, 3, "Test context (this) is the window object" );
} );
-QUnit.test( "globalEval execution after script injection (#7862)", function( assert ) {
- assert.expect( 1 );
+if ( jQuery.noConflict ) {
+ QUnit.test( "noConflict", function( assert ) {
+ assert.expect( 7 );
- var now,
- script = document.createElement( "script" );
+ var $$ = jQuery;
+
+ assert.strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
+ assert.strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." );
+ assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
- script.src = "data/longLoadScript.php?sleep=2";
+ jQuery = $ = $$;
- now = jQuery.now();
- document.body.appendChild( script );
+ assert.strictEqual( jQuery.noConflict( true ), $$, "noConflict returned the jQuery object" );
+ assert.strictEqual( window[ "jQuery" ], originaljQuery, "Make sure jQuery was reverted." );
+ assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
+ assert.ok( $$().pushStack( [] ), "Make sure that jQuery still works." );
- jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";" );
- assert.ok( window.strictEvalTest - now < 500, "Code executed synchronously" );
-} );
+ window[ "jQuery" ] = jQuery = $$;
+ } );
+}
// This is not run in AMD mode
if ( jQuery.noConflict ) {
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 ) {
- // 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 );
+test( "html() - script exceptions bubble (#11743)", function() {
- window.onerror = function() {
- assert.ok( true, "Exception thrown" );
+ expect( 2 );
- if ( jQuery.ajax ) {
- window.onerror = function() {
- assert.ok( true, "Exception thrown in remote script" );
- };
+ throws(function() {
+ jQuery("#qunit-fixture").html("<script>undefined(); ok( false, 'Exception not thrown' );</script>");
+ ok( false, "Exception ignored" );
+ }, "Exception bubbled from inline script" );
- jQuery( "#qunit-fixture" ).html( "<script src='data/badcall.js'></script>" );
- assert.ok( true, "Exception ignored" );
- } else {
- assert.ok( true, "No jQuery.ajax" );
- assert.ok( true, "No jQuery.ajax" );
- }
- };
-
- jQuery( "#qunit-fixture" ).html( "<script>undefined();</script>" );
-} );
+ 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" );
+ }
+});
QUnit.test( "checked state is cloned with clone()", function( assert ) {