Changeset 56877 in webkit


Ignore:
Timestamp:
Mar 31, 2010 5:09:55 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-03-31 Vitaly Repeshko <vitalyr@chromium.org>

Reviewed by David Levin.

[V8] SerializedScriptValue must be deserialized only once and in the right context
https://bugs.webkit.org/show_bug.cgi?id=36892

See also https://bugs.webkit.org/show_bug.cgi?id=34227 for the
corresponding JSC change.

General idea: SerializedScriptValue must be deserialized only once
and in the context of the intended MessageEvent recepient. The
approach we take for now is to eagerly deserialize when a
JavaScript wrapper for MessageEvent is created.

A better fix would be to keep a reference to the context in
MessageEvent and use it when lazily deserializing. It's harder to
do since the API doesn't have a clean method to have such a reference.

Tested by fast/dom/Window/window-postmessage-clone-frames.html. This
test still fails but only for the types which we can't serialize yet.

  • bindings/scripts/CodeGeneratorV8.pm:
  • bindings/v8/SerializedScriptValue.h: (WebCore::SerializedScriptValue::deserializeAndSetProperty):
  • bindings/v8/custom/V8MessageEventCustom.cpp: (WebCore::V8MessageEvent::initMessageEventCallback):
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56875 r56877  
     12010-03-31  Vitaly Repeshko  <vitalyr@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        [V8] SerializedScriptValue must be deserialized only once and in the right context
     6        https://bugs.webkit.org/show_bug.cgi?id=36892
     7
     8        See also https://bugs.webkit.org/show_bug.cgi?id=34227 for the
     9        corresponding JSC change.
     10
     11        General idea: SerializedScriptValue must be deserialized only once
     12        and in the context of the intended MessageEvent recepient. The
     13        approach we take for now is to eagerly deserialize when a
     14        JavaScript wrapper for MessageEvent is created.
     15
     16        A better fix would be to keep a reference to the context in
     17        MessageEvent and use it when lazily deserializing. It's harder to
     18        do since the API doesn't have a clean method to have such a reference.
     19
     20        Tested by fast/dom/Window/window-postmessage-clone-frames.html. This
     21        test still fails but only for the types which we can't serialize yet.
     22
     23        * bindings/scripts/CodeGeneratorV8.pm:
     24        * bindings/v8/SerializedScriptValue.h:
     25        (WebCore::SerializedScriptValue::deserializeAndSetProperty):
     26        * bindings/v8/custom/V8MessageEventCustom.cpp:
     27        (WebCore::V8MessageEvent::initMessageEventCallback):
     28
    1292010-03-31  Adam Barth  <abarth@webkit.org>
    230
  • trunk/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r56849 r56877  
    11421142    my $attrExt = $attribute->signature->extendedAttributes;
    11431143
     1144    # Attributes of type SerializedScriptValue are set in the
     1145    # constructor and don't require callbacks.
     1146    return if ($attribute->signature->type eq "SerializedScriptValue");
     1147
    11441148    my $accessControl = "v8::DEFAULT";
    11451149    if ($attrExt->{"DoNotCheckDomainSecurityOnGet"}) {
     
    14681472
    14691473    my $hasConstructors = 0;
     1474    my $serializedAttribute;
    14701475    # Generate property accessors for attributes.
    14711476    for ($index = 0; $index < @{$dataNode->attributes}; $index++) {
     
    14851490        if ($attrType eq "EventListener" && $interfaceName eq "DOMWindow") {
    14861491            $attribute->signature->extendedAttributes->{"v8OnProto"} = 1;
     1492        }
     1493
     1494        # Attributes of type SerializedScriptValue are set in the
     1495        # constructor and don't require callbacks.
     1496        if ($attrType eq "SerializedScriptValue") {
     1497            die "Only one attribute of type SerializedScriptValue supported" if $serializedAttribute;
     1498            $implIncludes{"SerializedScriptValue.h"} = 1;
     1499            $serializedAttribute = $attribute;
     1500            next;
    14871501        }
    14881502
     
    19121926    }
    19131927
    1914     GenerateToV8Converters($dataNode, $interfaceName, $className, $nativeType);
     1928    GenerateToV8Converters($dataNode, $interfaceName, $className, $nativeType, $serializedAttribute);
    19151929
    19161930    push(@implContent, <<END);
     
    19411955    my $className = shift;
    19421956    my $nativeType = shift;
     1957    my $serializedAttribute = shift;
    19431958
    19441959    my $domMapFunction = GetDomMapFunction($dataNode, $interfaceName);
     
    19942009    wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl);
    19952010END
    1996 
    19972011    if (IsNodeSubType($dataNode)) {
    19982012        push(@implContent, <<END);
     
    20082022END
    20092023    push(@implContent, "\n    impl->ref();\n") if IsRefPtrType($interfaceName);
     2024
     2025    # Eagerly deserialize attributes of type SerializedScriptValue
     2026    # while we're in the right context.
     2027    if ($serializedAttribute) {
     2028        die "Attribute of type SerializedScriptValue expected" if $serializedAttribute->signature->type ne "SerializedScriptValue";
     2029        my $attrName = $serializedAttribute->signature->name;
     2030        my $attrAttr = "v8::DontDelete";
     2031        if ($serializedAttribute->type =~ /^readonly/) {
     2032            $attrAttr .= " | v8::ReadOnly";
     2033        }
     2034        $attrAttr = "static_cast<v8::PropertyAttribute>($attrAttr)";
     2035        my $getterFunc = $codeGenerator->WK_lcfirst($attrName);
     2036        push(@implContent, <<END);
     2037    SerializedScriptValue::deserializeAndSetProperty(wrapper, "${attrName}", ${attrAttr}, impl->${getterFunc}());
     2038END
     2039    }
    20102040
    20112041    if ($domMapFunction) {
  • trunk/WebCore/bindings/v8/SerializedScriptValue.h

    r56070 r56877  
    4141class SerializedScriptValue : public RefCounted<SerializedScriptValue> {
    4242public:
     43    // Deserializes the given value and sets it as a property on the
     44    // object.
     45    static void deserializeAndSetProperty(v8::Handle<v8::Object> object,
     46                                          const char* propertyName,
     47                                          v8::PropertyAttribute attribute,
     48                                          SerializedScriptValue* value)
     49    {
     50        ASSERT(value);
     51        v8::Handle<v8::Value> deserialized = value->deserialize();
     52        object->ForceSet(v8::String::NewSymbol(propertyName), deserialized, attribute);
     53    }
     54
    4355    // Creates a serialized representation of the given V8 value.
    4456    static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value> value)
  • trunk/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp

    r54629 r56877  
    8585    }
    8686    event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, dataArg.release(), originArg, lastEventIdArg, sourceArg, portArray.release());
     87    v8::PropertyAttribute dataAttr = static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly);
     88    SerializedScriptValue::deserializeAndSetProperty(args.Holder(), "data", dataAttr, event->data());
    8789    return v8::Undefined();
    8890  }
Note: See TracChangeset for help on using the changeset viewer.