Commit e160480a authored by aandrey@chromium.org's avatar aandrey@chromium.org

DevTools: Extend Runtime.CallArgument to pass numbers that can not be JSON-stringified.

These numbers are: NaN, Infinity, -Infinity, -0.

R=pfeldman
TEST=various existing tests

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

git-svn-id: svn://svn.chromium.org/blink/trunk@169376 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 7d1422ba
......@@ -581,7 +581,10 @@ InjectedScript.prototype = {
return resolvedArg;
} else if ("value" in callArgumentJson) {
return callArgumentJson.value;
var value = callArgumentJson.value;
if (callArgumentJson.type === "number" && typeof value !== "number")
value = Number(value);
return value;
}
return undefined;
},
......@@ -1007,8 +1010,19 @@ InjectedScript.RemoteObject = function(object, objectGroupName, forceValueType,
this.subtype = "null";
// Provide user-friendly number values.
if (this.type === "number")
if (this.type === "number") {
this.description = toStringDescription(object);
// Override "value" property for values that can not be JSON-stringified.
switch (this.description) {
case "NaN":
case "Infinity":
case "-Infinity":
case "-0":
this.value = this.description;
break;
}
}
return;
}
......
......@@ -214,6 +214,10 @@ WebInspector.RemoteObjectImpl = function(target, objectId, type, subtype, value,
console.assert(type !== "object" || value === null);
this._description = description || (value + "");
this._hasChildren = false;
// Handle special numbers: NaN, Infinity, -Infinity, -0.
if (type === "number" && typeof value !== "number")
this.value = Number(value);
else
this.value = value;
}
}
......@@ -385,12 +389,8 @@ WebInspector.RemoteObjectImpl.prototype = {
// where property was defined; so do we.
var setPropertyValueFunction = "function(a, b) { this[a] = b; }";
// Special case for NaN, Infinity, -Infinity, -0.
if (result.type === "number" && String(result.value) !== result.description)
setPropertyValueFunction = "function(a) { this[a] = " + result.description + "; }";
delete result.description; // Optimize on traffic.
this._runtimeAgent.callFunctionOn(this._objectId, setPropertyValueFunction, [{ value:name }, result], true, undefined, undefined, propertySetCallback.bind(this));
var argv = [{ value: name }, this._toCallArgument(result)]
this._runtimeAgent.callFunctionOn(this._objectId, setPropertyValueFunction, argv, true, undefined, undefined, propertySetCallback.bind(this));
/**
* @param {?Protocol.Error} error
......@@ -407,6 +407,15 @@ WebInspector.RemoteObjectImpl.prototype = {
}
},
/**
* @param {!RuntimeAgent.RemoteObject} object
* @return {!RuntimeAgent.CallArgument}
*/
_toCallArgument: function(object)
{
return { value: object.value, objectId: object.objectId, type: /** @type {!RuntimeAgent.CallArgumentType.<string>} */ (object.type) };
},
/**
* @param {function(?DOMAgent.NodeId)} callback
*/
......@@ -645,21 +654,7 @@ WebInspector.ScopeRemoteObject.prototype = {
*/
doSetObjectPropertyValue: function(result, name, callback)
{
var newValue;
switch (result.type) {
case "undefined":
newValue = {};
break;
case "object":
case "function":
newValue = { objectId: result.objectId };
break;
default:
newValue = { value: result.value };
}
this._debuggerAgent.setVariableValue(this._scopeRef.number, name, newValue, this._scopeRef.callFrameId, this._scopeRef.functionId, setVariableValueCallback.bind(this));
this._debuggerAgent.setVariableValue(this._scopeRef.number, name, this._toCallArgument(result), this._scopeRef.callFrameId, this._scopeRef.functionId, setVariableValueCallback.bind(this));
/**
* @param {?Protocol.Error} error
......
......@@ -657,7 +657,7 @@
{ "name": "type", "type": "string", "enum": ["object", "function", "undefined", "string", "number", "boolean"], "description": "Object type." },
{ "name": "subtype", "type": "string", "optional": true, "enum": ["array", "null", "node", "regexp", "date"], "description": "Object subtype hint. Specified for <code>object</code> type values only." },
{ "name": "className", "type": "string", "optional": true, "description": "Object class (constructor) name. Specified for <code>object</code> type values only." },
{ "name": "value", "type": "any", "optional": true, "description": "Remote object value (in case of primitive values or JSON values if it was requested)." },
{ "name": "value", "type": "any", "optional": true, "description": "Remote object value in case of primitive values or JSON values (if it was requested), or description string if the value can not be JSON-stringified (like NaN, Infinity, -Infinity, -0)." },
{ "name": "description", "type": "string", "optional": true, "description": "String representation of the object." },
{ "name": "objectId", "$ref": "RemoteObjectId", "optional": true, "description": "Unique object identifier (for non-primitive values)." },
{ "name": "preview", "$ref": "ObjectPreview", "optional": true, "description": "Preview containing abbreviated property values.", "hidden": true }
......@@ -718,8 +718,9 @@
"type": "object",
"description": "Represents function call argument. Either remote object id <code>objectId</code> or primitive <code>value</code> or neither of (for undefined) them should be specified.",
"properties": [
{ "name": "value", "type": "any", "optional": true, "description": "Primitive value." },
{ "name": "objectId", "$ref": "RemoteObjectId", "optional": true, "description": "Remote object handle." }
{ "name": "value", "type": "any", "optional": true, "description": "Primitive value, or description string if the value can not be JSON-stringified (like NaN, Infinity, -Infinity, -0)." },
{ "name": "objectId", "$ref": "RemoteObjectId", "optional": true, "description": "Remote object handle." },
{ "name": "type", "optional": true, "hidden": true, "type": "string", "enum": ["object", "function", "undefined", "string", "number", "boolean"], "description": "Object type." }
]
},
{
......
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