Bug 212767

Summary: DOM constructor should only accept Ref<> / ExceptionOr<Ref<>> for creation to ensure toJSNewlyCreated is always returning object
Product: WebKit Reporter: Yusuke Suzuki <ysuzuki>
Component: New BugsAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, changseok, darin, eric.carlson, esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, jer.noble, kangil.han, keith_miller, kondapallykalyan, mark.lam, msaboff, philipj, saam, sergio, tzagallo, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 212799    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
darin: review+
Patch for landing none

Description Yusuke Suzuki 2020-06-04 11:27:30 PDT
DOM constructor should only accept Ref<> / ExceptionOr<Ref<>> for creation to ensure toJSNewlyCreated is always returning object
Comment 1 Yusuke Suzuki 2020-06-04 11:33:13 PDT
Created attachment 401053 [details]
Patch
Comment 2 Yusuke Suzuki 2020-06-04 11:35:31 PDT
Created attachment 401056 [details]
Patch
Comment 3 Darin Adler 2020-06-04 12:00:23 PDT
Comment on attachment 401056 [details]
Patch

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

I think you need to do run-bindings-tests --reset-results and include that in your patch.

> Source/WebCore/Modules/webaudio/AudioContext.cpp:125
>  unsigned AudioContext::s_hardwareContextCount = 0;

Do we even need to count on platforms other than Windows?

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:7466
> +            if ($interface->extendedAttributes->{ConstructorMayThrowException}) {

Long term, I was thinking we could use meta-programming to generate the exception handling code only if needed, and not require an attribute just to say something may throw an exception.

If C++ is powerful enough, it would be neat if the code generator did less of the work, and there was less redundancy between the IDL and header files.

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:7488
> +            push(@$outputArray, "    ASSERT(jsValue);\n");
> +            push(@$outputArray, "    ASSERT(jsValue.isObject());\n");

I think the asObject function should include both of these assertions, so we should not need to repeat them in the generated code.
Comment 4 Yusuke Suzuki 2020-06-04 15:46:23 PDT
Comment on attachment 401056 [details]
Patch

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

Updated the binding-test results.

>> Source/WebCore/Modules/webaudio/AudioContext.cpp:125
>>  unsigned AudioContext::s_hardwareContextCount = 0;
> 
> Do we even need to count on platforms other than Windows?

s_hardwareContextCount is also used for debugging (ASSERT in `AudioContext::uninitialize`), so I think keeping it is nice.

>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:7466
>> +            if ($interface->extendedAttributes->{ConstructorMayThrowException}) {
> 
> Long term, I was thinking we could use meta-programming to generate the exception handling code only if needed, and not require an attribute just to say something may throw an exception.
> 
> If C++ is powerful enough, it would be neat if the code generator did less of the work, and there was less redundancy between the IDL and header files.

Agree. In long term, we should delegate these features to C++.

>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:7488
>> +            push(@$outputArray, "    ASSERT(jsValue.isObject());\n");
> 
> I think the asObject function should include both of these assertions, so we should not need to repeat them in the generated code.

Sounds good. Fixed.
Comment 5 Yusuke Suzuki 2020-06-04 16:07:40 PDT
Windows failure looks unrelated since this does not change SVG.
Comment 6 Yusuke Suzuki 2020-06-04 16:11:02 PDT
Committed r262583: <https://trac.webkit.org/changeset/262583>
Comment 7 Radar WebKit Bug Importer 2020-06-04 16:11:17 PDT
<rdar://problem/64000845>
Comment 8 Yusuke Suzuki 2020-06-04 21:33:14 PDT
I'll comment out `static_assert` in CodeGeneratorJS.pm for now since we had the same problem in Internal builds.
Comment 9 Yusuke Suzuki 2020-06-04 21:41:15 PDT
Re-opened since this is blocked by bug 212799
Comment 10 Yusuke Suzuki 2020-06-05 00:28:23 PDT
Created attachment 401124 [details]
Patch for landing
Comment 11 EWS 2020-06-05 10:26:19 PDT
Committed r262628: <https://trac.webkit.org/changeset/262628>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 401124 [details].