Commit
…rick to ensure proper context. Unit tests added.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -561,24 +561,17 @@ jQuery.extend({ | |
|
||
noop: function() {}, | ||
|
||
// Evalulates a script in a global context | ||
// 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 ) { | ||
if ( data && rnotwhite.test(data) ) { | ||
// Inspired by code by Andrea Giammarchi | ||
// http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html | ||
var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement, | ||
script = document.createElement( "script" ); | ||
|
||
if ( jQuery.support.scriptEval() ) { | ||
script.appendChild( document.createTextNode( data ) ); | ||
} else { | ||
script.text = data; | ||
} | ||
|
||
// Use insertBefore instead of appendChild to circumvent an IE6 bug. | ||
// This arises when a base node is used (#2709). | ||
head.insertBefore( script, head.firstChild ); | ||
head.removeChild( script ); | ||
if ( data && rnotwhite.test( 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 ) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dmethvin
Member
|
||
window[ "eval" ].call( window, data ); | ||
} )( data ); | ||
} | ||
}, | ||
|
||
|
3 comments
on commit f3c6077
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jaubourg, I'm going to be nit-picky here and ask why there was no ticket for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are tickets actually. They are all related to Firefox not executing the string passed to globalEval synchronously when using script tag injection and non-async scripts are being loaded (jdalton confirmed to me this was fixed in firefox a few months ago provided you set the injected script tag as async).
But, in the end, the globalEval rewrite is a by-product of the support rewrite, I just put it in a separate commit so that it could be "inspected" separately. Not feature-testing for how to add text to a script tag saves a lot of size in support.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Details on FF4 async stuff https://developer.mozilla.org/En/HTML/Element/Script
noooos! 'execScript' is soo bad. It kills any meaningful error messages. Instead script inject that calls eval().