summaryrefslogtreecommitdiffstats
path: root/WebCore/inspector/front-end/InjectedScript.js
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/inspector/front-end/InjectedScript.js')
-rw-r--r--WebCore/inspector/front-end/InjectedScript.js78
1 files changed, 42 insertions, 36 deletions
diff --git a/WebCore/inspector/front-end/InjectedScript.js b/WebCore/inspector/front-end/InjectedScript.js
index 95867c4..8d8fa88 100644
--- a/WebCore/inspector/front-end/InjectedScript.js
+++ b/WebCore/inspector/front-end/InjectedScript.js
@@ -485,25 +485,30 @@ InjectedScript.getProperties = function(objectProxy, ignoreHasOwnProperty, abbre
var object = InjectedScript._resolveObject(objectProxy);
if (!InjectedScript._isDefined(object))
return false;
-
var properties = [];
+ var propertyNames = ignoreHasOwnProperty ? InjectedScript._getPropertyNames(object) : Object.getOwnPropertyNames(object);
+ if (!ignoreHasOwnProperty && object.__proto__)
+ propertyNames.push("__proto__");
// Go over properties, prepare results.
- for (var propertyName in object) {
- if (!ignoreHasOwnProperty && "hasOwnProperty" in object && !object.hasOwnProperty(propertyName))
- continue;
+ for (var i = 0; i < propertyNames.length; ++i) {
+ var propertyName = propertyNames[i];
var property = {};
- property.name = propertyName;
+ property.name = propertyName + "";
property.parentObjectProxy = objectProxy;
var isGetter = object["__lookupGetter__"] && object.__lookupGetter__(propertyName);
if (!property.isGetter) {
- var childObject = object[propertyName];
- var childObjectProxy = new InjectedScript.createProxyObject(childObject, objectProxy.objectId, abbreviate);
- childObjectProxy.path = objectProxy.path ? objectProxy.path.slice() : [];
- childObjectProxy.path.push(propertyName);
- childObjectProxy.protoDepth = objectProxy.protoDepth || 0;
- property.value = childObjectProxy;
+ try {
+ var childObject = object[propertyName];
+ var childObjectProxy = new InjectedScript.createProxyObject(childObject, objectProxy.objectId, abbreviate);
+ childObjectProxy.path = objectProxy.path ? objectProxy.path.slice() : [];
+ childObjectProxy.path.push(propertyName);
+ property.value = childObjectProxy;
+ } catch(e) {
+ property.value = { description: e.toString() };
+ property.isError = true;
+ }
} else {
// FIXME: this should show something like "getter" (bug 16734).
property.value = { description: "\u2014" }; // em dash
@@ -571,24 +576,25 @@ InjectedScript.setOuterHTML = function(nodeId, value, expanded)
return InjectedScriptHost.pushNodePathToFrontend(newNode, expanded, false);
}
-InjectedScript._getPropertyNames = function(object, resultSet)
+InjectedScript._populatePropertyNames = function(object, resultSet)
{
- if (Object.getOwnPropertyNames) {
- for (var o = object; o; o = o.__proto__) {
- try {
- var names = Object.getOwnPropertyNames(o);
- for (var i = 0; i < names.length; ++i)
- resultSet[names[i]] = true;
- } catch (e) {
- }
+ for (var o = object; o; o = o.__proto__) {
+ try {
+ var names = Object.getOwnPropertyNames(o);
+ for (var i = 0; i < names.length; ++i)
+ resultSet[names[i] + ""] = true;
+ } catch (e) {
}
- } else {
- // Chromium doesn't support getOwnPropertyNames yet.
- for (var name in object)
- resultSet[name] = true;
}
}
+InjectedScript._getPropertyNames = function(object, resultSet)
+{
+ var propertyNameSet = {};
+ InjectedScript._populatePropertyNames(object, propertyNameSet);
+ return Object.keys(propertyNameSet);
+}
+
InjectedScript.getCompletions = function(expression, includeInspectorCommandLineAPI, callFrameId)
{
var props = {};
@@ -605,7 +611,7 @@ InjectedScript.getCompletions = function(expression, includeInspectorCommandLine
// Evaluate into properties in scope of the selected call frame.
var scopeChain = callFrame.scopeChain;
for (var i = 0; i < scopeChain.length; ++i)
- InjectedScript._getPropertyNames(scopeChain[i], props);
+ InjectedScript._populatePropertyNames(scopeChain[i], props);
}
} else {
if (!expression)
@@ -613,7 +619,7 @@ InjectedScript.getCompletions = function(expression, includeInspectorCommandLine
expressionResult = InjectedScript._evaluateOn(InjectedScript._window().eval, InjectedScript._window(), expression);
}
if (typeof expressionResult == "object")
- InjectedScript._getPropertyNames(expressionResult, props);
+ InjectedScript._populatePropertyNames(expressionResult, props);
if (includeInspectorCommandLineAPI)
for (var prop in InjectedScript._window().console._inspectorCommandLineAPI)
if (prop.charAt(0) !== '_')
@@ -677,6 +683,12 @@ InjectedScript.addInspectedNode = function(nodeId)
InjectedScript.performSearch = function(whitespaceTrimmedQuery)
{
+ // FIXME: Few things are missing here:
+ // 1) Search works with node granularity - number of matches within node is not calculated.
+ // 2) Search does not work outside main documents' domain - we need to use specific InjectedScript instances
+ // for other domains.
+ // 3) There is no need to push all search results to the front-end at a time, pushing next / previous result
+ // is sufficient.
var tagNameQuery = whitespaceTrimmedQuery;
var attributeNameQuery = whitespaceTrimmedQuery;
var startTagFound = (tagNameQuery.indexOf("<") === 0);
@@ -1073,10 +1085,6 @@ InjectedScript._resolveObject = function(objectProxy)
for (var i = 0; InjectedScript._isDefined(object) && path && i < path.length; ++i)
object = object[path[i]];
- // Get to the necessary proto layer.
- for (var i = 0; InjectedScript._isDefined(object) && protoDepth && i < protoDepth; ++i)
- object = object.__proto__;
-
return object;
}
@@ -1136,14 +1144,12 @@ InjectedScript.createProxyObject = function(object, objectId, abbreviate)
result.injectedScriptId = injectedScriptId;
result.objectId = objectId;
result.type = InjectedScript._type(object);
+ if (result.type === "array")
+ result.propertyLength = object.length;
var type = typeof object;
- if ((type === "object" && object !== null) || type === "function") {
- for (var subPropertyName in object) {
- result.hasChildren = true;
- break;
- }
- }
+
+ result.hasChildren = (type === "object" && object !== null && (Object.getOwnPropertyNames(object).length || object.__proto__)) || type === "function";
try {
result.description = InjectedScript._describe(object, abbreviate);
} catch (e) {