Chromium Code Reviews| 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..ab445e8dfd92e9eeb48744e5546f1f0f318bcbea 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,64 +568,62 @@ 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) { | 
| + async doGetProperties(ownProperties, accessorPropertiesOnly, generatePreview, callback) { | 
| 
 
pfeldman
2017/05/24 00:43:32
async function with the callback seems like an ant
 
alph
2017/05/24 01:42:57
Done.
 
 | 
| if (!this._objectId) { | 
| callback(null, null); | 
| return; | 
| } | 
| - /** | 
| - * @param {?Protocol.Error} error | 
| - * @param {!Array.<!Protocol.Runtime.PropertyDescriptor>} properties | 
| - * @param {!Array.<!Protocol.Runtime.InternalPropertyDescriptor>=} internalProperties | 
| - * @param {?Protocol.Runtime.ExceptionDetails=} exceptionDetails | 
| - * @this {SDK.RemoteObjectImpl} | 
| - */ | 
| - function remoteObjectBinder(error, properties, internalProperties, exceptionDetails) { | 
| - if (error) { | 
| - callback(null, null); | 
| - return; | 
| - } | 
| - if (exceptionDetails) { | 
| - this._runtimeModel.exceptionThrown(Date.now(), exceptionDetails); | 
| - callback(null, null); | 
| - return; | 
| - } | 
| - var result = []; | 
| - for (var i = 0; properties && i < properties.length; ++i) { | 
| - var property = properties[i]; | 
| - var propertyValue = property.value ? this._runtimeModel.createRemoteObject(property.value) : null; | 
| - var propertySymbol = property.symbol ? this._runtimeModel.createRemoteObject(property.symbol) : null; | 
| - var remoteProperty = new SDK.RemoteObjectProperty( | 
| - property.name, propertyValue, !!property.enumerable, !!property.writable, !!property.isOwn, | 
| - !!property.wasThrown, propertySymbol); | 
| - | 
| - if (typeof property.value === 'undefined') { | 
| - if (property.get && property.get.type !== 'undefined') | 
| - remoteProperty.getter = this._runtimeModel.createRemoteObject(property.get); | 
| - if (property.set && property.set.type !== 'undefined') | 
| - remoteProperty.setter = this._runtimeModel.createRemoteObject(property.set); | 
| - } | 
| + var response = await this._runtimeAgent.invoke_getProperties({ | 
| + objectId: this._objectId, | 
| + ownProperties: ownProperties, | 
| + accessorPropertiesOnly: accessorPropertiesOnly, | 
| + generatePreview: generatePreview | 
| + }); | 
| + if (response[Protocol.Error]) { | 
| + callback(null, null); | 
| + return; | 
| + } | 
| - result.push(remoteProperty); | 
| + var properties = response.result; | 
| + var internalProperties = response.internalProperties; | 
| + if (response.exceptionDetails) { | 
| + this._runtimeModel.exceptionThrown(Date.now(), response.exceptionDetails); | 
| + callback(null, null); | 
| + return; | 
| + } | 
| + var result = []; | 
| + for (var i = 0; properties && i < properties.length; ++i) { | 
| + var property = properties[i]; | 
| + var propertyValue = property.value ? this._runtimeModel.createRemoteObject(property.value) : null; | 
| + var propertySymbol = property.symbol ? this._runtimeModel.createRemoteObject(property.symbol) : null; | 
| + var remoteProperty = new SDK.RemoteObjectProperty( | 
| + property.name, propertyValue, !!property.enumerable, !!property.writable, !!property.isOwn, | 
| + !!property.wasThrown, propertySymbol); | 
| + | 
| + if (typeof property.value === 'undefined') { | 
| + if (property.get && property.get.type !== 'undefined') | 
| + remoteProperty.getter = this._runtimeModel.createRemoteObject(property.get); | 
| + if (property.set && property.set.type !== 'undefined') | 
| + remoteProperty.setter = this._runtimeModel.createRemoteObject(property.set); | 
| } | 
| - var internalPropertiesResult = null; | 
| - if (internalProperties) { | 
| - internalPropertiesResult = []; | 
| - for (var i = 0; i < internalProperties.length; i++) { | 
| - var property = internalProperties[i]; | 
| - if (!property.value) | 
| - continue; | 
| - var propertyValue = this._runtimeModel.createRemoteObject(property.value); | 
| - internalPropertiesResult.push(new SDK.RemoteObjectProperty(property.name, propertyValue, true, false)); | 
| - } | 
| + | 
| + result.push(remoteProperty); | 
| + } | 
| + var internalPropertiesResult = null; | 
| + if (internalProperties) { | 
| + internalPropertiesResult = []; | 
| + for (var i = 0; i < internalProperties.length; i++) { | 
| + var property = internalProperties[i]; | 
| + if (!property.value) | 
| + continue; | 
| + var propertyValue = this._runtimeModel.createRemoteObject(property.value); | 
| + internalPropertiesResult.push(new SDK.RemoteObjectProperty(property.name, propertyValue, true, false)); | 
| } | 
| - callback(result, internalPropertiesResult); | 
| } | 
| - this._runtimeAgent.getProperties( | 
| - this._objectId, ownProperties, accessorPropertiesOnly, generatePreview, remoteObjectBinder.bind(this)); | 
| + callback(result, internalPropertiesResult); | 
| } | 
| /** | 
| @@ -659,7 +650,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 +660,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) { | 
| 
 
pfeldman
2017/05/24 00:43:32
async overriden by non-async below.
 
alph
2017/05/24 01:42:58
No, they are both async
 
 | 
| // 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 +670,9 @@ 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}); | 
| + return response[Protocol.error] || response.result.description || undefined; | 
| 
 
pfeldman
2017/05/24 00:43:32
You should return non-undefined upon error only.
 
alph
2017/05/24 01:42:58
Done.
 
 | 
| } | 
| /** | 
| @@ -704,30 +682,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 +709,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 +733,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 +853,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 | 
| @@ -908,7 +878,7 @@ SDK.ScopeRemoteObject = class extends SDK.RemoteObjectImpl { | 
| this._savedScopeProperties[i].value = this._runtimeModel.createRemoteObject(result); | 
| } | 
| } | 
| - callback(); | 
| + callback(undefined); | 
| } | 
| } | 
| }; | 
| @@ -1180,15 +1150,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 +1173,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 { |