mirror of
https://github.com/jquery/jquery.git
synced 2026-02-02 21:55:04 -05:00
Fixes #13714. jQuery.globalEval gotcha w/ strings that contain valid, prologue position strict mode pragma
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
This commit is contained in:
23
src/core.js
23
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 );
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user