noop: function() {},
// Evaluates a script in a global context
- globalEval: function( data ) {
- var indirect = eval;
- if ( jQuery.trim( data ) ) {
- indirect( data + ";" );
+ 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 );
+ }
}
},
equal( window.globalEvalTest, 3, "Test context (this) is the window object" );
});
+test( "globalEval with 'use strict'", function() {
+ expect( 1 );
+ Globals.register("strictEvalTest");
+
+ jQuery.globalEval("'use strict'; var strictEvalTest = 1;");
+ equal( window.strictEvalTest, 1, "Test variable declarations are global (strict mode)" );
+});
+
test("noConflict", function() {
expect(7);