[Pkg-javascript-commits] [dojo] 29/87: backport [27774], fixes #14375; !strict
David Prévot
taffit at moszumanska.debian.org
Thu Aug 21 17:39:17 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 abf5ab3b75e08a75ae21493ab581fc3df550350d
Author: Rawld Gill <rgill at altoviso.com>
Date: Wed Feb 8 07:47:09 2012 +0000
backport [27774], fixes #14375; !strict
git-svn-id: http://svn.dojotoolkit.org/src/branches/1.7/dojo@27795 560b804f-0ae3-0310-86f3-f6aa0a117693
---
i18n.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++----
tests/i18n.html | 24 ++++++++++++++++++++----
2 files changed, 71 insertions(+), 8 deletions(-)
diff --git a/i18n.js b/i18n.js
index fd45503..7e4ed85 100644
--- a/i18n.js
+++ b/i18n.js
@@ -118,6 +118,9 @@ define(["./_base/kernel", "require", "./has", "./_base/array", "./_base/lang", "
});
};
+ if(has("dojo-unit-tests")){
+ var unitTests = thisModule.unitTests = [];
+ }
has.add("dojo-v1x-i18n-Api",
// if true, define the v1.x i18n functions
@@ -126,13 +129,27 @@ define(["./_base/kernel", "require", "./has", "./_base/array", "./_base/lang", "
if(has("dojo-v1x-i18n-Api")){
var
+ __evalError = {},
+
evalBundle=
- // keep the minifiers off our define!
+ // use the function ctor to keep the minifiers away and come close to global scope
// if bundle is an AMD bundle, then __amdResult will be defined; otherwise it's a pre-amd bundle and the bundle value is returned by eval
- new Function("bundle", "var __preAmdResult, __amdResult; function define(bundle){__amdResult= bundle;} __preAmdResult= eval(bundle); return [__preAmdResult, __amdResult];"),
+ new Function("bundle, __evalError",
+ "var __amdResult, define = function(x){__amdResult= x;};" +
+ "return [(function(){" +
+ "try{eval(arguments[0]);}catch(e){}" +
+ "if(__amdResult)return 0;" +
+ "try{return eval('('+arguments[0]+')');}" +
+ "catch(e){__evalError.e = e; return __evalError;}" +
+ "})(arguments[0]) , __amdResult];"
+ ),
fixup= function(url, preAmdResult, amdResult){
// nls/<locale>/<bundle-name> indicates not the root.
+ if(preAmdResult===__evalError){
+ console.error("failed to evaluate i18n bundle; url=" + url, __evalError.e);
+ return {};
+ }
return preAmdResult ? (/nls\/[^\/]+\/[^\/]+$/.test(url) ? preAmdResult : {root:preAmdResult, _v1x:1}) : amdResult;
},
@@ -156,7 +173,7 @@ define(["./_base/kernel", "require", "./has", "./_base/array", "./_base/lang", "
url:url,
sync:true,
load:function(text){
- var result = evalBundle(text);
+ var result = evalBundle(text, __evalError);
results.push(cache[url]= fixup(url, result[0], result[1]));
},
error:function(){
@@ -166,7 +183,7 @@ define(["./_base/kernel", "require", "./has", "./_base/array", "./_base/lang", "
}
});
callback.apply(null, results);
- };
+ };
thisModule.getLocalization= function(moduleName, bundleName, locale){
var result,
@@ -182,6 +199,36 @@ define(["./_base/kernel", "require", "./has", "./_base/array", "./_base/lang", "
}
return result;
};
+
+ if(has("dojo-unit-tests")){
+ unitTests.push(function(doh){
+ doh.register("tests.i18n.unit", function(t){
+ var check;
+
+ check = evalBundle("{prop:1}", __evalError);
+ t.is({prop:1}, check[0]); t.is(undefined, check[1]);
+
+ check = evalBundle("({prop:1})", __evalError);
+ t.is({prop:1}, check[0]); t.is(undefined, check[1]);
+
+ check = evalBundle("{'prop-x':1}", __evalError);
+ t.is({'prop-x':1}, check[0]); t.is(undefined, check[1]);
+
+ check = evalBundle("({'prop-x':1})", __evalError);
+ t.is({'prop-x':1}, check[0]); t.is(undefined, check[1]);
+
+ check = evalBundle("define({'prop-x':1})", __evalError);
+ t.is(0, check[0]); t.is({'prop-x':1}, check[1]);
+
+ check = evalBundle("define({'prop-x':1});", __evalError);
+ t.is(0, check[0]); t.is({'prop-x':1}, check[1]);
+
+ check = evalBundle("this is total nonsense and should throw an error", __evalError);
+ t.is(__evalError, check[0]); t.is(undefined, check[1]);
+ t.is({}, fixup("some/url", check[0], check[1]));
+ });
+ });
+ }
}
return lang.mixin(thisModule, {
diff --git a/tests/i18n.html b/tests/i18n.html
index 7ccb8a5..41a93ac 100644
--- a/tests/i18n.html
+++ b/tests/i18n.html
@@ -7,7 +7,10 @@
var dohArgs= (window.parent.doh && window.parent.doh.dohArgs) || {async:0};
var dojoConfig = {
async:dohArgs.async,
- extraLocale:['en-us-hawaii', 'en-us-new_york-brooklyn']
+ extraLocale:['en-us-hawaii', 'en-us-new_york-brooklyn'],
+ has:{
+ "dojo-unit-tests":1
+ }
};
</script>
@@ -15,11 +18,15 @@
<script type="text/javascript">
// the following should load the current locale + 'en-us-hawaii' and 'en-us-new_york-brooklyn
- require(["dojo", "doh", "dojo/i18n!dojo/tests/nls/salutations"], function(dojo, doh){
+ require(["dojo", "doh", "dojo/has", "dojo/i18n", "dojo/i18n!dojo/tests/nls/salutations"], function(dojo, doh, has, i18n){
if(dohArgs.async){
doh.register(function extraLocalesAsync(t){
- t.is(require("dojo/i18n!dojo/tests/nls/en-us-hawaii/salutations").hello, "Aloha");
- t.is(require("dojo/i18n!dojo/tests/nls/en-us-new_york-brooklyn/salutations").hello, "Yo");
+ // the following should load synchronously...at least with the dojo loader
+ var hawaii, ny;
+ require(["dojo/i18n!dojo/tests/nls/en-us-hawaii/salutations"], function(bundle){ hawaii = bundle;});
+ require(["dojo/i18n!dojo/tests/nls/en-us-new_york-brooklyn/salutations"], function(bundle){ ny = bundle;});
+ t.is(hawaii.hello, "Aloha");
+ t.is(ny.hello, "Yo");
try{
var result = require("dojo/i18n!dojo/tests/nls/ar/salutations");
t.f(true, "should have thrown");
@@ -38,6 +45,14 @@
}
});
}
+
+
+ if(has("dojo-unit-tests")){
+ console.log("here");
+ dojo.forEach(i18n.unitTests, function(item){item(doh);});
+ }
+
+
doh.runOnLoad();
});
if(!require.async){
@@ -48,6 +63,7 @@
t.is(dojo.i18n.getLocalization("dojo.tests._base.loader", "amdBundle", "ab-cd-ef").amdBundle, "amdBundle-ab-cd-ef");
});
}
+
</script>
</head>
<body>
--
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