WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
143012
ES6: Classes: Early return in sub-class constructor results in returning undefined instead of instance
https://bugs.webkit.org/show_bug.cgi?id=143012
Summary
ES6: Classes: Early return in sub-class constructor results in returning unde...
Joseph Pecoraro
Reported
2015-03-24 12:53:52 PDT
* SUMMARY Early return in sub-class constructor results in returning undefined instead of instance * TEST <script> class Base { constructor(){ return; } } class Derived extends Base { constructor() { super(); // This early return breaks things. return; } } var x = new Derived; console.log(x); // undefined, should be new Derived. </script> * EXPECTED Derived instance in `x`. * ACTUAL undefined in `x`.
Attachments
[PATCH] Proposed Fix
(26.31 KB, patch)
2015-03-24 18:02 PDT
,
Joseph Pecoraro
rniwa
: review+
rniwa
: commit-queue-
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Joseph Pecoraro
Comment 1
2015-03-24 13:13:42 PDT
I think the relevant portion is [[Construct]]:
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-function-objects-construct-argumentslist-newtarget
Which has:
> 13. If result.[[type]] is return, then > a. If Type(result.[[value]]) is Object, return NormalCompletion(result.[[value]]). > b. If kind is "base", return NormalCompletion(thisArgument). > c. If result.[[value]] is not undefined, throw a TypeError exception. > 14. Else, ReturnIfAbrupt(result). > 15. Return envRec.GetThisBinding().
That seems weird to me. It sounds like if you early return from a base class constructor, you will get the "thisArgument". And if you early return from a derived class constructor we return "envRec.GetThisBinding()". Either way, my interpretation is that if we do an implicit return of undefined, we would get some "this" object.
Joseph Pecoraro
Comment 2
2015-03-24 14:13:15 PDT
I think I see the issue. I'll investigate.
Joseph Pecoraro
Comment 3
2015-03-24 18:02:58 PDT
Created
attachment 249370
[details]
[PATCH] Proposed Fix
Ryosuke Niwa
Comment 4
2015-03-24 18:10:46 PDT
Comment on
attachment 249370
[details]
[PATCH] Proposed Fix View in context:
https://bugs.webkit.org/attachment.cgi?id=249370&action=review
> Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:1943 > + if (!derived) > + emitUnaryNoDstOp(op_ret, &m_thisRegister); > + else {
I think this reads better if we checked if (derived) and put emitUnaryNoDstOp(op_ret, &m_thisRegister); after the if block.
Joseph Pecoraro
Comment 5
2015-03-24 18:19:28 PDT
http://trac.webkit.org/changeset/181924
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug