RESOLVED FIXED 160487
Add support for wrapper types in dictionaries
https://bugs.webkit.org/show_bug.cgi?id=160487
Summary Add support for wrapper types in dictionaries
Chris Dumez
Reported 2016-08-02 19:54:32 PDT
Add support for wrapper types in dictionaries
Attachments
WIP patch (9.15 KB, patch)
2016-08-02 19:56 PDT, Chris Dumez
no flags
Patch (10.44 KB, patch)
2016-08-02 20:28 PDT, Chris Dumez
no flags
Patch (10.20 KB, patch)
2016-08-03 08:54 PDT, Chris Dumez
no flags
Chris Dumez
Comment 1 2016-08-02 19:56:26 PDT
Created attachment 285184 [details] WIP patch
Chris Dumez
Comment 2 2016-08-02 20:28:34 PDT
Chris Dumez
Comment 3 2016-08-02 20:29:47 PDT
@Darin / @Sam: What do you think of this approach? @Simon: Is this sufficient to support your use cases? I have verified that the generated code builds.
Chris Dumez
Comment 5 2016-08-02 21:23:11 PDT
(In reply to comment #4) > What I need to work is: > https://wicg.github.io/IntersectionObserver/#intersection-observer-init > and > https://wicg.github.io/IntersectionObserver/#intersection-observer-entry Ok, this patch gets us closer but you will still have trouble with the union type because we don't support unions at all in the bindings generator (not just in dictionaries). Honestly, I would suggest using the "Dictionary" type in the IDL and deal with the JSDictionary type manually in the implementation for now.
Chris Dumez
Comment 6 2016-08-02 21:28:22 PDT
(In reply to comment #5) > (In reply to comment #4) > > What I need to work is: > > https://wicg.github.io/IntersectionObserver/#intersection-observer-init > > and > > https://wicg.github.io/IntersectionObserver/#intersection-observer-entry > > Ok, this patch gets us closer but you will still have trouble with the union > type because we don't support unions at all in the bindings generator (not > just in dictionaries). > > Honestly, I would suggest using the "Dictionary" type in the IDL and deal > with the JSDictionary type manually in the implementation for now. Or we could maybe use 'any' type for the ´threshold' dictionary member for now. If it does not work yet it would be trivial to add support for ´any' type in dictionaries. It would pass a JSValue to the implementation and the implementation would need to take care of converting this value into either a double or a sequence of double.
Darin Adler
Comment 7 2016-08-02 22:16:57 PDT
Comment on attachment 285186 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=285186&action=review > Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1022 > + # FIXME: Ideally we would pass non-nullable wrapper types by reference. However, we currently > + # cannot have references in the struct on native side because this function returns { } in case > + # of error. I suppose this could be fixed by making the return type of convert be an Optional just like the type of convertOptional and use Nullopt when we are throwing an exception. If that doesn’t hurt performance too badly it might be worth doing. Could even make the code calling this more optimal because checking for null is probably more efficient than checking state.hadException().
Chris Dumez
Comment 8 2016-08-02 22:28:04 PDT
(In reply to comment #7) > Comment on attachment 285186 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=285186&action=review > > > Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1022 > > + # FIXME: Ideally we would pass non-nullable wrapper types by reference. However, we currently > > + # cannot have references in the struct on native side because this function returns { } in case > > + # of error. > > I suppose this could be fixed by making the return type of convert be an > Optional just like the type of convertOptional and use Nullopt when we are > throwing an exception. If that doesn’t hurt performance too badly it might > be worth doing. Could even make the code calling this more optimal because > checking for null is probably more efficient than checking > state.hadException(). Yes, I had the same thought but it seemed like a bigger change, especially considering we do not have users that need support for non billable wrapper types in dictionaries yet (in Simon's case the member is nullable. That said, I am happy to incorporate this into my patch tomorrow if you think I should.
Chris Dumez
Comment 9 2016-08-02 22:29:12 PDT
(In reply to comment #8) > (In reply to comment #7) > > Comment on attachment 285186 [details] > > Patch > > > > View in context: > > https://bugs.webkit.org/attachment.cgi?id=285186&action=review > > > > > Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1022 > > > + # FIXME: Ideally we would pass non-nullable wrapper types by reference. However, we currently > > > + # cannot have references in the struct on native side because this function returns { } in case > > > + # of error. > > > > I suppose this could be fixed by making the return type of convert be an > > Optional just like the type of convertOptional and use Nullopt when we are > > throwing an exception. If that doesn’t hurt performance too badly it might > > be worth doing. Could even make the code calling this more optimal because > > checking for null is probably more efficient than checking > > state.hadException(). > > Yes, I had the same thought but it seemed like a bigger change, especially > considering we do not have users that need support for non billable wrapper > types in dictionaries yet (in Simon's case the member is nullable. That > said, I am happy to incorporate this into my patch tomorrow if you think I > should. s/billable/nullable (darn autocorrect)
Darin Adler
Comment 10 2016-08-02 22:46:35 PDT
Comment on attachment 285186 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=285186&action=review >>>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1022 >>>> + # of error. >>> >>> I suppose this could be fixed by making the return type of convert be an Optional just like the type of convertOptional and use Nullopt when we are throwing an exception. If that doesn’t hurt performance too badly it might be worth doing. Could even make the code calling this more optimal because checking for null is probably more efficient than checking state.hadException(). >> >> Yes, I had the same thought but it seemed like a bigger change, especially considering we do not have users that need support for non billable wrapper types in dictionaries yet (in Simon's case the member is nullable. That said, I am happy to incorporate this into my patch tomorrow if you think I should. > > s/billable/nullable (darn autocorrect) You could make it an error to ask for a non-nullable wrapper type in a dictionary rather than implementing it with the wrong type. If nobody needs it right now.
Chris Dumez
Comment 11 2016-08-03 08:54:19 PDT
Chris Dumez
Comment 12 2016-08-03 08:54:47 PDT
(In reply to comment #10) > Comment on attachment 285186 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=285186&action=review > > >>>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1022 > >>>> + # of error. > >>> > >>> I suppose this could be fixed by making the return type of convert be an Optional just like the type of convertOptional and use Nullopt when we are throwing an exception. If that doesn’t hurt performance too badly it might be worth doing. Could even make the code calling this more optimal because checking for null is probably more efficient than checking state.hadException(). > >> > >> Yes, I had the same thought but it seemed like a bigger change, especially considering we do not have users that need support for non billable wrapper types in dictionaries yet (in Simon's case the member is nullable. That said, I am happy to incorporate this into my patch tomorrow if you think I should. > > > > s/billable/nullable (darn autocorrect) > > You could make it an error to ask for a non-nullable wrapper type in a > dictionary rather than implementing it with the wrong type. If nobody needs > it right now. Ok, I chose this approach.
Chris Dumez
Comment 13 2016-08-04 15:03:43 PDT
Comment on attachment 285233 [details] Patch Clearing flags on attachment: 285233 Committed r204143: <http://trac.webkit.org/changeset/204143>
Chris Dumez
Comment 14 2016-08-04 15:03:49 PDT
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.