[Pkg-javascript-commits] [dojo] 27/87: backport [27791]; fixes #14406; !strict
David Prévot
taffit at moszumanska.debian.org
Thu Aug 21 17:39:16 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 1.7.5
in repository dojo.
commit 6b4c3d133d89bb18920722b9df4b504390bcd386
Author: Rawld Gill <rgill at altoviso.com>
Date: Wed Feb 8 07:34:41 2012 +0000
backport [27791]; fixes #14406; !strict
git-svn-id: http://svn.dojotoolkit.org/src/branches/1.7/dojo@27793 560b804f-0ae3-0310-86f3-f6aa0a117693
---
_base/kernel.js | 38 +++++++++++++++++++++++++++-----------
tests/_base/loader/bootstrap.js | 17 ++++++++++++++++-
2 files changed, 43 insertions(+), 12 deletions(-)
diff --git a/_base/kernel.js b/_base/kernel.js
index 5879607..4879c19 100644
--- a/_base/kernel.js
+++ b/_base/kernel.js
@@ -110,18 +110,34 @@ define(["../has", "./config", "require", "module"], function(has, config, requir
// is migrated. Absent specific advice otherwise, set extend-dojo to truthy.
has.add("extend-dojo", 1);
- if(has("dojo-loader")){
- dojo.eval = require.eval;
- }else{
- var eval_ =
- // use the function constructor so our eval is scoped close to (but not in) in the global space with minimal pollution
- new Function("__text", "return eval(__text);");
- dojo.eval = function(text, hint){
- // note: the four forward-slashes make the firebug hint work in ie9
- return eval_(text + "\r\n////@ sourceURL=" + hint);
- };
- }
+ dojo.eval = function(scriptText){
+ // summary:
+ // A legacy method created for use exclusively by internal Dojo methods. Do not use this method
+ // directly unless you understand its possibly-different implications on the platforms your are targeting.
+ // description:
+ // Makes an attempt to evaluate scriptText in the global scope. The function works correctly for browsers
+ // that support indirect eval.
+ //
+ // As usual, IE does not. On IE, the only way to implement global eval is to
+ // use execScript. Unfortunately, execScript does not return a value and breaks some current usages of dojo.eval.
+ // This implementation uses the technique of executing eval in the scope of a function that is a single scope
+ // frame below the global scope; thereby coming close to the global scope. Note carefully that
+ //
+ // dojo.eval("var pi = 3.14;");
+ //
+ // will define global pi in non-IE environments, but define pi only in a temporary local scope for IE. If you want
+ // to define a global variable using dojo.eval, write something like
+ //
+ // dojo.eval("window.pi = 3.14;")
+ // scriptText:
+ // The text to evaluation.
+ // returns:
+ // The result of the evaluation. Often `undefined`
+ };
+
+ (Function("d", "d.eval = function(){return d.global.eval ? d.global.eval(arguments[0]) : eval(arguments[0]);}"))(dojo);
+
if(has("host-rhino")){
dojo.exit = function(exitcode){
diff --git a/tests/_base/loader/bootstrap.js b/tests/_base/loader/bootstrap.js
index f46a3ef..616554c 100644
--- a/tests/_base/loader/bootstrap.js
+++ b/tests/_base/loader/bootstrap.js
@@ -1,4 +1,4 @@
-define(["dojo", "doh", "require"], function(dojo, doh, require){
+define(["dojo", "doh", "../../../_base/sniff", "require"], function(dojo, doh, has, require){
doh.register("tests._base._loader.bootstrap", [
function hasConsole(t){
t.assertTrue("console" in dojo.global);
@@ -96,6 +96,21 @@ define(["dojo", "doh", "require"], function(dojo, doh, require){
function evalWorks(t){
t.assertTrue(dojo.eval("(true)"));
t.assertFalse(dojo.eval("(false)"));
+ if(!has("ie")){
+ // eval truly executes in global scope for non IE
+ t.is(window.rawld, undefined);
+ dojo.eval("var rawld = 3.14;");
+ t.assertEqual(rawld, 3.14);
+ t.assertEqual(window.rawld, 3.14);
+ window.rawld = undefined;
+ }else{
+ // example of how to compensate for IE
+ t.is(window.rawld, undefined);
+ dojo.eval("window.rawld = 3.14;");
+ t.assertEqual(rawld, 3.14);
+ t.assertEqual(window.rawld, 3.14);
+ window.rawld = undefined;
+ }
},
function _mixin(t){
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git
More information about the Pkg-javascript-commits
mailing list