Commit 1b172db1 authored by aandrey@chromium.org's avatar aandrey@chromium.org

DevTools: Deleting object property in console would just assign it to undefined.

Evaluate explicit "delete this[p]" to delete a property.

R=vsevik

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

git-svn-id: svn://svn.chromium.org/blink/trunk@176188 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4187dfaf
......@@ -298,12 +298,14 @@ WebInspector.ObjectPropertyTreeElement.prototype = {
},
/**
* @param {!Event=} event
* @return {!Array.<!Element|undefined>}
* @return {{element: !Element, value: (string|undefined)}}
*/
elementAndValueToEdit: function(event)
elementAndValueToEdit: function()
{
return [this.valueElement, (typeof this.valueElement._originalTextContent === "string") ? this.valueElement._originalTextContent : undefined];
return {
element: this.valueElement,
value: (typeof this.valueElement._originalTextContent === "string") ? this.valueElement._originalTextContent : undefined
};
},
/**
......@@ -311,9 +313,9 @@ WebInspector.ObjectPropertyTreeElement.prototype = {
*/
startEditing: function(event)
{
var elementAndValueToEdit = this.elementAndValueToEdit(event);
var elementToEdit = elementAndValueToEdit[0];
var valueToEdit = elementAndValueToEdit[1];
var elementAndValueToEdit = this.elementAndValueToEdit();
var elementToEdit = elementAndValueToEdit.element;
var valueToEdit = elementAndValueToEdit.value;
if (WebInspector.isBeingEdited(elementToEdit) || !this.treeOutline.section.editable || this._readOnly)
return;
......@@ -377,7 +379,7 @@ WebInspector.ObjectPropertyTreeElement.prototype = {
}
this.editingEnded(context);
this.applyExpression(userInput, true);
this.applyExpression(userInput);
},
_promptKeyDown: function(context, event)
......@@ -394,10 +396,16 @@ WebInspector.ObjectPropertyTreeElement.prototype = {
}
},
applyExpression: function(expression, updateInterface)
/**
* @param {string} expression
*/
applyExpression: function(expression)
{
expression = expression.trim();
var expressionLength = expression.length;
if (expression)
this.property.parentObject.setPropertyValue(this.property.name, expression, callback.bind(this));
else
this.property.parentObject.deleteProperty(this.property.name, callback.bind(this));
/**
* @param {?Protocol.Error} error
......@@ -405,13 +413,12 @@ WebInspector.ObjectPropertyTreeElement.prototype = {
*/
function callback(error)
{
if (!updateInterface)
return;
if (error)
if (error) {
this.update();
return;
}
if (!expressionLength) {
if (!expression) {
// The property was deleted, so remove this tree element.
this.parent.removeChild(this);
} else {
......@@ -419,7 +426,6 @@ WebInspector.ObjectPropertyTreeElement.prototype = {
this.updateSiblings();
}
};
this.property.parentObject.setPropertyValue(this.property.name, expression.trim(), callback.bind(this));
},
/**
......
......@@ -85,6 +85,15 @@ WebInspector.RemoteObject.prototype = {
throw "Not implemented";
},
/**
* @param {string} name
* @param {function(string=)} callback
*/
deleteProperty: function(name, callback)
{
throw "Not implemented";
},
/**
* @param {function(this:Object, ...)} functionDeclaration
* @param {!Array.<!RuntimeAgent.CallArgument>=} args
......@@ -428,6 +437,38 @@ WebInspector.RemoteObjectImpl.prototype = {
}
},
/**
* @param {string} name
* @param {function(string=)} callback
*/
deleteProperty: function(name, callback)
{
if (!this._objectId) {
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, [{ value: name }], true, undefined, undefined, deletePropertyCallback);
/**
* @param {?Protocol.Error} error
* @param {!RuntimeAgent.RemoteObject} result
* @param {boolean=} wasThrown
*/
function deletePropertyCallback(error, result, wasThrown)
{
if (error || wasThrown) {
callback(error || result.description);
return;
}
if (!result.value)
callback("Failed to delete property.");
else
callback();
}
},
/**
* @param {function(?WebInspector.DOMNode)} callback
*/
......
......@@ -449,14 +449,17 @@ WebInspector.WatchExpressionTreeElement.prototype = {
},
/**
* @param {!Event=} event
* @return {!Array.<!Element|string>}
* @override
* @return {{element: !Element, value: (string|undefined)}}
*/
elementAndValueToEdit: function(event)
elementAndValueToEdit: function()
{
return [this.nameElement, this.property.name.trim()];
return { element: this.nameElement, value: this.property.name.trim() };
},
/**
* @override
*/
editingCancelled: function(element, context)
{
if (!context.elementToEdit.textContent)
......@@ -465,14 +468,14 @@ WebInspector.WatchExpressionTreeElement.prototype = {
WebInspector.ObjectPropertyTreeElement.prototype.editingCancelled.call(this, element, context);
},
applyExpression: function(expression, updateInterface)
/**
* @override
* @param {string} expression
*/
applyExpression: function(expression)
{
expression = expression.trim();
if (!expression)
expression = null;
this.property.name = expression;
this.property.name = expression || null;
this.treeOutline.section.updateExpression(this, expression);
},
......
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