Chromium Code Reviews| Index: Source/devtools/front_end/Runtime.js |
| diff --git a/Source/devtools/front_end/Runtime.js b/Source/devtools/front_end/Runtime.js |
| index 04875cd213821268c1e1df6ce4c36d9b3aac14ae..14bbb0bbb005ea20b91c32598a4c1eaf36da80ae 100644 |
| --- a/Source/devtools/front_end/Runtime.js |
| +++ b/Source/devtools/front_end/Runtime.js |
| @@ -138,7 +138,8 @@ function loadScriptsPromise(scriptNames) |
| if (_loadedScripts[sourceURL]) |
| continue; |
| urls.push(sourceURL); |
| - promises.push(loadResourcePromise(sourceURL).thenOrCatch(scriptSourceLoaded.bind(null, i))); |
| + var thenCallback = scriptSourceLoaded.bind(null, i); |
|
apavlov
2014/10/31 13:26:26
Why this change? It's a very sensitive snippet tha
dgozman
2014/10/31 13:56:06
Copied from Promise.js, as this file cannot does n
|
| + promises.push(loadResourcePromise(sourceURL).then(thenCallback, function(e) { thenCallback(undefined); })); |
| } |
| return Promise.all(promises).then(undefined); |
| @@ -210,7 +211,7 @@ function Runtime(descriptors, coreModuleNames) |
| for (var i = 0; i < descriptors.length; ++i) |
| this._registerModule(descriptors[i]); |
| if (coreModuleNames) |
| - this._loadAutoStartModules(coreModuleNames).done(); |
|
apavlov
2014/10/31 13:26:26
This is critical to the correct rejection handling
dgozman
2014/10/31 13:56:06
Restored with a local version.
|
| + this._loadAutoStartModules(coreModuleNames); |
| } |
| /** |
| @@ -341,7 +342,7 @@ Runtime.startApplication = function(appName) |
| coreModuleNames.push(name); |
| } |
| - Promise.all(moduleJSONPromises).then(instantiateRuntime).done(); |
|
apavlov
2014/10/31 13:26:26
Ditto
|
| + Promise.all(moduleJSONPromises).then(instantiateRuntime); |
| /** |
| * @param {!Array.<!Object>} moduleDescriptors |
| */ |
| @@ -376,6 +377,59 @@ Runtime._experimentsSetting = function() |
| } |
| } |
| +/** |
| + * @param {!Array.<!Promise.<T, !Error>>} promises |
| + * @return {!Promise.<!Array.<T>>} |
| + * @template T |
| + */ |
| +Runtime._some = function(promises) |
| +{ |
| + var all = []; |
| + var wasRejected = []; |
| + for (var i = 0; i < promises.length; ++i) { |
| + // Workaround closure compiler bug. |
| + var handlerFunction = /** @type {function()} */ (handler.bind(promises[i], i)); |
| + all.push(promises[i].catch(handlerFunction)); |
| + } |
| + |
| + return Promise.all(all).then(filterOutFailuresResults); |
| + |
| + /** |
| + * @param {!Array.<T>} results |
| + * @return {!Array.<T>} |
| + * @template T |
| + */ |
| + function filterOutFailuresResults(results) |
| + { |
| + var filtered = []; |
| + for (var i = 0; i < results.length; ++i) { |
| + if (!wasRejected[i]) |
| + filtered.push(results[i]); |
| + } |
| + return filtered; |
| + } |
| + |
| + /** |
| + * @this {!Promise} |
| + * @param {number} index |
| + * @param {!Error} e |
| + */ |
| + function handler(index, e) |
| + { |
| + wasRejected[index] = true; |
| + console.error(e.stack); |
| + } |
| +} |
| + |
| +Runtime._console = console; |
|
apavlov
2014/10/31 13:26:26
I'd rather vsevik@ take a look at this, as I'm not
dgozman
2014/10/31 13:56:06
We can't do this without duplication.
|
| +Runtime._originalAssert = console.assert; |
| +Runtime._assert = function(value, message) |
| +{ |
| + if (value) |
| + return; |
| + Runtime._originalAssert.call(Runtime._console, value, message); |
| +} |
| + |
| Runtime.prototype = { |
| /** |
| @@ -537,7 +591,7 @@ Runtime.prototype = { |
| var promises = []; |
| for (var i = 0; i < extensions.length; ++i) |
| promises.push(extensions[i].instancePromise()); |
| - return Promise.some(promises); |
| + return Runtime._some(promises); |
| }, |
| /** |
| @@ -687,7 +741,7 @@ Runtime.Module.prototype = { |
| if (Runtime.isReleaseMode()) |
| return loadScriptsPromise([this._name + "_module.js"]); |
| - return loadScriptsPromise(this._descriptor.scripts.map(modularizeURL, this)).catchAndReport(); |
| + return loadScriptsPromise(this._descriptor.scripts.map(modularizeURL, this)).catch(reportError); |
| /** |
| * @param {string} scriptName |
| @@ -697,6 +751,17 @@ Runtime.Module.prototype = { |
| { |
| return this._name + "/" + scriptName; |
| } |
| + |
| + /** |
| + * @param {*} e |
| + */ |
| + function reportError(e) |
| + { |
| + if (e instanceof Error) |
| + console.error(e.stack); |
| + else |
| + console.error(e); |
| + } |
| }, |
| /** |
| @@ -853,7 +918,7 @@ Runtime.ExperimentsSupport.prototype = { |
| */ |
| register: function(experimentName, experimentTitle, hidden) |
| { |
| - console.assert(!this._experimentNames[experimentName], "Duplicate registration of experiment " + experimentName); |
| + Runtime._assert(!this._experimentNames[experimentName], "Duplicate registration of experiment " + experimentName); |
| this._experimentNames[experimentName] = true; |
| this._experiments.push(new Runtime.Experiment(this, experimentName, experimentTitle, !!hidden)); |
| }, |
| @@ -923,7 +988,7 @@ Runtime.ExperimentsSupport.prototype = { |
| */ |
| _checkExperiment: function(experimentName) |
| { |
| - console.assert(this._experimentNames[experimentName], "Unknown experiment " + experimentName); |
| + Runtime._assert(this._experimentNames[experimentName], "Unknown experiment " + experimentName); |
| } |
| } |
| @@ -984,110 +1049,6 @@ Runtime.Experiment.prototype = { |
| } |
| })();} |
| -/** |
| - * @param {string} error |
| - * @return {!Promise.<T>} |
| - * @template T |
| - */ |
| -Promise.rejectWithError = function(error) |
| -{ |
| - return Promise.reject(new Error(error)); |
| -} |
| - |
| -/** |
| - * @param {function((T|undefined))} callback |
| - * @return {!Promise.<T>} |
| - * @template T |
| - */ |
| -Promise.prototype.thenOrCatch = function(callback) |
| -{ |
| - return this.then(callback, reject.bind(this)); |
| - |
| - /** |
| - * @param {*} e |
| - */ |
| - function reject(e) |
| - { |
| - this._reportError(e); |
| - callback(undefined); |
| - } |
| -} |
| - |
| -Promise.prototype.done = function() |
| -{ |
| - this.catchAndReport(); |
| -} |
| - |
| -Promise.prototype.catchAndReport = function() |
| -{ |
| - return this.catch(this._reportError.bind(this)); |
| -} |
| - |
| -/** |
| - * @param {*} e |
| - */ |
| -Promise.prototype._reportError = function(e) |
| -{ |
| - if (e instanceof Error) |
| - console.error(e.stack); |
| - else |
| - console.error(e); |
| -} |
| - |
| -/** |
| - * @param {!Array.<!Promise.<T, !Error>>} promises |
| - * @return {!Promise.<!Array.<T>>} |
| - * @template T |
| - */ |
| -Promise.some = function(promises) |
| -{ |
| - var all = []; |
| - var wasRejected = []; |
| - for (var i = 0; i < promises.length; ++i) { |
| - // Workaround closure compiler bug. |
| - var handlerFunction = /** @type {function()} */ (handler.bind(promises[i], i)); |
| - all.push(promises[i].catch(handlerFunction)); |
| - } |
| - |
| - return Promise.all(all).then(filterOutFailuresResults); |
| - |
| - /** |
| - * @param {!Array.<T>} results |
| - * @return {!Array.<T>} |
| - * @template T |
| - */ |
| - function filterOutFailuresResults(results) |
| - { |
| - var filtered = []; |
| - for (var i = 0; i < results.length; ++i) { |
| - if (!wasRejected[i]) |
| - filtered.push(results[i]); |
| - } |
| - return filtered; |
| - } |
| - |
| - /** |
| - * @this {!Promise} |
| - * @param {number} index |
| - * @param {!Error} e |
| - */ |
| - function handler(index, e) |
| - { |
| - wasRejected[index] = true; |
| - this._reportError(e); |
| - } |
| -} |
| - |
| -// FIXME: This performance optimization should be moved to blink so that all developers could enjoy it. |
| -// console is retrieved with V8Window.getAttribute method which is slow. Here we copy it to a js variable for faster access. |
| -console = console; |
| -console.__originalAssert = console.assert; |
| -console.assert = function(value, message) |
| -{ |
| - if (value) |
| - return; |
| - console.__originalAssert(value, message); |
| -} |
| // This must be constructed after the query parameters have been parsed. |
| Runtime.experiments = new Runtime.ExperimentsSupport(); |