[Pkg-javascript-commits] [dojo] 37/149: Parser: use separate cache for each require context.
David Prévot
taffit at moszumanska.debian.org
Sat Feb 27 03:13:45 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository dojo.
commit bab52a220c2f2b55b90356c15e7e9b3136aa9355
Author: Bill Keese <bill at dojotoolkit.org>
Date: Wed Feb 18 17:03:30 2015 +0900
Parser: use separate cache for each require context.
Avoids problems when "./Foo" or even "/foo/Bar" has different meanings in
different require contexts.
Fixes #18455.
---
parser.js | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/parser.js b/parser.js
index 46fcde3..0a10338 100644
--- a/parser.js
+++ b/parser.js
@@ -41,29 +41,35 @@ define([
return map;
}
- // Map from widget name or list of widget names(ex: "dijit/form/Button,acme/MyMixin") to a constructor.
- var _ctorMap = {};
-
function getCtor(/*String[]*/ types, /*Function?*/ contextRequire){
// summary:
// Retrieves a constructor. If the types array contains more than one class/MID then the
// subsequent classes will be mixed into the first class and a unique constructor will be
// returned for that array.
+ if(!contextRequire){
+ contextRequire = require;
+ }
+
+ // Map from widget name or list of widget names(ex: "dijit/form/Button,acme/MyMixin") to a constructor.
+ // Keep separate map for each requireContext to avoid false matches (ex: "./Foo" can mean different things
+ // depending on context.)
+ var ctorMap = contextRequire._dojoParserCtorMap || (contextRequire._dojoParserCtorMap = {});
+
var ts = types.join();
- if(!_ctorMap[ts]){
+ if(!ctorMap[ts]){
var mixins = [];
for(var i = 0, l = types.length; i < l; i++){
var t = types[i];
// TODO: Consider swapping getObject and require in the future
- mixins[mixins.length] = (_ctorMap[t] = _ctorMap[t] || (dlang.getObject(t) || (~t.indexOf('/') &&
- (contextRequire ? contextRequire(t) : require(t)))));
+ mixins[mixins.length] = (ctorMap[t] = ctorMap[t] || (dlang.getObject(t) || (~t.indexOf('/') &&
+ contextRequire(t))));
}
var ctor = mixins.shift();
- _ctorMap[ts] = mixins.length ? (ctor.createSubclass ? ctor.createSubclass(mixins) : ctor.extend.apply(ctor, mixins)) : ctor;
+ ctorMap[ts] = mixins.length ? (ctor.createSubclass ? ctor.createSubclass(mixins) : ctor.extend.apply(ctor, mixins)) : ctor;
}
- return _ctorMap[ts];
+ return ctorMap[ts];
}
var parser = {
--
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