vendor/assets/javascripts/require.js in requirejs-rails-0.9.9 vs vendor/assets/javascripts/require.js in requirejs-rails-1.0.0
- old
+ new
@@ -1,7 +1,7 @@
/** vim: et:ts=4:sw=4:sts=4
- * @license RequireJS 2.1.19 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
+ * @license RequireJS 2.1.22 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details
*/
//Not using strict: uneven strict support in browsers, #392, and causes
//problems with requirejs.exec()/transpiler plugins that may not be strict.
@@ -10,20 +10,19 @@
var requirejs, require, define;
(function (global) {
var req, s, head, baseElement, dataMain, src,
interactiveScript, currentlyAddingScript, mainScript, subPath,
- version = '2.1.19',
+ version = '2.1.22',
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
jsSuffixRegExp = /\.js$/,
currDirRegExp = /^\.\//,
op = Object.prototype,
ostring = op.toString,
hasOwn = op.hasOwnProperty,
ap = Array.prototype,
- apsp = ap.splice,
isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document),
isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
//PS3 indicates loaded and complete, but need to wait for complete
//specifically. Sequence is 'loading', 'loaded', execution,
// then 'complete'. The UA check is unfortunate, but not sure how
@@ -552,15 +551,17 @@
* defQueue.
*/
function takeGlobalQueue() {
//Push all the globalDefQueue items into the context's defQueue
if (globalDefQueue.length) {
- //Array splice in the values since the context code has a
- //local var ref to defQueue, so cannot just reassign the one
- //on context.
- apsp.apply(defQueue,
- [defQueue.length, 0].concat(globalDefQueue));
+ each(globalDefQueue, function(queueItem) {
+ var id = queueItem[0];
+ if (typeof id === 'string') {
+ context.defQueueMap[id] = true;
+ }
+ defQueue.push(queueItem);
+ });
globalDefQueue = [];
}
}
handlers = {
@@ -843,11 +844,14 @@
depExports = this.depExports,
exports = this.exports,
factory = this.factory;
if (!this.inited) {
- this.fetch();
+ // Only fetch if not already in the defQueue.
+ if (!hasProp(context.defQueueMap, id)) {
+ this.fetch();
+ }
} else if (this.error) {
this.emit('error', this.error);
} else if (!this.defining) {
//The factory could trigger another require call
//that would result in checking this module to
@@ -855,25 +859,14 @@
//of doing that, skip this work.
this.defining = true;
if (this.depCount < 1 && !this.defined) {
if (isFunction(factory)) {
- //If there is an error listener, favor passing
- //to that instead of throwing an error. However,
- //only do it for define()'d modules. require
- //errbacks should not be called for failures in
- //their callbacks (#699). However if a global
- //onError is set, use that.
- if ((this.events.error && this.map.isDefine) ||
- req.onError !== defaultOnError) {
- try {
- exports = context.execCb(id, factory, depExports, exports);
- } catch (e) {
- err = e;
- }
- } else {
+ try {
exports = context.execCb(id, factory, depExports, exports);
+ } catch (e) {
+ err = e;
}
// Favor return value over exports. If node/cjs in play,
// then will not have a return value anyway. Favor
// module.exports assignment over exports object.
@@ -886,16 +879,34 @@
exports = this.exports;
}
}
if (err) {
- err.requireMap = this.map;
- err.requireModules = this.map.isDefine ? [this.map.id] : null;
- err.requireType = this.map.isDefine ? 'define' : 'require';
- return onError((this.error = err));
+ // If there is an error listener, favor passing
+ // to that instead of throwing an error. However,
+ // only do it for define()'d modules. require
+ // errbacks should not be called for failures in
+ // their callbacks (#699). However if a global
+ // onError is set, use that.
+ if ((this.events.error && this.map.isDefine) ||
+ req.onError !== defaultOnError) {
+ err.requireMap = this.map;
+ err.requireModules = this.map.isDefine ? [this.map.id] : null;
+ err.requireType = this.map.isDefine ? 'define' : 'require';
+ return onError((this.error = err));
+ } else if (typeof console !== 'undefined' &&
+ console.error) {
+ // Log the error for debugging. If promises could be
+ // used, this would be different, but making do.
+ console.error(err);
+ } else {
+ // Do not want to completely lose the error. While this
+ // will mess up processing and lead to similar results
+ // as bug 1440, it at least surfaces the error.
+ req.onError(err);
+ }
}
-
} else {
//Just a literal value
exports = factory;
}
@@ -903,11 +914,15 @@
if (this.map.isDefine && !this.ignore) {
defined[id] = exports;
if (req.onResourceLoad) {
- req.onResourceLoad(context, this.map, this.depMaps);
+ var resLoadMaps = [];
+ each(this.depMaps, function (depMap) {
+ resLoadMaps.push(depMap.normalizedMap || depMap);
+ });
+ req.onResourceLoad(context, this.map, resLoadMaps);
}
}
//Clean up
cleanRegistry(id);
@@ -962,10 +977,11 @@
//for applying map config again either.
normalizedMap = makeModuleMap(map.prefix + '!' + name,
this.map.parentMap);
on(normalizedMap,
'defined', bind(this, function (value) {
+ this.map.normalizedMap = normalizedMap;
this.init([], function () { return value; }, null, {
enabled: true,
ignore: true
});
}));
@@ -1242,19 +1258,21 @@
//args are id, deps, factory. Should be normalized by the
//define() function.
callGetModule(args);
}
}
+ context.defQueueMap = {};
}
context = {
config: config,
contextName: contextName,
registry: registry,
defined: defined,
urlFetched: urlFetched,
defQueue: defQueue,
+ defQueueMap: {},
Module: Module,
makeModuleMap: makeModuleMap,
nextTick: req.nextTick,
onError: onError,
@@ -1500,10 +1518,11 @@
eachReverse(defQueue, function(args, i) {
if (args[0] === id) {
defQueue.splice(i, 1);
}
});
+ delete context.defQueueMap[id];
if (mod) {
//Hold on to listeners in case the
//module will be attempted to be reloaded
//using a different config.
@@ -1561,10 +1580,11 @@
found = true;
}
callGetModule(args);
}
+ context.defQueueMap = {};
//Do this after the cycle of callGetModule in case the result
//of those calls/init calls changes the registry.
mod = getOwn(registry, moduleName);
@@ -1696,11 +1716,25 @@
* Callback for script errors.
*/
onScriptError: function (evt) {
var data = getScriptData(evt);
if (!hasPathFallback(data.id)) {
- return onError(makeError('scripterror', 'Script error for: ' + data.id, evt, [data.id]));
+ var parents = [];
+ eachProp(registry, function(value, key) {
+ if (key.indexOf('_@r') !== 0) {
+ each(value.depMaps, function(depMap) {
+ if (depMap.id === data.id) {
+ parents.push(key);
+ }
+ return true;
+ });
+ }
+ });
+ return onError(makeError('scripterror', 'Script error for "' + data.id +
+ (parents.length ?
+ '", needed by: ' + parents.join(', ') :
+ '"'), evt, [data.id]));
}
}
};
context.require = context.makeRequire();
@@ -1923,13 +1957,13 @@
} else if (isWebWorker) {
try {
//In a web worker, use importScripts. This is not a very
//efficient use of importScripts, importScripts will block until
//its script is downloaded and evaluated. However, if web workers
- //are in play, the expectation that a build has been done so that
- //only one script needs to be loaded anyway. This may need to be
- //reevaluated if other use cases become common.
+ //are in play, the expectation is that a build has been done so
+ //that only one script needs to be loaded anyway. This may need
+ //to be reevaluated if other use cases become common.
importScripts(url);
//Account for anonymous modules
context.completeLoad(moduleName);
} catch (e) {
@@ -2065,10 +2099,15 @@
//This allows multiple modules to be in a file without prematurely
//tracing dependencies, and allows for anonymous module support,
//where the module name is not known until the script onload event
//occurs. If no context, use the global queue, and get it processed
//in the onscript load callback.
- (context ? context.defQueue : globalDefQueue).push([name, deps, callback]);
+ if (context) {
+ context.defQueue.push([name, deps, callback]);
+ context.defQueueMap[name] = true;
+ } else {
+ globalDefQueue.push([name, deps, callback]);
+ }
};
define.amd = {
jQuery: true
};