Commit 313ff6ba authored by dgozman@chromium.org's avatar dgozman@chromium.org

[DevTools] Extract platform module.

BUG=none

Review URL: https://codereview.chromium.org/673163004

git-svn-id: svn://svn.chromium.org/blink/trunk@184865 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 1c2041ad
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
if (!window.WebInspector) if (!window.WebInspector)
window.WebInspector = {}; window.WebInspector = {};
InspectorTest.importScript("../../../../../Source/devtools/front_end/platform/Promise.js");
InspectorTest.importScript("../../../../../Source/devtools/front_end/platform/utilities.js");
InspectorTest.importScript("../../../../../Source/devtools/front_end/common/UIString.js"); InspectorTest.importScript("../../../../../Source/devtools/front_end/common/UIString.js");
InspectorTest.importScript("../../../../../Source/devtools/front_end/common/utilities.js");
InspectorTest.importScript("../../../../../Source/devtools/front_end/profiler/HeapSnapshotCommon.js"); InspectorTest.importScript("../../../../../Source/devtools/front_end/profiler/HeapSnapshotCommon.js");
InspectorTest.importScript("../../../../../Source/devtools/front_end/heap_snapshot_worker/HeapSnapshot.js"); InspectorTest.importScript("../../../../../Source/devtools/front_end/heap_snapshot_worker/HeapSnapshot.js");
InspectorTest.importScript("../../../../../Source/devtools/front_end/heap_snapshot_worker/JSHeapSnapshot.js"); InspectorTest.importScript("../../../../../Source/devtools/front_end/heap_snapshot_worker/JSHeapSnapshot.js");
......
...@@ -9,6 +9,7 @@ Loaded modules: ...@@ -9,6 +9,7 @@ Loaded modules:
extensions extensions
host host
main main
platform
screencast screencast
sdk sdk
toolbox toolbox
...@@ -24,6 +25,7 @@ Loaded modules: ...@@ -24,6 +25,7 @@ Loaded modules:
extensions extensions
host host
main main
platform
screencast screencast
sdk sdk
toolbox toolbox
...@@ -40,6 +42,7 @@ Loaded modules: ...@@ -40,6 +42,7 @@ Loaded modules:
host host
main main
network network
platform
screencast screencast
sdk sdk
source_frame source_frame
...@@ -57,6 +60,7 @@ Loaded modules: ...@@ -57,6 +60,7 @@ Loaded modules:
host host
main main
network network
platform
screencast screencast
sdk sdk
source_frame source_frame
...@@ -75,6 +79,7 @@ Loaded modules: ...@@ -75,6 +79,7 @@ Loaded modules:
host host
main main
network network
platform
screencast screencast
sdk sdk
source_frame source_frame
......
...@@ -7,6 +7,7 @@ Loaded modules: ...@@ -7,6 +7,7 @@ Loaded modules:
extensions extensions
host host
main main
platform
screencast screencast
sdk sdk
toolbox toolbox
......
...@@ -19,6 +19,7 @@ devtools_core_files = ...@@ -19,6 +19,7 @@ devtools_core_files =
gypi_values.devtools_components_js_files + gypi_values.devtools_components_js_files +
gypi_values.devtools_host_js_files + gypi_values.devtools_host_js_files +
gypi_values.devtools_main_js_files + gypi_values.devtools_main_js_files +
gypi_values.devtools_platform_js_files +
gypi_values.devtools_screencast_js_files + gypi_values.devtools_screencast_js_files +
gypi_values.devtools_sdk_js_files + gypi_values.devtools_sdk_js_files +
gypi_values.devtools_toolbox_js_files + gypi_values.devtools_toolbox_js_files +
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
'<@(devtools_core_base_files)', '<@(devtools_core_base_files)',
'<@(devtools_host_js_files)', '<@(devtools_host_js_files)',
'<@(devtools_main_js_files)', '<@(devtools_main_js_files)',
'<@(devtools_platform_js_files)',
'<@(devtools_screencast_js_files)', '<@(devtools_screencast_js_files)',
'<@(devtools_sdk_js_files)', '<@(devtools_sdk_js_files)',
'<@(devtools_toolbox_bootstrap_js_files)', '<@(devtools_toolbox_bootstrap_js_files)',
...@@ -87,7 +88,6 @@ ...@@ -87,7 +88,6 @@
'front_end/common/TextUtils.js', 'front_end/common/TextUtils.js',
'front_end/common/Throttler.js', 'front_end/common/Throttler.js',
'front_end/common/UIString.js', 'front_end/common/UIString.js',
'front_end/common/utilities.js',
'front_end/common/WebInspector.js', 'front_end/common/WebInspector.js',
], ],
'devtools_components_js_files': [ 'devtools_components_js_files': [
...@@ -122,10 +122,8 @@ ...@@ -122,10 +122,8 @@
'front_end/components/TimelineGrid.js', 'front_end/components/TimelineGrid.js',
], ],
'devtools_host_js_files': [ 'devtools_host_js_files': [
'front_end/host/DOMExtension.js',
'front_end/host/InspectorFrontendHost.js', 'front_end/host/InspectorFrontendHost.js',
'front_end/host/Platform.js', 'front_end/host/Platform.js',
'front_end/host/ToolboxHost.js',
'front_end/host/UserMetrics.js', 'front_end/host/UserMetrics.js',
], ],
'devtools_screencast_js_files': [ 'devtools_screencast_js_files': [
...@@ -206,6 +204,11 @@ ...@@ -206,6 +204,11 @@
'front_end/bindings/TempFile.js', 'front_end/bindings/TempFile.js',
'front_end/bindings/WorkspaceController.js', 'front_end/bindings/WorkspaceController.js',
], ],
'devtools_platform_js_files': [
'front_end/platform/DOMExtension.js',
'front_end/platform/Promise.js',
'front_end/platform/utilities.js',
],
'devtools_toolbox_bootstrap_js_files': [ 'devtools_toolbox_bootstrap_js_files': [
'front_end/toolbox_bootstrap/Toolbox.js', 'front_end/toolbox_bootstrap/Toolbox.js',
], ],
...@@ -374,13 +377,14 @@ ...@@ -374,13 +377,14 @@
'devtools_heap_snapshot_worker_js_files': [ 'devtools_heap_snapshot_worker_js_files': [
'front_end/common/TextUtils.js', 'front_end/common/TextUtils.js',
'front_end/common/UIString.js', 'front_end/common/UIString.js',
'front_end/common/utilities.js',
'front_end/heap_snapshot_worker/AllocationProfile.js', 'front_end/heap_snapshot_worker/AllocationProfile.js',
'front_end/heap_snapshot_worker/HeapSnapshot.js', 'front_end/heap_snapshot_worker/HeapSnapshot.js',
'front_end/heap_snapshot_worker/HeapSnapshotLoader.js', 'front_end/heap_snapshot_worker/HeapSnapshotLoader.js',
'front_end/heap_snapshot_worker/HeapSnapshotWorker.js', 'front_end/heap_snapshot_worker/HeapSnapshotWorker.js',
'front_end/heap_snapshot_worker/HeapSnapshotWorkerDispatcher.js', 'front_end/heap_snapshot_worker/HeapSnapshotWorkerDispatcher.js',
'front_end/heap_snapshot_worker/JSHeapSnapshot.js', 'front_end/heap_snapshot_worker/JSHeapSnapshot.js',
'front_end/platform/Promise.js',
'front_end/platform/utilities.js',
'front_end/profiler/HeapSnapshotCommon.js', 'front_end/profiler/HeapSnapshotCommon.js',
], ],
'devtools_layers_js_files': [ 'devtools_layers_js_files': [
...@@ -446,7 +450,8 @@ ...@@ -446,7 +450,8 @@
'front_end/cm/javascript.js', 'front_end/cm/javascript.js',
'front_end/cm/xml.js', 'front_end/cm/xml.js',
'front_end/common/WebInspector.js', 'front_end/common/WebInspector.js',
'front_end/common/utilities.js', 'front_end/platform/Promise.js',
'front_end/platform/utilities.js',
'front_end/script_formatter_worker/CSSFormatter.js', 'front_end/script_formatter_worker/CSSFormatter.js',
'front_end/script_formatter_worker/JavaScriptFormatter.js', 'front_end/script_formatter_worker/JavaScriptFormatter.js',
'front_end/script_formatter_worker/ScriptFormatterWorker.js', 'front_end/script_formatter_worker/ScriptFormatterWorker.js',
......
...@@ -138,7 +138,7 @@ function loadScriptsPromise(scriptNames) ...@@ -138,7 +138,7 @@ function loadScriptsPromise(scriptNames)
if (_loadedScripts[sourceURL]) if (_loadedScripts[sourceURL])
continue; continue;
urls.push(sourceURL); 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); return Promise.all(promises).then(undefined);
...@@ -210,7 +210,7 @@ function Runtime(descriptors, coreModuleNames) ...@@ -210,7 +210,7 @@ function Runtime(descriptors, coreModuleNames)
for (var i = 0; i < descriptors.length; ++i) for (var i = 0; i < descriptors.length; ++i)
this._registerModule(descriptors[i]); this._registerModule(descriptors[i]);
if (coreModuleNames) if (coreModuleNames)
this._loadAutoStartModules(coreModuleNames).done(); this._loadAutoStartModules(coreModuleNames).catch(Runtime._reportError);
} }
/** /**
...@@ -341,7 +341,7 @@ Runtime.startApplication = function(appName) ...@@ -341,7 +341,7 @@ Runtime.startApplication = function(appName)
coreModuleNames.push(name); coreModuleNames.push(name);
} }
Promise.all(moduleJSONPromises).then(instantiateRuntime).done(); Promise.all(moduleJSONPromises).then(instantiateRuntime).catch(Runtime._reportError);
/** /**
* @param {!Array.<!Object>} moduleDescriptors * @param {!Array.<!Object>} moduleDescriptors
*/ */
...@@ -376,6 +376,70 @@ Runtime._experimentsSetting = function() ...@@ -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 = { Runtime.prototype = {
/** /**
...@@ -537,7 +601,7 @@ Runtime.prototype = { ...@@ -537,7 +601,7 @@ Runtime.prototype = {
var promises = []; var promises = [];
for (var i = 0; i < extensions.length; ++i) for (var i = 0; i < extensions.length; ++i)
promises.push(extensions[i].instancePromise()); promises.push(extensions[i].instancePromise());
return Promise.some(promises); return Runtime._some(promises);
}, },
/** /**
...@@ -687,7 +751,7 @@ Runtime.Module.prototype = { ...@@ -687,7 +751,7 @@ Runtime.Module.prototype = {
if (Runtime.isReleaseMode()) if (Runtime.isReleaseMode())
return loadScriptsPromise([this._name + "_module.js"]); 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 * @param {string} scriptName
...@@ -853,7 +917,7 @@ Runtime.ExperimentsSupport.prototype = { ...@@ -853,7 +917,7 @@ Runtime.ExperimentsSupport.prototype = {
*/ */
register: function(experimentName, experimentTitle, hidden) 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._experimentNames[experimentName] = true;
this._experiments.push(new Runtime.Experiment(this, experimentName, experimentTitle, !!hidden)); this._experiments.push(new Runtime.Experiment(this, experimentName, experimentTitle, !!hidden));
}, },
...@@ -923,7 +987,7 @@ Runtime.ExperimentsSupport.prototype = { ...@@ -923,7 +987,7 @@ Runtime.ExperimentsSupport.prototype = {
*/ */
_checkExperiment: function(experimentName) _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 = { ...@@ -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. // This must be constructed after the query parameters have been parsed.
Runtime.experiments = new Runtime.ExperimentsSupport(); Runtime.experiments = new Runtime.ExperimentsSupport();
......
{ {
"dependencies": ["sdk", "workspace"], "dependencies": ["sdk", "platform", "workspace"],
"scripts": [ "scripts": [
"LiveLocation.js", "LiveLocation.js",
"CompilerScriptMapping.js", "CompilerScriptMapping.js",
......
...@@ -248,3 +248,78 @@ Size.prototype.addHeight = function(size) ...@@ -248,3 +248,78 @@ Size.prototype.addHeight = function(size)
{ {
return new Size(this.width, this.height + (typeof size === "number" ? size : size.height)); return new Size(this.width, this.height + (typeof size === "number" ? size : size.height));
}; };
/**
* @constructor
* @param {!Size} minimum
* @param {?Size=} preferred
*/
function Constraints(minimum, preferred)
{
/**
* @type {!Size}
*/
this.minimum = minimum;
/**
* @type {!Size}
*/
this.preferred = preferred || minimum;
if (this.minimum.width > this.preferred.width || this.minimum.height > this.preferred.height)
throw new Error("Minimum size is greater than preferred.");
}
/**
* @param {?Constraints} constraints
* @return {boolean}
*/
Constraints.prototype.isEqual = function(constraints)
{
return !!constraints && this.minimum.isEqual(constraints.minimum) && this.preferred.isEqual(constraints.preferred);
}
/**
* @param {!Constraints|number} value
* @return {!Constraints}
*/
Constraints.prototype.widthToMax = function(value)
{
if (typeof value === "number")
return new Constraints(this.minimum.widthToMax(value), this.preferred.widthToMax(value));
return new Constraints(this.minimum.widthToMax(value.minimum), this.preferred.widthToMax(value.preferred));
}
/**
* @param {!Constraints|number} value
* @return {!Constraints}
*/
Constraints.prototype.addWidth = function(value)
{
if (typeof value === "number")
return new Constraints(this.minimum.addWidth(value), this.preferred.addWidth(value));
return new Constraints(this.minimum.addWidth(value.minimum), this.preferred.addWidth(value.preferred));
}
/**
* @param {!Constraints|number} value
* @return {!Constraints}
*/
Constraints.prototype.heightToMax = function(value)
{
if (typeof value === "number")
return new Constraints(this.minimum.heightToMax(value), this.preferred.heightToMax(value));
return new Constraints(this.minimum.heightToMax(value.minimum), this.preferred.heightToMax(value.preferred));
}
/**
* @param {!Constraints|number} value
* @return {!Constraints}
*/
Constraints.prototype.addHeight = function(value)
{
if (typeof value === "number")
return new Constraints(this.minimum.addHeight(value), this.preferred.addHeight(value));
return new Constraints(this.minimum.addHeight(value.minimum), this.preferred.addHeight(value.preferred));
}
{ {
"dependencies": [
"platform"
],
"scripts": [ "scripts": [
"utilities.js",
"WebInspector.js", "WebInspector.js",
"Object.js", "Object.js",
"NotificationService.js", "NotificationService.js",
......
{ {
"dependencies": [ "dependencies": [
"ui", "bindings",
"bindings" "platform",
"ui"
], ],
"scripts": [ "scripts": [
"CookiesTable.js", "CookiesTable.js",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
} }
], ],
"dependencies": [ "dependencies": [
"platform",
"sdk", "sdk",
"ui" "ui"
], ],
......
[ [
{ "name": "platform", "type": "autostart" },
{ "name": "main", "type": "autostart" }, { "name": "main", "type": "autostart" },
{ "name": "components", "type": "autostart" }, { "name": "components", "type": "autostart" },
{ "name": "ui", "type": "autostart" }, { "name": "ui", "type": "autostart" },
......
{ {
"scripts": [ "scripts": [
"../common/utilities.js", "../platform/Promise.js",
"../platform/utilities.js",
"../common/WebInspector.js", "../common/WebInspector.js",
"../common/UIString.js", "../common/UIString.js",
"../common/TextUtils.js", "../common/TextUtils.js",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @interface
*/
WebInspector.ToolboxHost = function() {}
WebInspector.ToolboxHost.prototype = {
/**
* @param {!Document} document
*/
toolboxLoaded: function(document) {}
}
{ {
"dependencies": [ "dependencies": [
"common" "common",
"platform"
], ],
"scripts": [ "scripts": [
"DOMExtension.js",
"InspectorFrontendHost.js", "InspectorFrontendHost.js",
"Platform.js", "Platform.js",
"ToolboxHost.js",
"UserMetrics.js" "UserMetrics.js"
] ]
} }
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
/** /**
* @constructor * @constructor
* @extends {WebInspector.App} * @extends {WebInspector.App}
* @implements {WebInspector.ToolboxHost}
*/ */
WebInspector.AdvancedApp = function() WebInspector.AdvancedApp = function()
{ {
...@@ -93,7 +92,6 @@ WebInspector.AdvancedApp.prototype = { ...@@ -93,7 +92,6 @@ WebInspector.AdvancedApp.prototype = {
/** /**
* @param {!Document} toolboxDocument * @param {!Document} toolboxDocument
* @override
*/ */
toolboxLoaded: function(toolboxDocument) toolboxLoaded: function(toolboxDocument)
{ {
......
...@@ -228,6 +228,7 @@ ...@@ -228,6 +228,7 @@
"dependencies": [ "dependencies": [
"extensions", "extensions",
"host", "host",
"platform",
"screencast", "screencast",
"sdk", "sdk",
"toolbox" "toolbox"
......
...@@ -202,80 +202,6 @@ function removeSubsequentNodes(fromNode, toNode) ...@@ -202,80 +202,6 @@ function removeSubsequentNodes(fromNode, toNode)
} }
} }
/**
* @constructor
* @param {!Size} minimum
* @param {?Size=} preferred
*/
function Constraints(minimum, preferred)
{
/**
* @type {!Size}
*/
this.minimum = minimum;
/**
* @type {!Size}
*/
this.preferred = preferred || minimum;
if (this.minimum.width > this.preferred.width || this.minimum.height > this.preferred.height)
throw new Error("Minimum size is greater than preferred.");
}
/**
* @param {?Constraints} constraints
* @return {boolean}
*/
Constraints.prototype.isEqual = function(constraints)
{
return !!constraints && this.minimum.isEqual(constraints.minimum) && this.preferred.isEqual(constraints.preferred);
}
/**
* @param {!Constraints|number} value
* @return {!Constraints}
*/
Constraints.prototype.widthToMax = function(value)
{
if (typeof value === "number")
return new Constraints(this.minimum.widthToMax(value), this.preferred.widthToMax(value));
return new Constraints(this.minimum.widthToMax(value.minimum), this.preferred.widthToMax(value.preferred));
}
/**
* @param {!Constraints|number} value
* @return {!Constraints}
*/
Constraints.prototype.addWidth = function(value)
{
if (typeof value === "number")
return new Constraints(this.minimum.addWidth(value), this.preferred.addWidth(value));
return new Constraints(this.minimum.addWidth(value.minimum), this.preferred.addWidth(value.preferred));
}
/**
* @param {!Constraints|number} value
* @return {!Constraints}
*/
Constraints.prototype.heightToMax = function(value)
{
if (typeof value === "number")
return new Constraints(this.minimum.heightToMax(value), this.preferred.heightToMax(value));
return new Constraints(this.minimum.heightToMax(value.minimum), this.preferred.heightToMax(value.preferred));
}
/**
* @param {!Constraints|number} value
* @return {!Constraints}
*/
Constraints.prototype.addHeight = function(value)
{
if (typeof value === "number")
return new Constraints(this.minimum.addHeight(value), this.preferred.addHeight(value));
return new Constraints(this.minimum.addHeight(value.minimum), this.preferred.addHeight(value.preferred));
}
/** /**
* @param {!Event} event * @param {!Event} event
* @return {boolean} * @return {boolean}
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @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
* @this {Promise}
*/
function reject(e)
{
this._reportError(e);
callback(undefined);
}
}
Promise.prototype.done = function()
{
this.catchAndReport();
}
/**
* @return {!Promise}
*/
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);
}
{
"dependencies": [
],
"scripts": [
"Promise.js",
"utilities.js",
"DOMExtension.js"
]
}
...@@ -27,6 +27,17 @@ ...@@ -27,6 +27,17 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
// 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);
}
/** @typedef {Array|NodeList|Arguments|{length: number}} */ /** @typedef {Array|NodeList|Arguments|{length: number}} */
var ArrayLike; var ArrayLike;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
], ],
"dependencies": [ "dependencies": [
"bindings", "bindings",
"platform",
"ui" "ui"
], ],
"experiment": "promiseTracker", "experiment": "promiseTracker",
......
{ {
"scripts": [ "scripts": [
"../common/utilities.js", "../platform/Promise.js",
"../platform/utilities.js",
"../cm/headlesscodemirror.js", "../cm/headlesscodemirror.js",
"../cm/css.js", "../cm/css.js",
"../cm/javascript.js", "../cm/javascript.js",
......
{ {
"dependencies": [ "dependencies": [
"common", "common",
"host" "host",
"platform"
], ],
"scripts": [ "scripts": [
"InspectorBackend.js", "InspectorBackend.js",
......
[ [
{ {
"name": "host", "name": "platform",
"type": "autostart"
},
{
"name": "common",
"type": "autostart" "type": "autostart"
}, },
{ {
......
{ {
"dependencies": [ "dependencies": [
"ui", "bindings",
"bindings" "platform",
"ui"
], ],
"scripts": [ "scripts": [
"OverridesUI.js", "OverridesUI.js",
......
...@@ -2,30 +2,31 @@ ...@@ -2,30 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// FIXME: This stub is invoked from the backend and should be removed
// once we migrate to the "pull" model for extensions retrieval.
WebInspector = {};
WebInspector.addExtensions = function() {};
(function()
{
/** /**
* @constructor
* @suppressGlobalPropertiesCheck * @suppressGlobalPropertiesCheck
*/ */
WebInspector.Toolbox = function() function toolboxLoaded()
{ {
if (!window.opener) if (!window.opener)
return; return;
window.opener.WebInspector["app"]["toolboxLoaded"](document);
var host = /** @type {!WebInspector.ToolboxHost} */ (window.opener.WebInspector["app"]);
host.toolboxLoaded(document);
} }
// FIXME: This stub is invoked from the backend and should be removed
// once we migrate to the "pull" model for extensions retrieval.
WebInspector.addExtensions = function() {}
/** /**
* @suppressGlobalPropertiesCheck * @suppressGlobalPropertiesCheck
*/ */
function windowLoaded() function windowLoaded()
{ {
window.removeEventListener("DOMContentLoaded", windowLoaded, false); window.removeEventListener("DOMContentLoaded", windowLoaded, false);
new WebInspector.Toolbox(); toolboxLoaded();
} }
/** /**
...@@ -34,8 +35,10 @@ function windowLoaded() ...@@ -34,8 +35,10 @@ function windowLoaded()
function initToolbox() function initToolbox()
{ {
if (document.readyState === "complete") if (document.readyState === "complete")
new WebInspector.Toolbox(); toolboxLoaded();
else else
window.addEventListener("DOMContentLoaded", windowLoaded, false); window.addEventListener("DOMContentLoaded", windowLoaded, false);
} }
initToolbox(); initToolbox();
})();
\ No newline at end of file
{ {
"dependencies": [ "dependencies": [
"host", "platform"
"common"
], ],
"scripts": [ "scripts": [
"Toolbox.js" "Toolbox.js"
......
{ {
"dependencies": [ "dependencies": [
"platform",
"common", "common",
"host" "host"
], ],
......
{ {
"dependencies": ["common", "host"], "dependencies": ["common", "host", "platform"],
"scripts": [ "scripts": [
"FileManager.js", "FileManager.js",
"FileSystemMapping.js", "FileSystemMapping.js",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment