Bug 144283

Summary: ES6 classes: super() should throw when extending null
Product: WebKit Reporter: Erik Arvidsson <arv>
Component: JavaScriptCoreAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED INVALID    
Severity: Normal    
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 140491    

Description Erik Arvidsson 2015-04-27 15:26:20 PDT
http://trac.webkit.org/browser/trunk/LayoutTests/js/script-tests/class-syntax-super.js#L59

shouldThrow('new (class extends null { constructor() { super(); return undefined } })', '"TypeError: undefined is not an object (evaluating \'super()\')"');


and

http://trac.webkit.org/browser/trunk/LayoutTests/js/script-tests/class-syntax-super.js#L64

shouldThrow('new (class extends null { constructor() { super() } })', '"TypeError: undefined is not an object (evaluating \'super()\')"');


The reason super() throws is because Function.prototype is not constructable. Your test seems to be testing the return value. It should never get there.
Comment 1 Ryosuke Niwa 2015-04-27 16:07:33 PDT
Oh, this is because of the way I'm retriecving Function.prototype. It is in fact throwing up before calling super() so our behavior is corect.

Thanks for filing all these bugs :)
Comment 2 Erik Arvidsson 2015-04-27 16:28:00 PDT
It is not clear to me that you are throwing at the right spot:

http://people.mozilla.org/~jorendorff/es6-draft.html#sec-super-keyword-runtime-semantics-evaluation

You should throw in step 7/8 in SuperCall : super Arguments

In this case there is no undefined value.
Comment 3 Ryosuke Niwa 2015-04-27 17:20:44 PDT
Yes, that's what's happening (throw in step 7 of 8) You're right that the error message isn't exactly descriptive/informative but I don't feel like I need to improve it since it's such an edge case.

Or do you feel that web devs will end up hitting this error often?
Comment 4 Erik Arvidsson 2015-04-28 07:42:35 PDT
> Or do you feel that web devs will end up hitting this error often?

I don't think this is a common case but the current message is pretty confusing. I assume it is hard coded so you can easily change it?
Comment 5 Ryosuke Niwa 2015-04-28 09:58:04 PDT
No, the problem is that I'm relying on accessing undefined to throw an exception in this case right now, and I'd need to add a runtime branch if I wanted to throw a nicer error message here.