Bug 152383 - [ES6][ES7] Drop Constructability of generator function
Summary: [ES6][ES7] Drop Constructability of generator function
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
Depends on:
Reported: 2015-12-17 02:44 PST by Yusuke Suzuki
Modified: 2015-12-29 11:50 PST (History)
8 users (show)

See Also:

Patch (37.20 KB, patch)
2015-12-26 08:07 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (1.58 KB, patch)
2015-12-29 05:57 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2015-12-17 02:44:11 PST
In ES7, the generator function becomes non-constructible.
This is good for the current JSC implementation. We no longer need to consider about newTarget when creating a generator.
And this is already introduced in ECMA262 2016 draft.

Comment 1 Yusuke Suzuki 2015-12-26 07:47:53 PST
Working on this.
Comment 2 Yusuke Suzuki 2015-12-26 08:07:40 PST
Created attachment 267926 [details]
Comment 3 Saam Barati 2015-12-27 22:42:23 PST
Is there a strong chance this could change before ES7 is finalized?
Comment 4 Yusuke Suzuki 2015-12-28 06:24:17 PST
(In reply to comment #3)
> Is there a strong chance this could change before ES7 is finalized?

If  something happens or better semantics is invested, it could be changed in the future.
But I don't think this behavior will be reverted. Because of inconsistency of the current behavior, even if the currently proposed one won't be landed as is, the ES2015 behavior will be changed anyway. (So, anyway, I think we will be required to change the current form in the future)

1. The current form is not consistent to the class constructor behavior. We cannot define (class A { *constructor() { } }), but the generator is constructible.
2. As described in the https://github.com/tc39/tc39-notes/blob/master/es7/2015-07/july-28.md#67-new--generatorfunction, `new` on the generator does not provide any useful things. |this| becomes TDZ, so we cannot touch the constructed object. And since its body is not the part of the constructor, It will be called when calling next(). So there's no chance to initialize |this| with the constructor (like, setting some properties etc.) even if |this| in `new generatorFunction()` represents the constructed object.
Comment 5 Saam Barati 2015-12-28 13:01:24 PST
Comment on attachment 267926 [details]

Comment 6 WebKit Commit Bot 2015-12-29 03:49:58 PST
Comment on attachment 267926 [details]

Clearing flags on attachment: 267926

Committed r194435: <http://trac.webkit.org/changeset/194435>
Comment 7 WebKit Commit Bot 2015-12-29 03:50:02 PST
All reviewed patches have been landed.  Closing bug.
Comment 8 Yusuke Suzuki 2015-12-29 05:57:06 PST
Reopening to attach new patch.
Comment 9 Yusuke Suzuki 2015-12-29 05:57:10 PST
Created attachment 267984 [details]
Comment 10 Yusuke Suzuki 2015-12-29 05:57:45 PST
Committed r194436: <http://trac.webkit.org/changeset/194436>