Bug 149001

Summary: ES6 classes: When a class extends B, super() invokes B.prototype.constructor() instead of B()
Product: WebKit Reporter: Claude Pache <claude.pache>
Component: JavaScriptCoreAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, fpizlo, ggaren, keith_miller, ljharb, mark.lam, msaboff, rniwa, saam, ysuzuki
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 140491    
Attachments:
Description Flags
Patch
none
Patch none

Description Claude Pache 2015-09-09 07:11:02 PDT
Testcase:

```js
var called = null
class B { constructor() { called = 'B' } }
class C extends B {}
B.prototype.constructor = function F() { called = 'F' }

new C
called // should be 'B', is 'F'

```

It seems to me that JSC follows an old drafted semantics of `super()`, when it was equivalent to `super.constructor()`.


For reference, see the runtime semantics of `SuperCall : super Arguments` in the final spec:

    http://www.ecma-international.org/ecma-262/6.0/#sec-super-keyword-runtime-semantics-evaluation

and pay attention to the definition of GetSuperConstructor():

   http://www.ecma-international.org/ecma-262/6.0/#sec-getsuperconstructor
Comment 1 Yusuke Suzuki 2015-10-11 04:29:31 PDT
Created attachment 262857 [details]
Patch
Comment 2 Yusuke Suzuki 2015-10-11 04:30:56 PDT
Created attachment 262858 [details]
Patch
Comment 3 Saam Barati 2015-10-11 09:55:57 PDT
Comment on attachment 262858 [details]
Patch

r=me
Does the latest spec change the "emitSuperBaseForCallee" static function in BytecodeGenerator?
Comment 4 Yusuke Suzuki 2015-10-11 10:41:07 PDT
(In reply to comment #3)
> Comment on attachment 262858 [details]
> Patch
> 
> r=me
> Does the latest spec change the "emitSuperBaseForCallee" static function in
> BytecodeGenerator?

Yup. emitSuperBaseForCallee is correct in the latest spec :)
http://ecma-international.org/ecma-262/6.0/#sec-getsuperbase
Comment 5 WebKit Commit Bot 2015-10-11 11:47:26 PDT
Comment on attachment 262858 [details]
Patch

Clearing flags on attachment: 262858

Committed r190847: <http://trac.webkit.org/changeset/190847>
Comment 6 WebKit Commit Bot 2015-10-11 11:47:31 PDT
All reviewed patches have been landed.  Closing bug.