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

Unified Diff: Source/core/inspector/InjectedScriptSource.js

Issue 83383002: DevTools: Allow setting -0 value to object property (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month 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: Source/core/inspector/InjectedScriptSource.js
diff --git a/Source/core/inspector/InjectedScriptSource.js b/Source/core/inspector/InjectedScriptSource.js
index 1ddcd7f02828f4d93aa8bf90d6c3c868f0905eba..449ddc9c93c51df8e822a70677855d0a03f9aaae 100644
--- a/Source/core/inspector/InjectedScriptSource.js
+++ b/Source/core/inspector/InjectedScriptSource.js
@@ -93,7 +93,7 @@ var InjectedScript = function()
{
/** @type {number} */
this._lastBoundObjectId = 1;
- /** @type {!Object.<number, Object>} */
+ /** @type {!Object.<number, *>} */
this._idToWrappedObject = {};
/** @type {!Object.<number, string>} */
this._idToObjectGroupName = {};
@@ -135,7 +135,7 @@ InjectedScript.prototype = {
wrapObject: function(object, groupName, canAccessInspectedWindow, generatePreview)
{
if (canAccessInspectedWindow)
- return this._wrapObject(object, groupName, false, generatePreview);
+ return this._wrapObject(object, groupName, false, false, generatePreview);
return this._fallbackWrapper(object);
},
@@ -172,7 +172,7 @@ InjectedScript.prototype = {
for (var i = 0; i < columns.length; ++i)
columnNames.push(toString(columns[i]));
}
- return this._wrapObject(table, "console", false, true, columnNames, true);
+ return this._wrapObject(table, "console", false, false, true, columnNames, true);
},
/**
@@ -216,16 +216,17 @@ InjectedScript.prototype = {
* @param {*} object
* @param {string=} objectGroupName
* @param {boolean=} forceValueType
+ * @param {boolean=} forceObjectId
* @param {boolean=} generatePreview
* @param {?Array.<string>=} columnNames
* @param {boolean=} isTable
* @return {!RuntimeAgent.RemoteObject}
* @suppress {checkTypes}
*/
- _wrapObject: function(object, objectGroupName, forceValueType, generatePreview, columnNames, isTable)
+ _wrapObject: function(object, objectGroupName, forceValueType, forceObjectId, generatePreview, columnNames, isTable)
{
try {
- return new InjectedScript.RemoteObject(object, objectGroupName, forceValueType, generatePreview, columnNames, isTable);
+ return new InjectedScript.RemoteObject(object, objectGroupName, forceValueType, forceObjectId, generatePreview, columnNames, isTable);
} catch (e) {
try {
var description = injectedScript._describe(e);
@@ -237,7 +238,7 @@ InjectedScript.prototype = {
},
/**
- * @param {Object} object
+ * @param {*} object
* @param {string=} objectGroupName
* @return {string}
*/
@@ -260,7 +261,7 @@ InjectedScript.prototype = {
/**
* @param {string} objectId
- * @return {Object}
+ * @return {{injectedScriptId: number, id: number}}
*/
_parseObjectId: function(objectId)
{
@@ -305,12 +306,12 @@ InjectedScript.prototype = {
getProperties: function(objectId, ownProperties, accessorPropertiesOnly)
{
var parsedObjectId = this._parseObjectId(objectId);
- var object = this._objectForId(parsedObjectId);
+ var object = this._objectForId(parsedObjectId.id);
var objectGroupName = this._idToObjectGroupName[parsedObjectId.id];
if (!this._isDefined(object))
return false;
- var descriptors = this._propertyDescriptors(object, ownProperties, accessorPropertiesOnly);
+ var descriptors = this._propertyDescriptors(/** @type {!Object} */ (object), ownProperties, accessorPropertiesOnly);
// Go over properties, wrap object values.
for (var i = 0; i < descriptors.length; ++i) {
@@ -336,7 +337,7 @@ InjectedScript.prototype = {
getInternalProperties: function(objectId, ownProperties)
{
var parsedObjectId = this._parseObjectId(objectId);
- var object = this._objectForId(parsedObjectId);
+ var object = this._objectForId(parsedObjectId.id);
var objectGroupName = this._idToObjectGroupName[parsedObjectId.id];
if (!this._isDefined(object))
return false;
@@ -362,7 +363,7 @@ InjectedScript.prototype = {
getFunctionDetails: function(functionId)
{
var parsedFunctionId = this._parseObjectId(functionId);
- var func = this._objectForId(parsedFunctionId);
+ var func = this._objectForId(parsedFunctionId.id);
if (typeof func !== "function")
return "Cannot resolve function by id.";
var details = InjectedScriptHost.functionDetails(func);
@@ -473,24 +474,26 @@ InjectedScript.prototype = {
* @param {string} objectGroup
* @param {boolean} injectCommandLineAPI
* @param {boolean} returnByValue
+ * @param {boolean} forceObjectId
* @param {boolean} generatePreview
* @return {*}
*/
- evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview)
+ evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByValue, forceObjectId, generatePreview)
{
- return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, generatePreview);
+ return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, forceObjectId, generatePreview);
},
/**
* @param {string} objectId
* @param {string} expression
* @param {boolean} returnByValue
+ * @param {boolean} forceObjectId
* @return {Object|string}
*/
- callFunctionOn: function(objectId, expression, args, returnByValue)
+ callFunctionOn: function(objectId, expression, args, returnByValue, forceObjectId)
{
var parsedObjectId = this._parseObjectId(objectId);
- var object = this._objectForId(parsedObjectId);
+ var object = this._objectForId(parsedObjectId.id);
if (!this._isDefined(object))
return "Could not find object with given id";
@@ -515,7 +518,7 @@ InjectedScript.prototype = {
return "Given expression does not evaluate to a function";
return { wasThrown: false,
- result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue) };
+ result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue, forceObjectId) };
} catch (e) {
return this._createThrownValue(e, objectGroup);
}
@@ -531,18 +534,15 @@ InjectedScript.prototype = {
var objectId = callArgumentJson.objectId;
if (objectId) {
var parsedArgId = this._parseObjectId(objectId);
- if (!parsedArgId || parsedArgId["injectedScriptId"] !== injectedScriptId)
+ if (!parsedArgId || parsedArgId.injectedScriptId !== injectedScriptId)
throw "Arguments should belong to the same JavaScript world as the target object.";
-
- var resolvedArg = this._objectForId(parsedArgId);
- if (!this._isDefined(resolvedArg))
+ if (!this._hasObjectForId(parsedArgId.id))
throw "Could not find object with given id";
-
- return resolvedArg;
- } else if ("value" in callArgumentJson)
+ return this._objectForId(parsedArgId.id);
+ } else if ("value" in callArgumentJson) {
return callArgumentJson.value;
- else
- return undefined;
+ }
+ return undefined;
},
/**
@@ -552,14 +552,15 @@ InjectedScript.prototype = {
* @param {boolean} isEvalOnCallFrame
* @param {boolean} injectCommandLineAPI
* @param {boolean} returnByValue
+ * @param {boolean} forceObjectId
* @param {boolean} generatePreview
* @return {*}
*/
- _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, isEvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview)
+ _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, isEvalOnCallFrame, injectCommandLineAPI, returnByValue, forceObjectId, generatePreview)
{
try {
return { wasThrown: false,
- result: this._wrapObject(this._evaluateOn(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI), objectGroup, returnByValue, generatePreview) };
+ result: this._wrapObject(this._evaluateOn(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI), objectGroup, returnByValue, forceObjectId, generatePreview) };
} catch (e) {
return this._createThrownValue(e, objectGroup);
}
@@ -635,15 +636,16 @@ InjectedScript.prototype = {
* @param {string} objectGroup
* @param {boolean} injectCommandLineAPI
* @param {boolean} returnByValue
+ * @param {boolean} forceObjectId
* @param {boolean} generatePreview
* @return {*}
*/
- evaluateOnCallFrame: function(topCallFrame, callFrameId, expression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview)
+ evaluateOnCallFrame: function(topCallFrame, callFrameId, expression, objectGroup, injectCommandLineAPI, returnByValue, forceObjectId, generatePreview)
{
var callFrame = this.callFrameForId(topCallFrame, callFrameId);
if (!callFrame)
return "Could not find call frame with given id";
- return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview);
+ return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, forceObjectId, generatePreview);
},
/**
@@ -698,7 +700,7 @@ InjectedScript.prototype = {
setter = callFrame.setVariableValue.bind(callFrame);
} else {
var parsedFunctionId = this._parseObjectId(/** @type {string} */ (functionObjectId));
- var func = this._objectForId(parsedFunctionId);
+ var func = this._objectForId(parsedFunctionId.id);
if (typeof func !== "function")
return "Cannot resolve function by id.";
setter = InjectedScriptHost.setFunctionVariableValue.bind(InjectedScriptHost, func);
@@ -739,22 +741,31 @@ InjectedScript.prototype = {
},
/**
- * @param {Object} objectId
- * @return {Object}
+ * @param {number} objectId
+ * @return {*}
*/
_objectForId: function(objectId)
{
- return this._idToWrappedObject[objectId.id];
+ return this._idToWrappedObject[objectId];
+ },
+
+ /**
+ * @param {number} objectId
+ * @return {boolean}
+ */
+ _hasObjectForId: function(objectId)
+ {
+ return (objectId in this._idToWrappedObject);
},
/**
* @param {string} objectId
- * @return {Object}
+ * @return {*}
*/
findObjectById: function(objectId)
{
var parsedObjectId = this._parseObjectId(objectId);
- return this._objectForId(parsedObjectId);
+ return this._objectForId(parsedObjectId.id);
},
/**
@@ -802,7 +813,7 @@ InjectedScript.prototype = {
*/
_isDefined: function(object)
{
- return !!object || this._isHTMLAllCollection(object);
+ return (!!object && !InjectedScript.primitiveTypes[typeof object]) || this._isHTMLAllCollection(object);
},
/**
@@ -913,11 +924,12 @@ var injectedScript = new InjectedScript();
* @param {*} object
* @param {string=} objectGroupName
* @param {boolean=} forceValueType
+ * @param {boolean=} forceObjectId
* @param {boolean=} generatePreview
* @param {?Array.<string>=} columnNames
* @param {boolean=} isTable
*/
-InjectedScript.RemoteObject = function(object, objectGroupName, forceValueType, generatePreview, columnNames, isTable)
+InjectedScript.RemoteObject = function(object, objectGroupName, forceValueType, forceObjectId, generatePreview, columnNames, isTable)
{
this.type = typeof object;
if (injectedScript.isPrimitiveValue(object) || object === null || forceValueType) {
@@ -932,6 +944,9 @@ InjectedScript.RemoteObject = function(object, objectGroupName, forceValueType,
// Provide user-friendly number values.
if (this.type === "number")
this.description = toString(object);
+
+ if (forceObjectId)
+ this.objectId = injectedScript._bind(object, objectGroupName);
return;
}

Powered by Google App Engine
This is Rietveld 408576698