| Index: Source/devtools/front_end/Runtime.js
|
| diff --git a/Source/devtools/front_end/Runtime.js b/Source/devtools/front_end/Runtime.js
|
| index afe37d38cccd217932c057c29c16a1170868be0e..04875cd213821268c1e1df6ce4c36d9b3aac14ae 100644
|
| --- a/Source/devtools/front_end/Runtime.js
|
| +++ b/Source/devtools/front_end/Runtime.js
|
| @@ -138,8 +138,7 @@
|
| if (_loadedScripts[sourceURL])
|
| continue;
|
| urls.push(sourceURL);
|
| - var thenCallback = scriptSourceLoaded.bind(null, i);
|
| - promises.push(loadResourcePromise(sourceURL).then(thenCallback, function(e) { thenCallback(undefined); }));
|
| + promises.push(loadResourcePromise(sourceURL).thenOrCatch(scriptSourceLoaded.bind(null, i)));
|
| }
|
| return Promise.all(promises).then(undefined);
|
|
|
| @@ -211,7 +210,7 @@
|
| for (var i = 0; i < descriptors.length; ++i)
|
| this._registerModule(descriptors[i]);
|
| if (coreModuleNames)
|
| - this._loadAutoStartModules(coreModuleNames).catch(Runtime._reportError);
|
| + this._loadAutoStartModules(coreModuleNames).done();
|
| }
|
|
|
| /**
|
| @@ -342,7 +341,7 @@
|
| coreModuleNames.push(name);
|
| }
|
|
|
| - Promise.all(moduleJSONPromises).then(instantiateRuntime).catch(Runtime._reportError);
|
| + Promise.all(moduleJSONPromises).then(instantiateRuntime).done();
|
| /**
|
| * @param {!Array.<!Object>} moduleDescriptors
|
| */
|
| @@ -375,70 +374,6 @@
|
| console.error("Failed to parse localStorage['experiments']");
|
| return {};
|
| }
|
| -}
|
| -
|
| -/**
|
| - * @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;
|
| -Runtime._originalAssert = console.assert;
|
| -Runtime._assert = function(value, message)
|
| -{
|
| - if (value)
|
| - return;
|
| - Runtime._originalAssert.call(Runtime._console, value, message);
|
| -}
|
| -
|
| -/**
|
| - * @param {*} e
|
| - */
|
| -Runtime._reportError = function(e)
|
| -{
|
| - if (e instanceof Error)
|
| - console.error(e.stack);
|
| - else
|
| - console.error(e);
|
| }
|
|
|
| Runtime.prototype = {
|
| @@ -602,7 +537,7 @@
|
| var promises = [];
|
| for (var i = 0; i < extensions.length; ++i)
|
| promises.push(extensions[i].instancePromise());
|
| - return Runtime._some(promises);
|
| + return Promise.some(promises);
|
| },
|
|
|
| /**
|
| @@ -752,7 +687,7 @@
|
| if (Runtime.isReleaseMode())
|
| return loadScriptsPromise([this._name + "_module.js"]);
|
|
|
| - return loadScriptsPromise(this._descriptor.scripts.map(modularizeURL, this)).catch(Runtime._reportError);
|
| + return loadScriptsPromise(this._descriptor.scripts.map(modularizeURL, this)).catchAndReport();
|
|
|
| /**
|
| * @param {string} scriptName
|
| @@ -918,7 +853,7 @@
|
| */
|
| register: function(experimentName, experimentTitle, hidden)
|
| {
|
| - Runtime._assert(!this._experimentNames[experimentName], "Duplicate registration of experiment " + experimentName);
|
| + console.assert(!this._experimentNames[experimentName], "Duplicate registration of experiment " + experimentName);
|
| this._experimentNames[experimentName] = true;
|
| this._experiments.push(new Runtime.Experiment(this, experimentName, experimentTitle, !!hidden));
|
| },
|
| @@ -988,7 +923,7 @@
|
| */
|
| _checkExperiment: function(experimentName)
|
| {
|
| - Runtime._assert(this._experimentNames[experimentName], "Unknown experiment " + experimentName);
|
| + console.assert(this._experimentNames[experimentName], "Unknown experiment " + experimentName);
|
| }
|
| }
|
|
|
| @@ -1049,6 +984,110 @@
|
| }
|
| })();}
|
|
|
| +/**
|
| + * @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();
|
|
|