Changeset 218511 in webkit


Ignore:
Timestamp:
Jun 19, 2017 2:55:00 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[WebIDL] Add support for serializers that have members that are themselves serializers (or inherit being a serializer from a parent)
https://bugs.webkit.org/show_bug.cgi?id=173395

Patch by Sam Weinig <sam@webkit.org> on 2017-06-19
Reviewed by Simon Fraser.

Source/WebCore:

Test: fast/css/DOMQuad-serialization.html

  • bindings/scripts/CodeGenerator.pm:

(InheritsSerializable):
Helper to determine if an interface inherits from any interfaces
that are serializable. This is necessary because an attribute is
serializable even if its interface is not marked as serializable.

(IsSerializableAttribute):
Check ancestor interfaces as well to determine serializability.

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateSerializerDefinition):
Specialize attributes that are serializable interfaces to call its interfaces
serialize function, thus allowing nested objects to be serialized.

  • dom/DOMQuad.idl:

Add serializer.

  • bindings/scripts/test/JS/JSTestSerialization.cpp:
  • bindings/scripts/test/JS/JSTestSerializationIndirectInheritance.cpp: Added.
  • bindings/scripts/test/JS/JSTestSerializationIndirectInheritance.h: Added.
  • bindings/scripts/test/TestSerialization.idl:
  • bindings/scripts/test/TestSerializationIndirectInheritance.idl: Added.

Add and update tests.

LayoutTests:

  • fast/css/DOMQuad-serialization-expected.txt: Added.
  • fast/css/DOMQuad-serialization.html: Added.

Add test for DOMQuad serialization, now that it is supported.

Location:
trunk
Files:
4 added
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r218510 r218511  
     12017-06-19  Sam Weinig  <sam@webkit.org>
     2
     3        [WebIDL] Add support for serializers that have members that are themselves serializers (or inherit being a serializer from a parent)
     4        https://bugs.webkit.org/show_bug.cgi?id=173395
     5
     6        Reviewed by Simon Fraser.
     7
     8        * fast/css/DOMQuad-serialization-expected.txt: Added.
     9        * fast/css/DOMQuad-serialization.html: Added.
     10        Add test for DOMQuad serialization, now that it is supported.
     11
    1122017-06-19  Commit Queue  <commit-queue@webkit.org>
    213
  • trunk/Source/WebCore/ChangeLog

    r218510 r218511  
     12017-06-19  Sam Weinig  <sam@webkit.org>
     2
     3        [WebIDL] Add support for serializers that have members that are themselves serializers (or inherit being a serializer from a parent)
     4        https://bugs.webkit.org/show_bug.cgi?id=173395
     5
     6        Reviewed by Simon Fraser.
     7
     8        Test: fast/css/DOMQuad-serialization.html
     9
     10        * bindings/scripts/CodeGenerator.pm:
     11        (InheritsSerializable):
     12        Helper to determine if an interface inherits from any interfaces
     13        that are serializable. This is necessary because an attribute is
     14        serializable even if its interface is not marked as serializable.
     15
     16        (IsSerializableAttribute):
     17        Check ancestor interfaces as well to determine serializability.
     18
     19        * bindings/scripts/CodeGeneratorJS.pm:
     20        (GenerateSerializerDefinition):
     21        Specialize attributes that are serializable interfaces to call its interfaces
     22        serialize function, thus allowing nested objects to be serialized.
     23
     24        * dom/DOMQuad.idl:
     25        Add serializer.
     26
     27        * bindings/scripts/test/JS/JSTestSerialization.cpp:
     28        * bindings/scripts/test/JS/JSTestSerializationIndirectInheritance.cpp: Added.
     29        * bindings/scripts/test/JS/JSTestSerializationIndirectInheritance.h: Added.
     30        * bindings/scripts/test/TestSerialization.idl:
     31        * bindings/scripts/test/TestSerializationIndirectInheritance.idl: Added.
     32        Add and update tests.
     33
    1342017-06-19  Commit Queue  <commit-queue@webkit.org>
    235
  • trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm

    r218495 r218511  
    904904}
    905905
     906sub InheritsSerializable
     907{
     908    my ($object, $interface) = @_;
     909
     910    my $anyParentIsSerializable = 0;
     911    $object->ForAllParents($interface, sub {
     912        my $parentInterface = shift;
     913        $anyParentIsSerializable = 1 if $parentInterface->serializable;
     914    }, 0);
     915
     916    return $anyParentIsSerializable;
     917}
     918
    906919sub IsSerializableAttribute
    907920{
    908     my ($object, $currentInterface, $attribute) = @_;
     921    my ($object, $interface, $attribute) = @_;
    909922
    910923    # https://heycam.github.io/webidl/#dfn-serializable-type
     
    921934    }
    922935
    923     my $interface = GetInterfaceForAttribute($object, $currentInterface, $attribute);
    924     if ($interface && $interface->serializable) {
    925         die "Serializer for non-primitive types is not currently supported\n";
     936    return 0 if !$object->IsInterfaceType($type);
     937
     938    my $interfaceForAttribute = $object->GetInterfaceForAttribute($interface, $attribute);
     939    if ($interfaceForAttribute) {
     940        return 1 if $interfaceForAttribute->serializable;
     941        return $object->InheritsSerializable($interfaceForAttribute);
    926942    }
    927943
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r218495 r218511  
    51935193
    51945194    foreach my $attribute (@serializedAttributes) {
     5195        assert("Attributes that throw exceptions are not supported with serializers yet.") if $attribute->extendedAttributes->{GetterMayThrowException} || $attribute->extendedAttributes->{MayThrowException};
     5196
    51955197        my $name = $attribute->name;
    51965198        my $getFunctionName = GetAttributeGetterName($interface, $className, $attribute);
    51975199        push(@implContent, "    auto ${name}Value = ${getFunctionName}Getter(state, thisObject, throwScope);\n");
    51985200        push(@implContent, "    throwScope.assertNoException();\n");
    5199         push(@implContent, "    result->putDirect(vm, Identifier::fromString(&vm, \"${name}\"), ${name}Value);\n");
     5201
     5202        if ($codeGenerator->IsInterfaceType($attribute->type)) {
     5203            my $attributeInterfaceName = $attribute->type->name;
     5204            push(@implContent, "    auto* ${name}SerializedValue = JS${attributeInterfaceName}::serialize(state, *jsCast<JS${attributeInterfaceName}*>(${name}Value), globalObject, throwScope);\n");
     5205            push(@implContent, "    result->putDirect(vm, Identifier::fromString(&vm, \"${name}\"), ${name}SerializedValue);\n");
     5206        } else {
     5207            push(@implContent, "    result->putDirect(vm, Identifier::fromString(&vm, \"${name}\"), ${name}Value);\n");
     5208        }
     5209
    52005210        push(@implContent, "\n");
    52015211    }
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestSerialization.cpp

    r218342 r218511  
    3333#include "JSDOMWrapperCache.h"
    3434#include "JSTestException.h"
     35#include "JSTestSerializationIndirectInheritance.h"
     36#include "JSTestSerializationInheritFinal.h"
    3537#include <runtime/FunctionPrototype.h>
    3638#include <runtime/JSCInlines.h>
     
    6264JSC::EncodedJSValue jsTestSerializationSixthTypedefAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
    6365bool setJSTestSerializationSixthTypedefAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
     66JSC::EncodedJSValue jsTestSerializationSeventhDirectlySerializableAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
     67bool setJSTestSerializationSeventhDirectlySerializableAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
     68JSC::EncodedJSValue jsTestSerializationEighthIndirectlyAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
     69bool setJSTestSerializationEighthIndirectlyAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
    6470
    6571class JSTestSerializationPrototype : public JSC::JSNonFinalObject {
     
    116122    { "fifthLongAttribute", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestSerializationFifthLongAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestSerializationFifthLongAttribute) } },
    117123    { "sixthTypedefAttribute", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestSerializationSixthTypedefAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestSerializationSixthTypedefAttribute) } },
     124    { "seventhDirectlySerializableAttribute", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestSerializationSeventhDirectlySerializableAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestSerializationSeventhDirectlySerializableAttribute) } },
     125    { "eighthIndirectlyAttribute", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestSerializationEighthIndirectlyAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestSerializationEighthIndirectlyAttribute) } },
    118126    { "toJSON", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestSerializationPrototypeFunctionToJSON), (intptr_t) (0) } },
    119127};
     
    375383}
    376384
     385static inline JSValue jsTestSerializationSeventhDirectlySerializableAttributeGetter(ExecState& state, JSTestSerialization& thisObject, ThrowScope& throwScope)
     386{
     387    UNUSED_PARAM(throwScope);
     388    UNUSED_PARAM(state);
     389    auto& impl = thisObject.wrapped();
     390    JSValue result = toJS<IDLInterface<TestSerializationInheritFinal>>(state, *thisObject.globalObject(), impl.seventhDirectlySerializableAttribute());
     391    return result;
     392}
     393
     394EncodedJSValue jsTestSerializationSeventhDirectlySerializableAttribute(ExecState* state, EncodedJSValue thisValue, PropertyName)
     395{
     396    return IDLAttribute<JSTestSerialization>::get<jsTestSerializationSeventhDirectlySerializableAttributeGetter>(*state, thisValue, "seventhDirectlySerializableAttribute");
     397}
     398
     399static inline bool setJSTestSerializationSeventhDirectlySerializableAttributeSetter(ExecState& state, JSTestSerialization& thisObject, JSValue value, ThrowScope& throwScope)
     400{
     401    UNUSED_PARAM(state);
     402    UNUSED_PARAM(throwScope);
     403    auto& impl = thisObject.wrapped();
     404    auto nativeValue = convert<IDLInterface<TestSerializationInheritFinal>>(state, value, [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwAttributeTypeError(state, scope, "TestSerialization", "seventhDirectlySerializableAttribute", "TestSerializationInheritFinal"); });
     405    RETURN_IF_EXCEPTION(throwScope, false);
     406    impl.setSeventhDirectlySerializableAttribute(*nativeValue);
     407    return true;
     408}
     409
     410bool setJSTestSerializationSeventhDirectlySerializableAttribute(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
     411{
     412    return IDLAttribute<JSTestSerialization>::set<setJSTestSerializationSeventhDirectlySerializableAttributeSetter>(*state, thisValue, encodedValue, "seventhDirectlySerializableAttribute");
     413}
     414
     415static inline JSValue jsTestSerializationEighthIndirectlyAttributeGetter(ExecState& state, JSTestSerialization& thisObject, ThrowScope& throwScope)
     416{
     417    UNUSED_PARAM(throwScope);
     418    UNUSED_PARAM(state);
     419    auto& impl = thisObject.wrapped();
     420    JSValue result = toJS<IDLInterface<TestSerializationIndirectInheritance>>(state, *thisObject.globalObject(), impl.eighthIndirectlyAttribute());
     421    return result;
     422}
     423
     424EncodedJSValue jsTestSerializationEighthIndirectlyAttribute(ExecState* state, EncodedJSValue thisValue, PropertyName)
     425{
     426    return IDLAttribute<JSTestSerialization>::get<jsTestSerializationEighthIndirectlyAttributeGetter>(*state, thisValue, "eighthIndirectlyAttribute");
     427}
     428
     429static inline bool setJSTestSerializationEighthIndirectlyAttributeSetter(ExecState& state, JSTestSerialization& thisObject, JSValue value, ThrowScope& throwScope)
     430{
     431    UNUSED_PARAM(state);
     432    UNUSED_PARAM(throwScope);
     433    auto& impl = thisObject.wrapped();
     434    auto nativeValue = convert<IDLInterface<TestSerializationIndirectInheritance>>(state, value, [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwAttributeTypeError(state, scope, "TestSerialization", "eighthIndirectlyAttribute", "TestSerializationIndirectInheritance"); });
     435    RETURN_IF_EXCEPTION(throwScope, false);
     436    impl.setEighthIndirectlyAttribute(*nativeValue);
     437    return true;
     438}
     439
     440bool setJSTestSerializationEighthIndirectlyAttribute(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
     441{
     442    return IDLAttribute<JSTestSerialization>::set<setJSTestSerializationEighthIndirectlyAttributeSetter>(*state, thisValue, encodedValue, "eighthIndirectlyAttribute");
     443}
     444
    377445JSC::JSObject* JSTestSerialization::serialize(ExecState& state, JSTestSerialization& thisObject, JSDOMGlobalObject& globalObject, ThrowScope& throwScope)
    378446{
     
    399467    throwScope.assertNoException();
    400468    result->putDirect(vm, Identifier::fromString(&vm, "sixthTypedefAttribute"), sixthTypedefAttributeValue);
     469
     470    auto seventhDirectlySerializableAttributeValue = jsTestSerializationSeventhDirectlySerializableAttributeGetter(state, thisObject, throwScope);
     471    throwScope.assertNoException();
     472    auto* seventhDirectlySerializableAttributeSerializedValue = JSTestSerializationInheritFinal::serialize(state, *jsCast<JSTestSerializationInheritFinal*>(seventhDirectlySerializableAttributeValue), globalObject, throwScope);
     473    result->putDirect(vm, Identifier::fromString(&vm, "seventhDirectlySerializableAttribute"), seventhDirectlySerializableAttributeSerializedValue);
     474
     475    auto eighthIndirectlyAttributeValue = jsTestSerializationEighthIndirectlyAttributeGetter(state, thisObject, throwScope);
     476    throwScope.assertNoException();
     477    auto* eighthIndirectlyAttributeSerializedValue = JSTestSerializationIndirectInheritance::serialize(state, *jsCast<JSTestSerializationIndirectInheritance*>(eighthIndirectlyAttributeValue), globalObject, throwScope);
     478    result->putDirect(vm, Identifier::fromString(&vm, "eighthIndirectlyAttribute"), eighthIndirectlyAttributeSerializedValue);
    401479
    402480    return result;
  • trunk/Source/WebCore/bindings/scripts/test/TestSerialization.idl

    r211409 r218511  
    3434    attribute TestTimeStamp         sixthTypedefAttribute;
    3535
     36    attribute TestSerializationInheritFinal seventhDirectlySerializableAttribute;
     37    attribute TestSerializationIndirectInheritance eighthIndirectlyAttribute;
     38
    3639    serializer = { attribute };
    3740};
  • trunk/Source/WebCore/bindings/scripts/test/TestSerializationIndirectInheritance.idl

    r218510 r218511  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 typedef double TestTimeStamp;
    27 
    28 interface TestSerialization {
    29     attribute DOMString             firstStringAttribute;
    30     attribute long                  secondLongAttribute;
    31     attribute TestException         thirdUnserializableAttribute;
    32     attribute unrestricted double   fourthUnrestrictedDoubleAttribute;
    33     attribute long                  fifthLongAttribute;
    34     attribute TestTimeStamp         sixthTypedefAttribute;
    35 
    36     serializer = { attribute };
     26interface TestSerializationIndirectInheritance : TestSerializationInherit {
    3727};
  • trunk/Source/WebCore/dom/DOMQuad.idl

    r218458 r218511  
    3131    ImplementationLacksVTable,
    3232    JSCustomMarkFunction
    33 ]
    34 interface DOMQuad {
     33] interface DOMQuad {
    3534    [NewObject] static DOMQuad fromRect(optional DOMRectInit other);
    3635    [NewObject] static DOMQuad fromQuad(optional DOMQuadInit other);
     
    4241    [NewObject] DOMRect getBounds();
    4342
    44     // serializer = { attribute }; FIXME: implement.
     43    serializer = { attribute };
    4544};
Note: See TracChangeset for help on using the changeset viewer.