Bug 152383

Summary: [ES6][ES7] Drop Constructability of generator function
Product: WebKit Reporter: Yusuke Suzuki <ysuzuki>
Component: JavaScriptCoreAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, commit-queue, fpizlo, ggaren, keith_miller, mark.lam, msaboff, saam
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch none

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.

https://github.com/tc39/ecma262/releases/tag/es2016-draft-20151201
https://github.com/tc39/tc39-notes/blob/master/es7/2015-07/july-28.md#67-new--generatorfunction
https://github.com/tc39/tc39-notes/blob/master/es7/2015-07/july-29.md#revisit-67-new--generatorfunction
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]
Patch
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)
Because,

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]
Patch

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

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]
Patch
Comment 10 Yusuke Suzuki 2015-12-29 05:57:45 PST
Committed r194436: <http://trac.webkit.org/changeset/194436>