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

Unified Diff: third_party/WebKit/Source/devtools/front_end/sdk/RemoteObject.js

Issue 2899163002: DevTools: Promisify Runtime domain (Closed)
Patch Set: addressing comments Created 3 years, 7 months 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
Index: third_party/WebKit/Source/devtools/front_end/sdk/RemoteObject.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/RemoteObject.js b/third_party/WebKit/Source/devtools/front_end/sdk/RemoteObject.js
index 32067513efb1d69ff7b5f484d642cfff76a1c5d2..0aa4e28df5ce18d80b4c9f07e0755e0ad3680a98 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/RemoteObject.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/RemoteObject.js
@@ -381,14 +381,7 @@ SDK.RemoteObject = class {
* @template T
*/
callFunctionJSONPromise(functionDeclaration, args) {
- return new Promise(promiseConstructor.bind(this));
-
- /**
- * @this {SDK.RemoteObject}
- */
- function promiseConstructor(success) {
- this.callFunctionJSON(functionDeclaration, args, success);
- }
+ return new Promise(success => this.callFunctionJSON(functionDeclaration, args, success));
}
release() {
@@ -575,7 +568,7 @@ SDK.RemoteObjectImpl = class extends SDK.RemoteObject {
* @param {boolean} ownProperties
* @param {boolean} accessorPropertiesOnly
* @param {boolean} generatePreview
- * @param {function(?Array.<!SDK.RemoteObjectProperty>, ?Array.<!SDK.RemoteObjectProperty>)} callback
+ * @param {function(?Array<!SDK.RemoteObjectProperty>, ?Array<!SDK.RemoteObjectProperty>)} callback
*/
doGetProperties(ownProperties, accessorPropertiesOnly, generatePreview, callback) {
if (!this._objectId) {
@@ -583,23 +576,26 @@ SDK.RemoteObjectImpl = class extends SDK.RemoteObject {
return;
}
+ this._runtimeAgent
+ .invoke_getProperties({objectId: this._objectId, ownProperties, accessorPropertiesOnly, generatePreview})
+ .then(remoteObjectBinder.bind(this));
+
/**
- * @param {?Protocol.Error} error
- * @param {!Array.<!Protocol.Runtime.PropertyDescriptor>} properties
- * @param {!Array.<!Protocol.Runtime.InternalPropertyDescriptor>=} internalProperties
- * @param {?Protocol.Runtime.ExceptionDetails=} exceptionDetails
+ * @param {!Protocol.RuntimeAgent.GetPropertiesResponse} response
* @this {SDK.RemoteObjectImpl}
*/
- function remoteObjectBinder(error, properties, internalProperties, exceptionDetails) {
- if (error) {
+ function remoteObjectBinder(response) {
+ if (response[Protocol.Error]) {
callback(null, null);
return;
}
- if (exceptionDetails) {
- this._runtimeModel.exceptionThrown(Date.now(), exceptionDetails);
+ if (response.exceptionDetails) {
+ this._runtimeModel.exceptionThrown(Date.now(), response.exceptionDetails);
callback(null, null);
return;
}
+ var properties = response.result;
+ var internalProperties = response.internalProperties;
var result = [];
for (var i = 0; properties && i < properties.length; ++i) {
var property = properties[i];
@@ -631,8 +627,6 @@ SDK.RemoteObjectImpl = class extends SDK.RemoteObject {
}
callback(result, internalPropertiesResult);
}
- this._runtimeAgent.getProperties(
- this._objectId, ownProperties, accessorPropertiesOnly, generatePreview, remoteObjectBinder.bind(this));
}
/**
@@ -643,7 +637,7 @@ SDK.RemoteObjectImpl = class extends SDK.RemoteObject {
*/
setPropertyValue(name, value, callback) {
if (!this._objectId) {
- callback('Can\'t set a property of non-object.');
+ callback(`Can't set a property of non-object.`);
return;
}
@@ -659,7 +653,7 @@ SDK.RemoteObjectImpl = class extends SDK.RemoteObject {
if (typeof name === 'string')
name = SDK.RemoteObject.toCallArgument(name);
- this.doSetObjectPropertyValue(response.result, name, callback);
+ this.doSetObjectPropertyValue(response.result, name).then(callback);
if (response.result.objectId)
this._runtimeAgent.releaseObject(response.result.objectId);
@@ -669,9 +663,9 @@ SDK.RemoteObjectImpl = class extends SDK.RemoteObject {
/**
* @param {!Protocol.Runtime.RemoteObject} result
* @param {!Protocol.Runtime.CallArgument} name
- * @param {function(string=)} callback
+ * @return {!Promise<string|undefined>}
*/
- doSetObjectPropertyValue(result, name, callback) {
+ async doSetObjectPropertyValue(result, name) {
// This assignment may be for a regular (data) property, and for an accessor property (with getter/setter).
// Note the sensitive matter about accessor property: the property may be physically defined in some proto object,
// but logically it is bound to the object in question. JavaScript passes this object to getters/setters, not the object
@@ -679,22 +673,10 @@ SDK.RemoteObjectImpl = class extends SDK.RemoteObject {
var setPropertyValueFunction = 'function(a, b) { this[a] = b; }';
var argv = [name, SDK.RemoteObject.toCallArgument(result)];
- this._runtimeAgent.callFunctionOn(
- this._objectId, setPropertyValueFunction, argv, true, undefined, undefined, undefined, undefined,
- propertySetCallback);
-
- /**
- * @param {?Protocol.Error} error
- * @param {!Protocol.Runtime.RemoteObject} result
- * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails
- */
- function propertySetCallback(error, result, exceptionDetails) {
- if (error || !!exceptionDetails) {
- callback(error || result.description);
- return;
- }
- callback();
- }
+ var response = await this._runtimeAgent.invoke_callFunctionOn(
+ {objectId: this._objectId, functionDeclaration: setPropertyValueFunction, arguments: argv, silent: true});
+ var error = response[Protocol.Error];
+ return error || response.exceptionDetails ? error || response.result.description : undefined;
}
/**
@@ -704,30 +686,24 @@ SDK.RemoteObjectImpl = class extends SDK.RemoteObject {
*/
deleteProperty(name, callback) {
if (!this._objectId) {
- callback('Can\'t delete a property of non-object.');
+ callback(`Can't delete a property of non-object.`);
return;
}
var deletePropertyFunction = 'function(a) { delete this[a]; return !(a in this); }';
- this._runtimeAgent.callFunctionOn(
- this._objectId, deletePropertyFunction, [name], true, undefined, undefined, undefined, undefined,
- deletePropertyCallback);
-
- /**
- * @param {?Protocol.Error} error
- * @param {!Protocol.Runtime.RemoteObject} result
- * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails
- */
- function deletePropertyCallback(error, result, exceptionDetails) {
- if (error || !!exceptionDetails) {
- callback(error || result.description);
- return;
- }
- if (!result.value)
- callback('Failed to delete property.');
- else
- callback();
- }
+ this._runtimeAgent
+ .invoke_callFunctionOn(
+ {objectId: this._objectId, functionDeclaration: deletePropertyFunction, arguments: [name], silent: true})
+ .then(response => {
+ if (response[Protocol.Error] || response.exceptionDetails) {
+ callback(response[Protocol.Error] || response.result.description);
+ return;
+ }
+ if (!response.result.value)
+ callback('Failed to delete property.');
+ else
+ callback();
+ });
}
/**
@@ -737,24 +713,21 @@ SDK.RemoteObjectImpl = class extends SDK.RemoteObject {
* @param {function(?SDK.RemoteObject, boolean=)=} callback
*/
callFunction(functionDeclaration, args, callback) {
- /**
- * @param {?Protocol.Error} error
- * @param {!Protocol.Runtime.RemoteObject} result
- * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails
- * @this {SDK.RemoteObjectImpl}
- */
- function mycallback(error, result, exceptionDetails) {
- if (!callback)
- return;
- if (error)
- callback(null, false);
- else
- callback(this._runtimeModel.createRemoteObject(result), !!exceptionDetails);
- }
-
- this._runtimeAgent.callFunctionOn(
- this._objectId, functionDeclaration.toString(), args, true, undefined, undefined, undefined, undefined,
- mycallback.bind(this));
+ this._runtimeAgent
+ .invoke_callFunctionOn({
+ objectId: this._objectId,
+ functionDeclaration: functionDeclaration.toString(),
+ arguments: args,
+ silent: true
+ })
+ .then(response => {
+ if (!callback)
+ return;
+ if (response[Protocol.Error])
+ callback(null, false);
+ else
+ callback(this._runtimeModel.createRemoteObject(response.result), !!response.exceptionDetails);
+ });
}
/**
@@ -764,17 +737,16 @@ SDK.RemoteObjectImpl = class extends SDK.RemoteObject {
* @param {function(*)} callback
*/
callFunctionJSON(functionDeclaration, args, callback) {
- /**
- * @param {?Protocol.Error} error
- * @param {!Protocol.Runtime.RemoteObject} result
- * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails
- */
- function mycallback(error, result, exceptionDetails) {
- callback((error || !!exceptionDetails) ? null : result.value);
- }
-
- this._runtimeAgent.callFunctionOn(
- this._objectId, functionDeclaration.toString(), args, true, true, false, undefined, undefined, mycallback);
+ this._runtimeAgent
+ .invoke_callFunctionOn({
+ objectId: this._objectId,
+ functionDeclaration: functionDeclaration.toString(),
+ arguments: args,
+ silent: true,
+ returnByValue: true
+ })
+ .then(
+ response => callback(response[Protocol.Error] || response.exceptionDetails ? null : response.result.value));
}
/**
@@ -885,13 +857,15 @@ SDK.ScopeRemoteObject = class extends SDK.RemoteObjectImpl {
* @override
* @param {!Protocol.Runtime.RemoteObject} result
* @param {!Protocol.Runtime.CallArgument} argumentName
- * @param {function(string=)} callback
+ * @return {!Promise<string|undefined>}
*/
- doSetObjectPropertyValue(result, argumentName, callback) {
+ async doSetObjectPropertyValue(result, argumentName) {
var name = /** @type {string} */ (argumentName.value);
this.debuggerModel().setVariableValue(
this._scopeRef.number, name, SDK.RemoteObject.toCallArgument(result), this._scopeRef.callFrameId,
setVariableValueCallback.bind(this));
+ var callback;
+ return new Promise(resolve => callback = resolve);
/**
* @param {string=} error
@@ -1180,15 +1154,12 @@ SDK.LocalJSONObject = class extends SDK.RemoteObject {
/**
* @override
* @param {function(this:Object, ...)} functionDeclaration
- * @param {!Array.<!Protocol.Runtime.CallArgument>=} args
+ * @param {!Array<!Protocol.Runtime.CallArgument>=} args
* @param {function(?SDK.RemoteObject, boolean=)=} callback
*/
callFunction(functionDeclaration, args, callback) {
var target = /** @type {?Object} */ (this._value);
- var rawArgs = args ? args.map(function(arg) {
- return arg.value;
- }) :
- [];
+ var rawArgs = args ? args.map(arg => arg.value) : [];
var result;
var wasThrown = false;
@@ -1206,15 +1177,12 @@ SDK.LocalJSONObject = class extends SDK.RemoteObject {
/**
* @override
* @param {function(this:Object)} functionDeclaration
- * @param {!Array.<!Protocol.Runtime.CallArgument>|undefined} args
+ * @param {!Array<!Protocol.Runtime.CallArgument>|undefined} args
* @param {function(*)} callback
*/
callFunctionJSON(functionDeclaration, args, callback) {
var target = /** @type {?Object} */ (this._value);
- var rawArgs = args ? args.map(function(arg) {
- return arg.value;
- }) :
- [];
+ var rawArgs = args ? args.map(arg => arg.value) : [];
var result;
try {

Powered by Google App Engine
This is Rietveld 408576698