From 557e4200c1ef5640f3540628e71f0129b9b7a2b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 16 Aug 2016 18:37:51 +0200 Subject: [PATCH] Update to require.js 2.2.0 --- wcfsetup/install/files/js/require.js | 112 ++++++++++++++++++++------- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/wcfsetup/install/files/js/require.js b/wcfsetup/install/files/js/require.js index a3e74da0b2..23ddb4ee66 100644 --- a/wcfsetup/install/files/js/require.js +++ b/wcfsetup/install/files/js/require.js @@ -1,7 +1,6 @@ /** vim: et:ts=4:sw=4:sts=4 - * @license RequireJS 2.1.19 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 + * @license RequireJS 2.2.0 Copyright jQuery Foundation and other contributors. + * Released under MIT license, http://github.com/requirejs/requirejs/LICENSE */ //Not using strict: uneven strict support in browsers, #392, and causes //problems with requirejs.exec()/transpiler plugins that may not be strict. @@ -12,7 +11,7 @@ var requirejs, require, define; (function (global) { var req, s, head, baseElement, dataMain, src, interactiveScript, currentlyAddingScript, mainScript, subPath, - version = '2.1.19', + version = '2.2.0', commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, jsSuffixRegExp = /\.js$/, @@ -20,8 +19,6 @@ var requirejs, require, define; 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 @@ -38,6 +35,11 @@ var requirejs, require, define; globalDefQueue = [], useInteractive = false; + //Could match something like ')//comment', do not lose the prefix to comment. + function commentReplace(match, multi, multiText, singlePrefix) { + return singlePrefix || ''; + } + function isFunction(it) { return ostring.call(it) === '[object Function]'; } @@ -554,11 +556,13 @@ var requirejs, require, define; 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 = []; } } @@ -845,7 +849,10 @@ var requirejs, require, define; 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) { @@ -905,7 +912,11 @@ var requirejs, require, define; 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); } } @@ -964,6 +975,7 @@ var requirejs, require, define; this.map.parentMap); on(normalizedMap, 'defined', bind(this, function (value) { + this.map.normalizedMap = normalizedMap; this.init([], function () { return value; }, null, { enabled: true, ignore: true @@ -1244,6 +1256,7 @@ var requirejs, require, define; callGetModule(args); } } + context.defQueueMap = {}; } context = { @@ -1253,6 +1266,7 @@ var requirejs, require, define; defined: defined, urlFetched: urlFetched, defQueue: defQueue, + defQueueMap: {}, Module: Module, makeModuleMap: makeModuleMap, nextTick: req.nextTick, @@ -1270,6 +1284,14 @@ var requirejs, require, define; } } + // Convert old style urlArgs string to a function. + if (typeof cfg.urlArgs === 'string') { + var urlArgs = cfg.urlArgs; + cfg.urlArgs = function(id, url) { + return (url.indexOf('?') === -1 ? '?' : '&') + urlArgs; + }; + } + //Save off the paths since they require special processing, //they are additive. var shim = config.shim, @@ -1502,6 +1524,7 @@ var requirejs, require, define; defQueue.splice(i, 1); } }); + delete context.defQueueMap[id]; if (mod) { //Hold on to listeners in case the @@ -1563,6 +1586,7 @@ var requirejs, require, define; callGetModule(args); } + context.defQueueMap = {}; //Do this after the cycle of callGetModule in case the result //of those calls/init calls changes the registry. @@ -1644,13 +1668,12 @@ var requirejs, require, define; //Join the path parts together, then figure out if baseUrl is needed. url = syms.join('/'); - url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js')); + url += (ext || (/^data\:|^blob\:|\?/.test(url) || skipExt ? '' : '.js')); url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url; } - return config.urlArgs ? url + - ((url.indexOf('?') === -1 ? '?' : '&') + - config.urlArgs) : url; + return config.urlArgs && !/^blob\:/.test(url) ? + url + config.urlArgs(moduleName, url) : url; }, //Delegates to req.load. Broken out as a separate function to @@ -1698,7 +1721,21 @@ var requirejs, require, define; 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])); } } }; @@ -1857,9 +1894,6 @@ var requirejs, require, define; if (isBrowser) { //In the browser so use a script tag node = req.createNode(config, moduleName, url); - if (config.onNodeCreated) { - config.onNodeCreated(node, config, moduleName, url); - } node.setAttribute('data-requirecontext', context.contextName); node.setAttribute('data-requiremodule', moduleName); @@ -1875,11 +1909,11 @@ var requirejs, require, define; if (node.attachEvent && //Check if node.attachEvent is artificially added by custom script or //natively supported by browser - //read https://github.com/jrburke/requirejs/issues/187 + //read https://github.com/requirejs/requirejs/issues/187 //if we can NOT find [native code] then it must NOT natively supported. //in IE8, node.attachEvent does not have toString() //Note the test for "[native code" with no closing brace, see: - //https://github.com/jrburke/requirejs/issues/273 + //https://github.com/requirejs/requirejs/issues/273 !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) && !isOpera) { //Probably IE. IE (at least 6-8) do not fire @@ -1907,6 +1941,12 @@ var requirejs, require, define; } node.src = url; + //Calling onNodeCreated after all properties on the node have been + //set, but before it is placed in the DOM. + if (config.onNodeCreated) { + config.onNodeCreated(node, config, moduleName, url); + } + //For some cache cases in IE 6-8, the script executes before the end //of the appendChild execution, so to tie an anonymous define //call to the module name (which is stored on the node), hold on @@ -1925,9 +1965,14 @@ var requirejs, require, define; //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. + + // Post a task to the event loop to work around a bug in WebKit + // where the worker gets garbage-collected after calling + // importScripts(): https://webkit.org/b/153317 + setTimeout(function() {}, 0); importScripts(url); //Account for anonymous modules @@ -1973,8 +2018,10 @@ var requirejs, require, define; //Preserve dataMain in case it is a path (i.e. contains '?') mainScript = dataMain; - //Set final baseUrl if there is not already an explicit one. - if (!cfg.baseUrl) { + //Set final baseUrl if there is not already an explicit one, + //but only do so if the data-main value is not a loader plugin + //module ID. + if (!cfg.baseUrl && mainScript.indexOf('!') === -1) { //Pull off the directory of data-main for use as the //baseUrl. src = mainScript.split('/'); @@ -2035,7 +2082,7 @@ var requirejs, require, define; if (callback.length) { callback .toString() - .replace(commentRegExp, '') + .replace(commentRegExp, commentReplace) .replace(cjsRequireRegExp, function (match, dep) { deps.push(dep); }); @@ -2067,7 +2114,12 @@ var requirejs, require, define; //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 = { -- 2.20.1