Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1086)

Unified Diff: Source/devtools/front_end/Runtime.js

Issue 673163004: [DevTools] Extract platform module. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed bug in hosted mode Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/bindings/module.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..708667b5d3287b835fbb4178d076147c1cc931d2 100644
--- a/Source/devtools/front_end/Runtime.js
+++ b/Source/devtools/front_end/Runtime.js
@@ -138,7 +138,7 @@ function loadScriptsPromise(scriptNames)
if (_loadedScripts[sourceURL])
continue;
urls.push(sourceURL);
- promises.push(loadResourcePromise(sourceURL).thenOrCatch(scriptSourceLoaded.bind(null, i)));
+ promises.push(loadResourcePromise(sourceURL).then(scriptSourceLoaded.bind(null, i), scriptSourceLoaded.bind(null, i, undefined)));
}
return Promise.all(promises).then(undefined);
@@ -210,7 +210,7 @@ function Runtime(descriptors, coreModuleNames)
for (var i = 0; i < descriptors.length; ++i)
this._registerModule(descriptors[i]);
if (coreModuleNames)
- this._loadAutoStartModules(coreModuleNames).done();
+ this._loadAutoStartModules(coreModuleNames).catch(Runtime._reportError);
}
/**
@@ -341,7 +341,7 @@ Runtime.startApplication = function(appName)
coreModuleNames.push(name);
}
- Promise.all(moduleJSONPromises).then(instantiateRuntime).done();
+ Promise.all(moduleJSONPromises).then(instantiateRuntime).catch(Runtime._reportError);
/**
* @param {!Array.<!Object>} moduleDescriptors
*/
@@ -376,6 +376,70 @@ 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;
+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 = {
/**
@@ -537,7 +601,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 +751,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(Runtime._reportError);
/**
* @param {string} scriptName
@@ -853,7 +917,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 +987,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 +1048,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();
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/bindings/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698