aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRick Waldron <waldron.rick@gmail.com>2013-04-03 11:26:07 -0400
committerRick Waldron <waldron.rick@gmail.com>2013-04-03 11:26:07 -0400
commitfeea9394b75a5dcb16fad013a402b388f97cefba (patch)
treea4210a8f82b2bd7c7096c5a3ffbc9de97a1fc3f5 /src
parent05d55d08e74aca4e39a1f66e3dcb51036265039b (diff)
downloadjquery-feea9394b75a5dcb16fad013a402b388f97cefba.tar.gz
jquery-feea9394b75a5dcb16fad013a402b388f97cefba.zip
Fixes #13714. jQuery.globalEval gotcha w/ strings that contain valid, prologue position strict mode pragma
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/core.js23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/core.js b/src/core.js
index cae3a90e3..e37627459 100644
--- a/src/core.js
+++ b/src/core.js
@@ -515,10 +515,25 @@ jQuery.extend({
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 );
+ }
}
},