Commit 703a517d authored by eric@webkit.org's avatar eric@webkit.org

2009-09-17 Yury Semikhatsky <yurys@chromium.org>

        Reviewed by Timothy Hatcher.

        Wrap primitive values (as objects) in InspectorController::wrap.

        https://bugs.webkit.org/show_bug.cgi?id=28983

        * inspector/InspectorController.cpp:
        (WebCore::InspectorController::wrapObject): objects of any type will be wrapped into proxies,
         only object proxies will have objectId.
        * inspector/front-end/ConsoleView.js:
        (WebInspector.ConsoleView.prototype.completions): there is InjectedScript.getCompletionsi
         that accepts an expression and returns possible completions. This way we don't need to wrap
         and unwrap the completions result into a proxy object.
        * inspector/front-end/InjectedScript.js:
        (InjectedScript.getCompletions):
        (InjectedScript.evaluate):
        (InjectedScript._evaluateOn):
        (InjectedScript.createProxyObject):
        * inspector/front-end/InjectedScriptAccess.js:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48491 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4404a525
2009-09-17 Yury Semikhatsky <yurys@chromium.org>
Reviewed by Timothy Hatcher.
Wrap primitive values (as objects) in InspectorController::wrap.
https://bugs.webkit.org/show_bug.cgi?id=28983
* inspector/InspectorController.cpp:
(WebCore::InspectorController::wrapObject): objects of any type will be wrapped into proxies,
only object proxies will have objectId.
* inspector/front-end/ConsoleView.js:
(WebInspector.ConsoleView.prototype.completions): there is InjectedScript.getCompletionsi
that accepts an expression and returns possible completions. This way we don't need to wrap
and unwrap the completions result into a proxy object.
* inspector/front-end/InjectedScript.js:
(InjectedScript.getCompletions):
(InjectedScript.evaluate):
(InjectedScript._evaluateOn):
(InjectedScript.createProxyObject):
* inspector/front-end/InjectedScriptAccess.js:
2009-09-17 Nate Chapin <japhet@chromium.org>
Reviewed by Dimitri Glazkov.
......@@ -1531,18 +1531,17 @@ InspectorController::SpecialPanels InspectorController::specialPanelForJSName(co
ScriptValue InspectorController::wrapObject(const ScriptValue& quarantinedObject)
{
ScriptFunctionCall function(m_scriptState, m_injectedScriptObj, "createProxyObject");
function.appendArgument(quarantinedObject);
if (quarantinedObject.isObject()) {
long id = m_lastBoundObjectId++;
String objectId = String::format("object#%ld", id);
m_idToConsoleObject.set(objectId, quarantinedObject);
ScriptFunctionCall function(m_scriptState, m_injectedScriptObj, "createProxyObject");
function.appendArgument(quarantinedObject);
function.appendArgument(objectId);
ScriptValue wrapper = function.call();
return wrapper;
}
return quarantinedObject;
ScriptValue wrapper = function.call();
return wrapper;
}
ScriptValue InspectorController::unwrapObject(const String& objectId)
......
......@@ -291,24 +291,8 @@ WebInspector.ConsoleView.prototype = {
}
}
function parsingCallback(result, isException)
{
if (!isException)
result = JSON.parse(result);
reportCompletions(result, isException);
}
this.evalInInspectedWindow(
"(function() {" +
"var props = {};" +
"for (var prop in (" + expressionString + ")) props[prop] = true;" +
((!dotNotation && !bracketNotation) ?
"for (var prop in window._inspectorCommandLineAPI)" +
"if (prop.charAt(0) !== '_') props[prop] = true;"
: "") +
"return JSON.stringify(props);" +
"})()",
parsingCallback);
var includeInspectorCommandLineAPI = (!dotNotation && !bracketNotation);
InjectedScriptAccess.getCompletions(expressionString, includeInspectorCommandLineAPI, reportCompletions);
},
_reportCompletions: function(bestMatchOnly, completionsReadyCallback, dotNotation, bracketNotation, prefix, result, isException) {
......
......@@ -498,21 +498,29 @@ InjectedScript.setPropertyValue = function(objectProxy, propertyName, expression
}
}
InjectedScript.evaluate = function(expression)
InjectedScript.getCompletions = function(expression, includeInspectorCommandLineAPI)
{
return InjectedScript._evaluateOn(InjectedScript._window().eval, InjectedScript._window(), expression);
var props = {};
try {
var expressionResult = InjectedScript._evaluateOn(InjectedScript._window().eval, InjectedScript._window(), expression);
for (var prop in expressionResult)
props[prop] = true;
if (includeInspectorCommandLineAPI)
for (var prop in InjectedScript._window()._inspectorCommandLineAPI)
if (prop.charAt(0) !== '_')
props[prop] = true;
} catch(e) {
}
return props;
}
InjectedScript._evaluateOn = function(evalFunction, object, expression)
{
InjectedScript._ensureCommandLineAPIInstalled();
// Surround the expression in with statements to inject our command line API so that
// the window object properties still take more precedent than our API functions.
expression = "with (window._inspectorCommandLineAPI) { with (window) { " + expression + " } }";
InjectedScript.evaluate = function(expression)
{
var result = {};
try {
var value = evalFunction.call(object, expression);
var value = InjectedScript._evaluateOn(InjectedScript._window().eval, InjectedScript._window(), expression);
if (value === null)
return { value: null };
if (Object.type(value) === "error") {
......@@ -535,6 +543,15 @@ InjectedScript._evaluateOn = function(evalFunction, object, expression)
return result;
}
InjectedScript._evaluateOn = function(evalFunction, object, expression)
{
InjectedScript._ensureCommandLineAPIInstalled();
// Surround the expression in with statements to inject our command line API so that
// the window object properties still take more precedent than our API functions.
expression = "with (window._inspectorCommandLineAPI) { with (window) { " + expression + " } }";
return evalFunction.call(object, expression);
}
InjectedScript.addInspectedNode = function(nodeId)
{
var node = InjectedScript._nodeForId(nodeId);
......@@ -950,7 +967,7 @@ InjectedScript.createProxyObject = function(object, objectId, abbreviate)
result.type = Object.type(object);
var type = typeof object;
if (type === "object" || type === "function") {
if ((type === "object" && object !== null) || type === "function") {
for (var subPropertyName in object) {
result.hasChildren = true;
break;
......
......@@ -63,6 +63,7 @@ InjectedScriptAccess._installHandler("setStyleProperty");
InjectedScriptAccess._installHandler("getPrototypes");
InjectedScriptAccess._installHandler("getProperties");
InjectedScriptAccess._installHandler("setPropertyValue");
InjectedScriptAccess._installHandler("getCompletions");
InjectedScriptAccess._installHandler("evaluate");
InjectedScriptAccess._installHandler("addInspectedNode");
InjectedScriptAccess._installHandler("pushNodeToFrontend");
......
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