Bug 182399 - [WebIDL] Support optional Promise arguments
Summary: [WebIDL] Support optional Promise arguments
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andy Estes
URL:
Keywords: InRadar
Depends on:
Blocks: 182538
  Show dependency treegraph
 
Reported: 2018-02-01 11:32 PST by Andy Estes
Modified: 2018-02-06 13:45 PST (History)
13 users (show)

See Also:


Attachments
Patch (8.71 KB, patch)
2018-02-01 11:39 PST, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (9.15 KB, patch)
2018-02-06 11:46 PST, Andy Estes
aestes: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Estes 2018-02-01 11:32:46 PST
[WebIDL] Support optional Promise arguments
Comment 1 Andy Estes 2018-02-01 11:39:29 PST
Created attachment 332898 [details]
Patch
Comment 2 Saam Barati 2018-02-01 11:48:43 PST
Comment on attachment 332898 [details]
Patch

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

> Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp:6282
> +    auto promise = state->argument(0).isUndefined() ? nullptr : convert<IDLPromise<IDLVoid>>(*state, state->uncheckedArgument(0));

Seems weird to do argument(0) followed by uncheckedArgument(0) here. I think it's probably semantically correct (you can't have non-undefined passed unless an argument was passed there), but I'd just use argument(0) twice. The compiler should eliminate the second bounds check anyways.
Comment 3 Andy Estes 2018-02-01 12:57:24 PST
rdar://problem/36754552
Comment 4 Andy Estes 2018-02-02 09:37:27 PST
(In reply to Saam Barati from comment #2)
> Comment on attachment 332898 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=332898&action=review
> 
> > Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp:6282
> > +    auto promise = state->argument(0).isUndefined() ? nullptr : convert<IDLPromise<IDLVoid>>(*state, state->uncheckedArgument(0));
> 
> Seems weird to do argument(0) followed by uncheckedArgument(0) here. I think
> it's probably semantically correct (you can't have non-undefined passed
> unless an argument was passed there), but I'd just use argument(0) twice.
> The compiler should eliminate the second bounds check anyways.

Ok, I'll look to do this in a follow-up. This change will update a bunch of bindings test expectations and I'd like to keep this patch small for merging purposes.
Comment 5 Chris Dumez 2018-02-06 10:56:29 PST
Comment on attachment 332898 [details]
Patch

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

Change seems fine since Promise types cannot be nullable as per Web IDL spec (therefore, we will never need to distinguish null parameter from missing/undefined parameter). A few comments though.

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1540
> +    return "WTFMove(${name})" if $type->isNullable || (ref($context) eq "IDLArgument" && $context->isOptional);

Could we instead use below:
return "${name}.releaseNonNull()" if $codeGenerator->IsCallbackInterface($type) || $codeGenerator->IsCallbackFunction($type) || ($codeGenerator->IsPromiseType($type) && !$context->isOptional);

I do not like that this line is not Promise type specific.

>>> Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp:6282
>>> +    auto promise = state->argument(0).isUndefined() ? nullptr : convert<IDLPromise<IDLVoid>>(*state, state->uncheckedArgument(0));
>> 
>> Seems weird to do argument(0) followed by uncheckedArgument(0) here. I think it's probably semantically correct (you can't have non-undefined passed unless an argument was passed there), but I'd just use argument(0) twice. The compiler should eliminate the second bounds check anyways.
> 
> Ok, I'll look to do this in a follow-up. This change will update a bunch of bindings test expectations and I'd like to keep this patch small for merging purposes.

I would keep using uncheckedArgument(), we do this on purpose in the bindings generator.

Does this build though? is the compiler able to figure out the auto type given the ternary and nullptr ?
Comment 6 WebKit Commit Bot 2018-02-06 10:57:19 PST
Comment on attachment 332898 [details]
Patch

Rejecting attachment 332898 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-01', 'validate-changelog', '--check-oops', '--non-interactive', 332898, '--port=mac']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit

ChangeLog entry in Source/WebCore/ChangeLog contains OOPS!.

Full output: http://webkit-queues.webkit.org/results/6384993
Comment 7 Andy Estes 2018-02-06 11:02:17 PST
(In reply to Chris Dumez from comment #5)
> Comment on attachment 332898 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=332898&action=review
> 
> Change seems fine since Promise types cannot be nullable as per Web IDL spec
> (therefore, we will never need to distinguish null parameter from
> missing/undefined parameter). A few comments though.
> 
> > Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1540
> > +    return "WTFMove(${name})" if $type->isNullable || (ref($context) eq "IDLArgument" && $context->isOptional);
> 
> Could we instead use below:
> return "${name}.releaseNonNull()" if
> $codeGenerator->IsCallbackInterface($type) ||
> $codeGenerator->IsCallbackFunction($type) ||
> ($codeGenerator->IsPromiseType($type) && !$context->isOptional);
> 
> I do not like that this line is not Promise type specific.

We could do that, but I think the WTFMove() is right for all optionals.

> 
> >>> Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp:6282
> >>> +    auto promise = state->argument(0).isUndefined() ? nullptr : convert<IDLPromise<IDLVoid>>(*state, state->uncheckedArgument(0));
> >> 
> >> Seems weird to do argument(0) followed by uncheckedArgument(0) here. I think it's probably semantically correct (you can't have non-undefined passed unless an argument was passed there), but I'd just use argument(0) twice. The compiler should eliminate the second bounds check anyways.
> > 
> > Ok, I'll look to do this in a follow-up. This change will update a bunch of bindings test expectations and I'd like to keep this patch small for merging purposes.
> 
> I would keep using uncheckedArgument(), we do this on purpose in the
> bindings generator.
> 
> Does this build though? is the compiler able to figure out the auto type
> given the ternary and nullptr ?

Yes, it builds.
Comment 8 Andy Estes 2018-02-06 11:46:01 PST
Created attachment 333198 [details]
Patch
Comment 9 Andy Estes 2018-02-06 13:45:52 PST
Committed r228189: <https://trac.webkit.org/r228189>