Changeset 92471 in webkit


Ignore:
Timestamp:
Aug 5, 2011 2:37:02 AM (13 years ago)
Author:
yurys@chromium.org
Message:

Web Inspector: constrain maximum depth for returnByValue objects
https://bugs.webkit.org/show_bug.cgi?id=65761

Source/WebCore:

Set maximum depth to 20 for objects returned by value as a result of evaluations.

Reviewed by Pavel Feldman.

  • bindings/js/ScriptValue.cpp:

(WebCore::jsToInspectorValue):
(WebCore::ScriptValue::toInspectorValue):

  • bindings/v8/ScriptValue.cpp:

(WebCore::v8ToInspectorValue):
(WebCore::ScriptValue::toInspectorValue):

  • inspector/InjectedScript.cpp:

(WebCore::InjectedScript::makeCall):

  • inspector/InspectorValues.h:

LayoutTests:

Reviewed by Pavel Feldman.

  • inspector/protocol/runtime-agent-expected.txt:
  • inspector/protocol/runtime-agent.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r92470 r92471  
     12011-08-05  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: constrain maximum depth for returnByValue objects
     4        https://bugs.webkit.org/show_bug.cgi?id=65761
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/protocol/runtime-agent-expected.txt:
     9        * inspector/protocol/runtime-agent.html:
     10
    1112011-08-05  Zoltan Horvath  <zoltan@webkit.org>
    212
  • trunk/LayoutTests/inspector/protocol/runtime-agent-expected.txt

    r91750 r92471  
    7474            value : "callFunctionOn function works fine"
    7575        }
     76    }
     77    id : <number>
     78}
     79
     80-----------------------------------------------------------
     81RuntimeAgent.evaluate("var o = {n:2011, b:true, s:\"a string\", o:{n:2011}}; o","test",false,true,null,true)
     82
     83request:
     84{
     85    method : "Runtime.evaluate"
     86    params : {
     87        expression : "var o = {n:2011, b:true, s:"a string", o:{n:2011}}; o"
     88        objectGroup : "test"
     89        includeCommandLineAPI : false
     90        doNotPauseOnExceptions : true
     91        returnByValue : true
     92    }
     93    id : <number>
     94}
     95
     96response:
     97{
     98    result : {
     99        result : {
     100            type : "object"
     101            value : {
     102                n : 2011
     103                b : true
     104                s : "a string"
     105                o : {
     106                    n : 2011
     107                }
     108            }
     109        }
     110    }
     111    id : <number>
     112}
     113
     114-----------------------------------------------------------
     115RuntimeAgent.evaluate("var x = {}; x.self = x; x","test",false,true,null,true)
     116
     117request:
     118{
     119    method : "Runtime.evaluate"
     120    params : {
     121        expression : "var x = {}; x.self = x; x"
     122        objectGroup : "test"
     123        includeCommandLineAPI : false
     124        doNotPauseOnExceptions : true
     125        returnByValue : true
     126    }
     127    id : <number>
     128}
     129
     130response:
     131{
     132    error : {
     133        code : -32000
     134        message : "Object has too long reference chain(must not be longer than 1000)"
     135    }
     136    id : <number>
     137}
     138
     139-----------------------------------------------------------
     140RuntimeAgent.callFunctionOn(<string>,"function() { this.self = this; return this; }",null,true)
     141
     142request:
     143{
     144    method : "Runtime.callFunctionOn"
     145    params : {
     146        objectId : <string>
     147        functionDeclaration : "function() { this.self = this; return this; }"
     148        returnByValue : true
     149    }
     150    id : <number>
     151}
     152
     153response:
     154{
     155    error : {
     156        code : -32000
     157        message : "Object has too long reference chain(must not be longer than 1000)"
    76158    }
    77159    id : <number>
     
    100182                    type : "string"
    101183                    value : "callFunctionOn function works fine"
     184                }
     185            }
     186            {
     187                name : "self"
     188                value : {
     189                    type : "object"
     190                    objectId : <string>
     191                    className : <string>
     192                    description : "TestObject"
    102193                }
    103194            }
  • trunk/LayoutTests/inspector/protocol/runtime-agent.html

    r91750 r92471  
    2121            ["RuntimeAgent", "evaluate", 'testObject', 'test'],
    2222            ["RuntimeAgent", "callFunctionOn", result.objectId, 'function() { this.assignedByCallFunctionOn = "callFunctionOn function works fine"; return this.assignedByCallFunctionOn; }'],
     23
     24            // test returnByValue:
     25            ["RuntimeAgent", "evaluate", 'var o = {n:2011, b:true, s:"a string", o:{n:2011}}; o', 'test', false, true, undefined, true],
     26            ["RuntimeAgent", "evaluate", 'var x = {}; x.self = x; x', 'test', false, true, undefined, true],
     27            ["RuntimeAgent", "callFunctionOn", result.objectId, 'function() { this.self = this; return this; }', undefined, true],
     28
    2329            ["RuntimeAgent", "getProperties", result.objectId, false],
    2430            ["RuntimeAgent", "releaseObject", result.objectId],
  • trunk/Source/WebCore/ChangeLog

    r92469 r92471  
     12011-08-05  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: constrain maximum depth for returnByValue objects
     4        https://bugs.webkit.org/show_bug.cgi?id=65761
     5
     6        Set maximum depth to 20 for objects returned by value as a result of evaluations.
     7
     8        Reviewed by Pavel Feldman.
     9
     10        * bindings/js/ScriptValue.cpp:
     11        (WebCore::jsToInspectorValue):
     12        (WebCore::ScriptValue::toInspectorValue):
     13        * bindings/v8/ScriptValue.cpp:
     14        (WebCore::v8ToInspectorValue):
     15        (WebCore::ScriptValue::toInspectorValue):
     16        * inspector/InjectedScript.cpp:
     17        (WebCore::InjectedScript::makeCall):
     18        * inspector/InspectorValues.h:
     19
    1202011-08-05  Mark Pilgrim  <pilgrim@chromium.org>
    221
  • trunk/Source/WebCore/bindings/js/ScriptValue.cpp

    r83645 r92471  
    112112
    113113#if ENABLE(INSPECTOR)
    114 static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value)
     114static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value, int maxDepth)
    115115{
    116116    if (!value) {
     
    118118        return 0;
    119119    }
     120
     121    if (!maxDepth)
     122        return 0;
     123    maxDepth--;
     124
    120125    if (value.isNull() || value.isUndefined())
    121126        return InspectorValue::null();
     
    135140            for (unsigned i = 0; i < length; i++) {
    136141                JSValue element = array->getIndex(i);
    137                 RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element);
    138                 if (!elementValue) {
    139                     ASSERT_NOT_REACHED();
    140                     elementValue = InspectorValue::null();
    141                 }
     142                RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element, maxDepth);
     143                if (!elementValue)
     144                    return 0;
    142145                inspectorArray->pushValue(elementValue);
    143146            }
     
    151154            const Identifier& name =  propertyNames[i];
    152155            JSValue propertyValue = object->get(scriptState, name);
    153             RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue);
    154             if (!inspectorValue) {
    155                 ASSERT_NOT_REACHED();
    156                 inspectorValue = InspectorValue::null();
    157             }
     156            RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue, maxDepth);
     157            if (!inspectorValue)
     158                return 0;
    158159            inspectorObject->setValue(String(name.characters(), name.length()), inspectorValue);
    159160        }
     
    166167PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ScriptState* scriptState) const
    167168{
    168     return jsToInspectorValue(scriptState, m_value.get());
     169    return jsToInspectorValue(scriptState, m_value.get(), InspectorValue::maxDepth);
    169170}
    170171#endif // ENABLE(INSPECTOR)
  • trunk/Source/WebCore/bindings/v8/ScriptValue.cpp

    r82664 r92471  
    7474
    7575#if ENABLE(INSPECTOR)
    76 static PassRefPtr<InspectorValue> v8ToInspectorValue(v8::Handle<v8::Value> value)
     76static PassRefPtr<InspectorValue> v8ToInspectorValue(v8::Handle<v8::Value> value, int maxDepth)
    7777{
    7878    if (value.IsEmpty()) {
     
    8080        return 0;
    8181    }
     82
     83    if (!maxDepth)
     84        return 0;
     85    maxDepth--;
     86
    8287    if (value->IsNull() || value->IsUndefined())
    8388        return InspectorValue::null();
     
    9499        for (uint32_t i = 0; i < length; i++) {
    95100            v8::Local<v8::Value> value = array->Get(v8::Int32::New(i));
    96             RefPtr<InspectorValue> element = v8ToInspectorValue(value);
    97             if (!element) {
    98                 ASSERT_NOT_REACHED();
    99                 element = InspectorValue::null();
    100             }
     101            RefPtr<InspectorValue> element = v8ToInspectorValue(value, maxDepth);
     102            if (!element)
     103                return 0;
    101104            inspectorArray->pushValue(element);
    102105        }
     
    113116            if (name->IsString() && !object->HasRealNamedProperty(v8::Handle<v8::String>::Cast(name)))
    114117                continue;
    115             RefPtr<InspectorValue> propertyValue = v8ToInspectorValue(object->Get(name));
    116             if (!propertyValue) {
    117                 ASSERT_NOT_REACHED();
    118                 continue;
    119             }
     118            RefPtr<InspectorValue> propertyValue = v8ToInspectorValue(object->Get(name), maxDepth);
     119            if (!propertyValue)
     120                return 0;
    120121            inspectorObject->setValue(toWebCoreStringWithNullCheck(name), propertyValue);
    121122        }
     
    131132    // v8::Object::GetPropertyNames() expects current context to be not null.
    132133    v8::Context::Scope contextScope(scriptState->context());
    133     return v8ToInspectorValue(m_value);
     134    return v8ToInspectorValue(m_value, InspectorValue::maxDepth);
    134135}
    135136#endif
  • trunk/Source/WebCore/inspector/InjectedScript.cpp

    r92377 r92471  
    193193
    194194    ASSERT(!hadException);
    195     if (!hadException)
     195    if (!hadException) {
    196196        *result = resultValue.toInspectorValue(m_injectedScriptObject.scriptState());
    197     else
     197        if (!*result)
     198            *result = InspectorString::create(String::format("Object has too long reference chain(must not be longer than %d)", InspectorValue::maxDepth));
     199    } else
    198200        *result = InspectorString::create("Exception while making a call.");
    199201}
  • trunk/Source/WebCore/inspector/InspectorValues.h

    r77489 r92471  
    4949class InspectorValue : public RefCounted<InspectorValue> {
    5050public:
     51    static const int maxDepth = 1000;
     52
    5153    InspectorValue() : m_type(TypeNull) { }
    5254    virtual ~InspectorValue() { }
Note: See TracChangeset for help on using the changeset viewer.