RESOLVED FIXED 190997
[WebIDL] Support serializing sequences and FrozenArrays of non-interfaces
https://bugs.webkit.org/show_bug.cgi?id=190997
Summary [WebIDL] Support serializing sequences and FrozenArrays of non-interfaces
Andy Estes
Reported 2018-10-27 15:39:05 PDT
[WebIDL] Support serializing sequences and FrozenArrays of non-interfaces
Attachments
Patch (17.59 KB, patch)
2018-10-27 15:46 PDT, Andy Estes
no flags
Patch (17.57 KB, patch)
2018-10-28 05:38 PDT, Andy Estes
no flags
Patch (19.86 KB, patch)
2019-02-07 16:04 PST, Andy Estes
no flags
Patch (19.85 KB, patch)
2019-02-08 09:41 PST, Andy Estes
no flags
Andy Estes
Comment 1 2018-10-27 15:40:10 PDT
Andy Estes
Comment 2 2018-10-27 15:46:10 PDT
Wenson Hsieh
Comment 3 2018-10-27 19:14:03 PDT
Comment on attachment 353247 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=353247&action=review > Source/WebCore/bindings/scripts/test/TestSerialization.idl:42 > + attribute sequence<TestSerializationInheritFinal> twelthInterfaceSequenceAttribute; twelth!
Andy Estes
Comment 4 2018-10-27 19:38:47 PDT
(In reply to Wenson Hsieh from comment #3) > Comment on attachment 353247 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=353247&action=review > > > Source/WebCore/bindings/scripts/test/TestSerialization.idl:42 > > + attribute sequence<TestSerializationInheritFinal> twelthInterfaceSequenceAttribute; > > twelth 🤦‍♂️
Andy Estes
Comment 5 2018-10-28 05:38:14 PDT
Joseph Pecoraro
Comment 6 2018-10-30 17:30:34 PDT
Comment on attachment 353254 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=353254&action=review > Source/WebCore/bindings/scripts/test/JS/JSTestSerialization.cpp:646 > + auto tenthFrozenArrayAttributeValue = jsTestSerializationTenthFrozenArrayAttributeGetter(state, thisObject, throwScope); > + throwScope.assertNoException(); > + result->putDirect(vm, Identifier::fromString(&vm, "tenthFrozenArrayAttribute"), tenthFrozenArrayAttributeValue); > + > + auto eleventhSequenceAttributeValue = jsTestSerializationEleventhSequenceAttributeGetter(state, thisObject, throwScope); > + throwScope.assertNoException(); > + result->putDirect(vm, Identifier::fromString(&vm, "eleventhSequenceAttribute"), eleventhSequenceAttributeValue); Is this actually putting the raw array on the serialized object? Should this need to be copied/cloned somewhere? I'd expect if there is: interface TestSerialization { attribute sequence<DOMString> seq; serializer = { attribute }; } That if I have an instance that looked like: let instance = new TestSerialization; instance.seq = ["one", "two"]; The toJSON's seq should be separate from the instance's seq: assert( instance.toJSON().seq !== instance.seq ); // (1) Such that modifications to the toJSON result should not affect the instance's: let json = instance.toJSON(); assert( instance.seq.length === 2 ); json.seq.push("test"); assert( instance.seq.length === 2 ); // (2) Right now it looks like we are directly putting the value on to the JSON. So I'd think (1) and (2) would fail. -- Honestly the spec doesn't seem too clear to me on this. (Note serializer became toJSON a while back): https://heycam.github.io/webidl/#idl-tojson-operation It's example only uses primitives, where getting the underlying value is a copy. It doesn't show what to do with non-primitives, or I'm missing it.
Andy Estes
Comment 7 2018-10-31 14:08:53 PDT
(In reply to Joseph Pecoraro from comment #6) > Comment on attachment 353254 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=353254&action=review > > > Source/WebCore/bindings/scripts/test/JS/JSTestSerialization.cpp:646 > > + auto tenthFrozenArrayAttributeValue = jsTestSerializationTenthFrozenArrayAttributeGetter(state, thisObject, throwScope); > > + throwScope.assertNoException(); > > + result->putDirect(vm, Identifier::fromString(&vm, "tenthFrozenArrayAttribute"), tenthFrozenArrayAttributeValue); > > + > > + auto eleventhSequenceAttributeValue = jsTestSerializationEleventhSequenceAttributeGetter(state, thisObject, throwScope); > > + throwScope.assertNoException(); > > + result->putDirect(vm, Identifier::fromString(&vm, "eleventhSequenceAttribute"), eleventhSequenceAttributeValue); > > Is this actually putting the raw array on the serialized object? eleventhSequenceAttributeValue (for example) is a newly-created JSValue. jsTestSerializationEleventhSequenceAttributeGetter() calls toJS() on the wrapped object's Vector, which converts the vector's items into JSValues in a MarkedArgumentBuffer then creates a new array with JSC::constructArray(). But now that I think about it, we won't always get a new value if the attribute uses [CachedAttribute], [CustomGetter], or [CustomSetter]. I'll think about how to handle those. In the meantime, I wrote a layout test to check your questions: > I'd expect if there is: > > interface TestSerialization { > attribute sequence<DOMString> seq; > serializer = { attribute }; > } > > That if I have an instance that looked like: > > let instance = new TestSerialization; > instance.seq = ["one", "two"]; > > The toJSON's seq should be separate from the instance's seq: > > assert( instance.toJSON().seq !== instance.seq ); // (1) This assertion is true (the sequences are separate). > > Such that modifications to the toJSON result should not affect the > instance's: > > let json = instance.toJSON(); > assert( instance.seq.length === 2 ); > json.seq.push("test"); > assert( instance.seq.length === 2 ); // (2) These two assertions are also true (the sequences are separate).
Joseph Pecoraro
Comment 8 2018-10-31 14:43:10 PDT
> > The toJSON's seq should be separate from the instance's seq: > > > > assert( instance.toJSON().seq !== instance.seq ); // (1) > This assertion is true (the sequences are separate). > > > > > Such that modifications to the toJSON result should not affect the > > instance's: > > > > let json = instance.toJSON(); > > assert( instance.seq.length === 2 ); > > json.seq.push("test"); > > assert( instance.seq.length === 2 ); // (2) > These two assertions are also true (the sequences are separate). Awesome, then this is looking good to me.
Andy Estes
Comment 9 2019-02-07 16:04:56 PST
Brent Fulgham
Comment 10 2019-02-08 09:07:14 PST
Comment on attachment 361462 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=361462&action=review r=me > Source/WebCore/ChangeLog:14 > + left that as a follow-up task, since I don't see any IDLs that currently need this. If there are specs that support this idea, I think we should file a Bugzilla now that tracks this, and reference it in your FIXME comment. But, if no IDL needs this at all I guess we don't have to track work that isn't even conceptually needed. > Source/WebCore/bindings/scripts/CodeGenerator.pm:957 > + # FIXME: Teach GenerateSerializerDefinition to serialize sequences of interfaces, then remove this line. FIXME(Bug), please...
Andy Estes
Comment 11 2019-02-08 09:33:44 PST
Comment on attachment 361462 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=361462&action=review >> Source/WebCore/ChangeLog:14 >> + left that as a follow-up task, since I don't see any IDLs that currently need this. > > If there are specs that support this idea, I think we should file a Bugzilla now that tracks this, and reference it in your FIXME comment. > > But, if no IDL needs this at all I guess we don't have to track work that isn't even conceptually needed. Filed bug #194439 and will add a comment below. Thanks for reviewing!
Andy Estes
Comment 12 2019-02-08 09:41:06 PST
WebKit Commit Bot
Comment 13 2019-02-08 10:18:33 PST
Comment on attachment 361511 [details] Patch Clearing flags on attachment: 361511 Committed r241198: <https://trac.webkit.org/changeset/241198>
WebKit Commit Bot
Comment 14 2019-02-08 10:18:35 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.