Bug 168293 - [WebIDL] Improve serializer = { inherit }
Summary: [WebIDL] Improve serializer = { inherit }
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Bindings (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords:
Depends on:
Blocks: 168086
  Show dependency treegraph
 
Reported: 2017-02-14 00:53 PST by Joseph Pecoraro
Modified: 2017-02-14 23:13 PST (History)
5 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (21.70 KB, patch)
2017-02-14 00:58 PST, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2017-02-14 00:53:40 PST
This improves, and fixes serializer = { inherit } now that I have a class where I can test it.

Given:

>    interface TestSerialization {
>        attribute long a;
>        attribute long b;
>        attribute long c;
>        serializer = { attribute };
>    };
>
>    interface TestSerializationFinal : TestSerialization {
>        attribute long x;
>        attribute long y;
>        serializer = { inherit, attribute };
>    };

The existing code would have compiler errors for TestSerializationFinal trying to access static inline functions that only exist inside of TestSerialization.cpp when trying to generate the toJSON serializer for TestSerializationFinal.

I will change serializer generation to create an exposed serialize method which does what we do now:

>    class JSTestSerialization : public JSDOMWrapper<TestSerialization> {
>    public:
>        ...
>        static JSC::JSObject* serialize(JSC::ExecState*, JSTestSerialization* thisObject, JSC::ThrowScope&);
>        ...
>    };

Which any subclass (a serializer with {inherit}) can use to get the parent's serialization:

>    JSC::JSObject* JSTestSerializationInherit::serialize(ExecState* state, JSTestSerializationInherit* thisObject, ThrowScope& throwScope)
>    {
>        auto& vm = state->vm();
>        auto* result = JSTestSerialization::serialize(state, thisObject, throwScope);
>
>        auto inheritLongAttributeValue = jsTestSerializationInheritX(*state, *thisObject, throwScope);
>        ASSERT(!throwScope.exception());
>        result->putDirect(vm, Identifier::fromString(&vm, "x"), inheritLongAttributeValue);
>
>        auto inheritLongAttributeValue = jsTestSerializationInheritY(*state, *thisObject, throwScope);
>        ASSERT(!throwScope.exception());
>        result->putDirect(vm, Identifier::fromString(&vm, "y"), inheritLongAttributeValue);
>
>        return result;
>    }

This is way better (each class only needs to generate for its own accessors) and more importantly it actually works!
Comment 1 Joseph Pecoraro 2017-02-14 00:58:56 PST
Created attachment 301474 [details]
[PATCH] Proposed Fix
Comment 2 youenn fablet 2017-02-14 22:04:10 PST
Comment on attachment 301474 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=301474&action=review

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1938
> +    push(@headerContent, "    static JSC::JSObject* serialize(JSC::ExecState*, JS${interfaceName}* thisObject, JSC::ThrowScope&);\n") if $interface->serializable;

Can we pass ExecState& and JSXX& instead of pointers?
Comment 3 Joseph Pecoraro 2017-02-14 22:47:49 PST
(In reply to comment #2)
> Comment on attachment 301474 [details]
> [PATCH] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=301474&action=review
> 
> > Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1938
> > +    push(@headerContent, "    static JSC::JSObject* serialize(JSC::ExecState*, JS${interfaceName}* thisObject, JSC::ThrowScope&);\n") if $interface->serializable;
> 
> Can we pass ExecState& and JSXX& instead of pointers?

Hmm, probably. I'll look at that in a follow-up if I have time. This uses whatever the existing bindings code expects, so I'm going to keep it consistent for now.

Thanks for the review!
Comment 4 WebKit Commit Bot 2017-02-14 23:13:44 PST
Comment on attachment 301474 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 301474

Committed r212344: <http://trac.webkit.org/changeset/212344>
Comment 5 WebKit Commit Bot 2017-02-14 23:13:50 PST
All reviewed patches have been landed.  Closing bug.