Index: Source/devtools/front_end/sdk/RemoteObject.js |
diff --git a/Source/devtools/front_end/sdk/RemoteObject.js b/Source/devtools/front_end/sdk/RemoteObject.js |
index 445f441ca1e483f564b1b29cbbb52d0bc618d421..492f7224264e1d41f99bdc2f11100ea871fd3a3a 100644 |
--- a/Source/devtools/front_end/sdk/RemoteObject.js |
+++ b/Source/devtools/front_end/sdk/RemoteObject.js |
@@ -29,6 +29,11 @@ |
*/ |
/** |
+ * @typedef {{object: ?WebInspector.RemoteObject, wasThrown: (boolean|undefined)}} |
+ */ |
+WebInspector.CallFunctionResult; |
+ |
+/** |
* This may not be an interface due to "instanceof WebInspector.RemoteObject" checks in the code. |
* |
* @constructor |
@@ -164,6 +169,24 @@ WebInspector.RemoteObject.prototype = { |
}, |
/** |
+ * @param {function(this:Object):!Array<!{handler:function(), useCapture: boolean, type:string}>} getter |
+ * @return {!Promise<?Array<!WebInspector.EventListener>>} |
+ */ |
+ frameworkEventListeners: function(getter) |
+ { |
+ throw "Not implemented"; |
+ }, |
+ |
+ /** |
+ * @param {function(this:Object):!Array<function()>} getter |
+ * @return {!Promise<?WebInspector.RemoteSet>} |
+ */ |
+ frameworkInternalHandlers: function(getter) |
+ { |
+ throw "Not implemented"; |
+ }, |
+ |
+ /** |
* @param {!RuntimeAgent.CallArgument} name |
* @param {function(string=)} callback |
*/ |
@@ -185,14 +208,14 @@ WebInspector.RemoteObject.prototype = { |
/** |
* @param {function(this:Object, ...)} functionDeclaration |
* @param {!Array.<!RuntimeAgent.CallArgument>=} args |
- * @return {!Promise.<!{object: ?WebInspector.RemoteObject, wasThrown: (boolean|undefined)}>} |
+ * @return {!Promise<!WebInspector.CallFunctionResult>} |
*/ |
callFunctionPromise: function(functionDeclaration, args) |
{ |
return new Promise(promiseConstructor.bind(this)); |
/** |
- * @param {function(!{object: ?WebInspector.RemoteObject, wasThrown: (boolean|undefined)})} success |
+ * @param {function(!WebInspector.CallFunctionResult)} success |
* @this {WebInspector.RemoteObject} |
*/ |
function promiseConstructor(success) |
@@ -201,7 +224,7 @@ WebInspector.RemoteObject.prototype = { |
} |
/** |
- * @param {function(!{object: ?WebInspector.RemoteObject, wasThrown: (boolean|undefined)})} callback |
+ * @param {function(!WebInspector.CallFunctionResult)} callback |
* @param {?WebInspector.RemoteObject} object |
* @param {boolean=} wasThrown |
*/ |
@@ -215,7 +238,7 @@ WebInspector.RemoteObject.prototype = { |
}, |
/** |
- * @param {function(this:Object)} functionDeclaration |
+ * @param {function(this:Object, ...)} functionDeclaration |
* @param {!Array<!RuntimeAgent.CallArgument>|undefined} args |
* @param {function(*)} callback |
*/ |
@@ -225,7 +248,7 @@ WebInspector.RemoteObject.prototype = { |
}, |
/** |
- * @param {function(this:Object)} functionDeclaration |
+ * @param {function(this:Object, ...)} functionDeclaration |
* @param {!Array<!RuntimeAgent.CallArgument>|undefined} args |
* @return {!Promise<*>} |
*/ |
@@ -565,6 +588,177 @@ WebInspector.RemoteObjectImpl.prototype = { |
}, |
/** |
+ * @override |
+ * @param {function(this:Object):!Array<!{handler:function(), useCapture: boolean, type:string}>} getter |
+ * @return {!Promise<?Array<!WebInspector.EventListener>>} |
+ */ |
+ frameworkEventListeners: function(getter) |
pfeldman
2015/08/27 01:21:32
This does not belong to RemoteObject, I thought we
|
+ { |
+ return this.callFunctionPromise(getter, undefined) |
+ .then(WebInspector.assertCallFunctionResult) |
+ .then(WebInspector.RemoteArray.createPromise) |
+ .then(toEventListeners) |
+ .catchException(/** @type {?Array<!WebInspector.EventListener>} */(null)); |
+ |
+ /** |
+ * @param {!WebInspector.RemoteArray} array |
+ * @return {!Promise<?Array<!WebInspector.EventListener>>} |
+ */ |
+ function toEventListeners(array) |
+ { |
+ var promises = []; |
+ for (var i = 0; i < array.length(); ++i) { |
+ var promise = array.at(i) |
+ .then(WebInspector.assertCallFunctionResult) |
+ .then(toEventListener) |
+ .catchException(/** @type {?WebInspector.EventListener} */(null)); |
+ promises.push(promise); |
+ } |
+ return /** @type {!Promise<?Array<!WebInspector.EventListener>>} */(Promise.all(promises).then(nonEmptyListeners)); |
+ } |
+ |
+ /** |
+ * @param {!WebInspector.RemoteObject} object |
+ * @return {!Promise<!WebInspector.EventListener>} |
+ */ |
+ function toEventListener(object) |
+ { |
+ var data = {}; |
+ var promises = []; |
+ promises.push(object.callFunctionPromise(listenerEffectiveFunction, undefined) |
+ .then(WebInspector.assertCallFunctionResult) |
+ .then(WebInspector.RemoteFunction.createPromise) |
+ .then(storeTargetFunctionWithDetails.bind(null, data))); |
+ promises.push(object.callFunctionJSONPromise(WebInspector.identity, undefined) |
+ .then(WebInspector.storeTo.bind(null, data, "listenerJSON"))); |
+ return Promise.all(promises).then(createEventListener.bind(null, /** @type {!{targetFunction: !WebInspector.RemoteObject, listenerJSON: !Object, targetFunctionDetails: !WebInspector.DebuggerModel.FunctionDetails}}*/ (data))); |
+ } |
+ |
+ /** |
+ * @param {?} data |
+ * @param {!WebInspector.RemoteFunction} functionObject |
+ * @return {!Promise<void>} |
+ */ |
+ function storeTargetFunctionWithDetails(data, functionObject) |
+ { |
+ return functionObject.targetFunction() |
+ .then(WebInspector.storeTo.bind(null, data, "targetFunction")) |
+ .then(functionDetails); |
+ |
+ /** |
+ * @param {!WebInspector.RemoteObject} functionObject |
+ * @return {!Promise<void>} |
+ */ |
+ function functionDetails(functionObject) |
+ { |
+ return functionObject.functionDetailsPromise() |
+ .then(WebInspector.storeTo.bind(null, data, "targetFunctionDetails")); |
+ } |
+ } |
+ |
+ /** |
+ * @param {!{targetFunction: !WebInspector.RemoteObject, listenerJSON: !Object, targetFunctionDetails: !WebInspector.DebuggerModel.FunctionDetails}} data |
+ * @return {!WebInspector.EventListener} |
+ */ |
+ function createEventListener(data) |
+ { |
+ return new WebInspector.EventListener(data.targetFunction._target, |
+ data.listenerJSON.type, |
+ data.listenerJSON.useCapture, |
+ data.targetFunction, |
+ /** @type {!WebInspector.DebuggerModel.Location}} */ (data.targetFunctionDetails.location)); |
+ } |
+ |
+ /** |
+ * @suppressReceiverCheck |
+ * @return {function()} |
+ * @this {Object} |
+ */ |
+ function listenerEffectiveFunction() |
+ { |
+ if (typeof this.handler === "function") |
+ return this.handler; |
+ return typeof this.handler === "object" ? (this.handler.handlerEvent || this.handler.constructor) : null; |
+ } |
+ |
+ /** |
+ * @param {!Array<?WebInspector.EventListener>} listeners |
+ * @return {!Array<!WebInspector.EventListener>} |
+ */ |
+ function nonEmptyListeners(listeners) |
+ { |
+ return listeners.filter(filterOutEmpty); |
+ |
+ /** |
+ * @param {?WebInspector.EventListener} listener |
+ */ |
+ function filterOutEmpty(listener) |
+ { |
+ return !!listener; |
+ } |
+ } |
+ }, |
+ |
+ /** |
+ * @override |
+ * @param {function(this:Object):!Array<function()>} getter |
+ * @return {!Promise<?WebInspector.RemoteSet>} |
+ */ |
+ frameworkInternalHandlers: function(getter) |
+ { |
+ return this.callFunctionPromise(getter, undefined) |
+ .then(WebInspector.assertCallFunctionResult) |
+ .then(WebInspector.RemoteArray.createPromise) |
+ .then(toInternalHandlers.bind(this)) |
+ .catchException(/** @type {?WebInspector.RemoteSet} */(null)); |
+ |
+ /** |
+ * @param {!WebInspector.RemoteArray} array |
+ * @return {!Promise<!WebInspector.RemoteSet>} |
+ * @this {WebInspector.RemoteObject} |
+ */ |
+ function toInternalHandlers(array) |
+ { |
+ var promises = []; |
+ for (var i = 0; i < array.length(); ++i) { |
+ var promise = array.at(i) |
+ .then(WebInspector.assertCallFunctionResult) |
+ .then(WebInspector.RemoteFunction.createPromise) |
+ .then(toInternalHandler) |
+ .catchException(/** @type {?WebInspector.RemoteObject} */(null)); |
+ promises.push(promise); |
+ } |
+ return Promise.all(promises).then(nonEmptyHandlers).then(WebInspector.RemoteSet.createFromArrayPromise.bind(this)); |
+ } |
+ |
+ /** |
+ * @param {!WebInspector.RemoteFunction} handler |
+ * @return {!Promise<!WebInspector.RemoteObject>} |
+ */ |
+ function toInternalHandler(handler) |
+ { |
+ return handler.targetFunction(); |
+ } |
+ |
+ /** |
+ * @param {!Array<?WebInspector.RemoteObject>} handlers |
+ * @return {!Array<!WebInspector.RemoteObject>} |
+ */ |
+ function nonEmptyHandlers(handlers) |
+ { |
+ return handlers.filter(filterOutEmpty); |
+ |
+ /** |
+ * @param {?WebInspector.RemoteObject} handler |
+ */ |
+ function filterOutEmpty(handler) |
+ { |
+ return !!handler; |
+ } |
+ } |
+ }, |
+ |
+ /** |
* @param {!Array.<string>} propertyPath |
* @param {function(?WebInspector.RemoteObject, boolean=)} callback |
*/ |