Bug 215966 - [JSC] super property with new should be accepted
Summary: [JSC] super property with new should be accepted
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: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-08-28 20:18 PDT by Yusuke Suzuki
Modified: 2020-08-29 00:12 PDT (History)
9 users (show)

See Also:


Attachments
Patch (4.82 KB, patch)
2020-08-28 20:20 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (8.68 KB, patch)
2020-08-28 22:47 PDT, Yusuke Suzuki
ross.kirsling: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2020-08-28 20:18:34 PDT
[JSC] super property with new should be accepted
Comment 1 Yusuke Suzuki 2020-08-28 20:20:30 PDT
Created attachment 407522 [details]
Patch
Comment 2 Yusuke Suzuki 2020-08-28 20:21:43 PDT
Interestingly, there is no test262 tests for that.
Comment 3 Alexey Shvayka 2020-08-28 22:18:19 PDT
Comment on attachment 407522 [details]
Patch

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

This is a great find!
I've vetted ~130 LOC between the previous and current check location, everything looks correct.

> Source/JavaScriptCore/ChangeLog:8
> +        While we should reject `new super` / `new super()`, we should accept `new super.property`.

Should we explain why by linking the grammar?
https://tc39.es/ecma262/#prod-SuperProperty is a child production of https://tc39.es/ecma262/#prod-MemberExpression, unlike https://tc39.es/ecma262/#prod-SuperCall.

> Source/JavaScriptCore/parser/Parser.cpp:4977
> +                    semanticFailIfTrue(baseIsSuper, "Cannot use new with super");

There are 2 error messages that refer invalid super() as "super call" rather than just "super".
It would be nice to follow that.

> JSTests/stress/super-and-new.js:42
> +            shouldBe(typeof (new super["hey2"]()), "object");

A few more ideas on test coverage:

```
new async.super();
new new.target.super();
new super.super``;
?.
```
Comment 4 Alexey Shvayka 2020-08-28 22:19:11 PDT
(In reply to Yusuke Suzuki from comment #2)
> Interestingly, there is no test262 tests for that.

No open issue either. We should definitely add one since V8 8.4 experiences the same bug. SpiderMonkey is correct.
Comment 5 Yusuke Suzuki 2020-08-28 22:32:27 PDT
Comment on attachment 407522 [details]
Patch

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

Thanks!

>> Source/JavaScriptCore/ChangeLog:8
>> +        While we should reject `new super` / `new super()`, we should accept `new super.property`.
> 
> Should we explain why by linking the grammar?
> https://tc39.es/ecma262/#prod-SuperProperty is a child production of https://tc39.es/ecma262/#prod-MemberExpression, unlike https://tc39.es/ecma262/#prod-SuperCall.

Sounds good, added.

>> Source/JavaScriptCore/parser/Parser.cpp:4977
>> +                    semanticFailIfTrue(baseIsSuper, "Cannot use new with super");
> 
> There are 2 error messages that refer invalid super() as "super call" rather than just "super".
> It would be nice to follow that.

Sounds good. Changed.

>> JSTests/stress/super-and-new.js:42
>> +            shouldBe(typeof (new super["hey2"]()), "object");
> 
> A few more ideas on test coverage:
> 
> ```
> new async.super();
> new new.target.super();
> new super.super``;
> ?.
> ```

Added.
Comment 6 Yusuke Suzuki 2020-08-28 22:32:56 PDT
(In reply to Alexey Shvayka from comment #4)
> (In reply to Yusuke Suzuki from comment #2)
> > Interestingly, there is no test262 tests for that.
> 
> No open issue either. We should definitely add one since V8 8.4 experiences
> the same bug. SpiderMonkey is correct.

Interesting! We should contribute it to test262.
Comment 7 Yusuke Suzuki 2020-08-28 22:47:35 PDT
Created attachment 407528 [details]
Patch
Comment 8 Ross Kirsling 2020-08-28 23:08:42 PDT
Comment on attachment 407528 [details]
Patch

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

r=me

> LayoutTests/ChangeLog:9
> +        * js/class-syntax-super-expected.txt:
> +        * js/script-tests/class-syntax-super.js:

Hmm, should we move this file out of LayoutTests while we're at it?
Comment 9 Yusuke Suzuki 2020-08-29 00:08:45 PDT
Comment on attachment 407528 [details]
Patch

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

>> LayoutTests/ChangeLog:9
>> +        * js/script-tests/class-syntax-super.js:
> 
> Hmm, should we move this file out of LayoutTests while we're at it?

Yeah, I think we should do that in a separate patch.
Comment 10 Yusuke Suzuki 2020-08-29 00:09:01 PDT
Mac-debug-wk1 failure is WebAudio ones we already know.
Comment 11 Yusuke Suzuki 2020-08-29 00:11:48 PDT
Committed r266322: <https://trac.webkit.org/changeset/266322>
Comment 12 Radar WebKit Bug Importer 2020-08-29 00:12:14 PDT
<rdar://problem/67983175>