<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[181924] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/181924">181924</a></dd>
<dt>Author</dt> <dd>joepeck@webkit.org</dd>
<dt>Date</dt> <dd>2015-03-24 18:18:18 -0700 (Tue, 24 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>ES6: Classes: Early return in sub-class constructor results in returning undefined instead of instance
https://bugs.webkit.org/show_bug.cgi?id=143012

Reviewed by Ryosuke Niwa.

Source/JavaScriptCore:

* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitReturn):
Fix handling of &quot;undefined&quot; when returned from a Derived class. It was
returning &quot;undefined&quot; when it should have returned &quot;this&quot;.

LayoutTests:

* js/class-constructor-return-expected.txt: Added.
* js/class-constructor-return.html: Added.
* js/script-tests/class-constructor-return.js: Added.
New test covering different return values from constructors.

* js/class-syntax-super-expected.txt:
* js/script-tests/class-syntax-super.js:
Fix test. Returning undefined is the same as an implicit return
and should return `this`.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsjsclasssyntaxsuperexpectedtxt">trunk/LayoutTests/js/class-syntax-super-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsclasssyntaxsuperjs">trunk/LayoutTests/js/script-tests/class-syntax-super.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorcpp">trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsclassconstructorreturnexpectedtxt">trunk/LayoutTests/js/class-constructor-return-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsclassconstructorreturnhtml">trunk/LayoutTests/js/class-constructor-return.html</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsclassconstructorreturnjs">trunk/LayoutTests/js/script-tests/class-constructor-return.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (181923 => 181924)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-03-25 00:55:11 UTC (rev 181923)
+++ trunk/LayoutTests/ChangeLog        2015-03-25 01:18:18 UTC (rev 181924)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2015-03-24  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        ES6: Classes: Early return in sub-class constructor results in returning undefined instead of instance
+        https://bugs.webkit.org/show_bug.cgi?id=143012
+
+        Reviewed by Ryosuke Niwa.
+
+        * js/class-constructor-return-expected.txt: Added.
+        * js/class-constructor-return.html: Added.
+        * js/script-tests/class-constructor-return.js: Added.
+        New test covering different return values from constructors.
+
+        * js/class-syntax-super-expected.txt:
+        * js/script-tests/class-syntax-super.js:
+        Fix test. Returning undefined is the same as an implicit return
+        and should return `this`.
+
</ins><span class="cx"> 2015-03-24  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WK2] Responses with 204 HTTP Status Code should be cacheable by default
</span></span></pre></div>
<a id="trunkLayoutTestsjsclassconstructorreturnexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/class-constructor-return-expected.txt (0 => 181924)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-constructor-return-expected.txt                                (rev 0)
+++ trunk/LayoutTests/js/class-constructor-return-expected.txt        2015-03-25 01:18:18 UTC (rev 181924)
</span><span class="lines">@@ -0,0 +1,95 @@
</span><ins>+Tests for ES6 class constructor return values
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Base class
+PASS (new BaseNoReturn) instanceof BaseNoReturn is true
+PASS (new BaseReturnImplicit) instanceof BaseReturnImplicit is true
+PASS (new BaseReturnImplicit) !== undefined is true
+PASS (new BaseReturnUndefined) instanceof BaseReturnUndefined is true
+PASS (new BaseReturnUndefined) !== undefined is true
+PASS (new BaseReturnThis) instanceof BaseReturnThis is true
+PASS (new BaseReturnObject) instanceof BaseReturnObject is false
+PASS typeof (new BaseReturnObject) === &quot;object&quot; is true
+PASS (new BaseReturnObject2) instanceof BaseReturnObject is false
+PASS (new BaseReturnObject2) === globalVariable is true
+PASS (new BaseReturnString) instanceof BaseReturnString is true
+PASS typeof (new BaseReturnString) !== &quot;string&quot; is true
+PASS (new BaseReturnNumber) instanceof BaseReturnNumber is true
+PASS typeof (new BaseReturnNumber) !== &quot;number&quot; is true
+PASS (new BaseReturnNull) instanceof BaseReturnNull is true
+PASS (new BaseReturnNull) !== null is true
+PASS (new BaseReturnSymbol) instanceof BaseReturnSymbol is true
+PASS (new BaseReturnSymbol) !== globalSymbol is true
+PASS (new BaseThrow) threw exception Thrown Exception String.
+
+Function constructor (non-class)
+PASS (new FunctionNoReturn) instanceof FunctionNoReturn is true
+PASS (new FunctionReturnImplicit) instanceof FunctionReturnImplicit is true
+PASS (new FunctionReturnImplicit) !== undefined is true
+PASS (new FunctionReturnUndefined) instanceof FunctionReturnUndefined is true
+PASS (new FunctionReturnUndefined) !== undefined is true
+PASS (new FunctionReturnThis) instanceof FunctionReturnThis is true
+PASS (new FunctionReturnObject) instanceof FunctionReturnObject is false
+PASS typeof (new FunctionReturnObject) === &quot;object&quot; is true
+PASS (new FunctionReturnObject2) instanceof FunctionReturnObject is false
+PASS (new FunctionReturnObject2) === globalVariable is true
+PASS (new FunctionReturnString) instanceof FunctionReturnString is true
+PASS typeof (new FunctionReturnString) !== &quot;string&quot; is true
+PASS (new FunctionReturnNumber) instanceof FunctionReturnNumber is true
+PASS typeof (new FunctionReturnNumber) !== &quot;number&quot; is true
+PASS (new FunctionReturnNull) instanceof FunctionReturnNull is true
+PASS (new FunctionReturnNull) !== null is true
+PASS (new FunctionReturnSymbol) instanceof FunctionReturnSymbol is true
+PASS (new FunctionReturnSymbol) !== globalSymbol is true
+PASS (new FunctionThrow) threw exception Thrown Exception String.
+
+Derived class calling super()
+PASS (new DerivedNoReturn) instanceof DerivedNoReturn is true
+PASS (new DerivedReturnImplicit) instanceof DerivedReturnImplicit is true
+PASS (new DerivedReturnImplicit) !== undefined is true
+PASS (new DerivedReturnUndefined) instanceof DerivedReturnUndefined is true
+PASS (new DerivedReturnUndefined) !== undefined is true
+PASS (new DerivedReturnThis) instanceof DerivedReturnThis is true
+PASS (new DerivedReturnObject) instanceof DerivedReturnObject is false
+PASS typeof (new DerivedReturnObject) === &quot;object&quot; is true
+PASS (new DerivedReturnObject2) instanceof DerivedReturnObject2 is false
+PASS (new DerivedReturnObject2) === globalVariable is true
+PASS (new DerivedReturnString) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
+PASS (new DerivedReturnNumber) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
+PASS (new DerivedReturnNull) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
+PASS (new DerivedReturnSymbol) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
+PASS (new DerivedThrow) threw exception Thrown Exception String.
+
+Derived class not calling super()
+PASS (new DerivedNoSuperNoReturn) threw exception ReferenceError: Cannot access uninitialized variable..
+PASS (new DerivedNoSuperReturnImplicit) threw exception ReferenceError: Can't find variable: DerivedNoSuperReturnImplicit.
+PASS (new DerivedNoSuperReturnUndefined) threw exception ReferenceError: Cannot access uninitialized variable..
+PASS (new DerivedNoSuperReturnThis) threw exception ReferenceError: Cannot access uninitialized variable..
+PASS (new DerivedNoSuperReturnObject) did not throw exception.
+PASS (new DerivedNoSuperReturnObject2) did not throw exception.
+PASS (new DerivedNoSuperReturnString) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
+PASS (new DerivedNoSuperReturnNumber) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
+PASS (new DerivedNoSuperReturnNull) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
+PASS (new DerivedNoSuperReturnSymbol) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
+PASS (new DerivedNoSuperThrow) threw exception Thrown Exception String.
+
+Derived class with default constructor and base class returning different values
+PASS (new DerivedDefaultConstructorWithBaseNoReturn) instanceof DerivedDefaultConstructorWithBaseNoReturn is true
+PASS (new DerivedDefaultConstructorWithBaseReturnImplicit) instanceof DerivedDefaultConstructorWithBaseReturnImplicit is true
+PASS (new DerivedDefaultConstructorWithBaseReturnUndefined) instanceof DerivedDefaultConstructorWithBaseReturnUndefined is true
+PASS (new DerivedDefaultConstructorWithBaseReturnObject) instanceof DerivedDefaultConstructorWithBaseReturnObject is false
+PASS typeof (new DerivedDefaultConstructorWithBaseReturnObject) === &quot;object&quot; is true
+PASS (new DerivedDefaultConstructorWithBaseReturnObject2) instanceof DerivedDefaultConstructorWithBaseReturnObject2 is false
+PASS (new DerivedDefaultConstructorWithBaseReturnObject2) === globalVariable is true
+PASS (new DerivedDefaultConstructorWithBaseReturnThis) instanceof DerivedDefaultConstructorWithBaseReturnThis is true
+PASS (new DerivedDefaultConstructorWithBaseReturnString) instanceof DerivedDefaultConstructorWithBaseReturnString is true
+PASS (new DerivedDefaultConstructorWithBaseReturnNumber) instanceof DerivedDefaultConstructorWithBaseReturnNumber is true
+PASS (new DerivedDefaultConstructorWithBaseReturnNull) instanceof DerivedDefaultConstructorWithBaseReturnNull is true
+PASS (new DerivedDefaultConstructorWithBaseReturnSymbol) instanceof DerivedDefaultConstructorWithBaseReturnSymbol is true
+PASS (new DerivedDefaultConstructorWithBaseThrow) threw exception Thrown Exception String.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsclassconstructorreturnhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/class-constructor-return.html (0 => 181924)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-constructor-return.html                                (rev 0)
+++ trunk/LayoutTests/js/class-constructor-return.html        2015-03-25 01:18:18 UTC (rev 181924)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;script src=&quot;../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;script-tests/class-constructor-return.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsjsclasssyntaxsuperexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/class-syntax-super-expected.txt (181923 => 181924)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-syntax-super-expected.txt        2015-03-25 00:55:11 UTC (rev 181923)
+++ trunk/LayoutTests/js/class-syntax-super-expected.txt        2015-03-25 01:18:18 UTC (rev 181924)
</span><span class="lines">@@ -24,12 +24,14 @@
</span><span class="cx"> PASS (new x).method2() threw exception ReferenceError: Cannot delete a super property.
</span><span class="cx"> PASS new (class { constructor() { return undefined; } }) instanceof Object is true
</span><span class="cx"> PASS new (class { constructor() { return 1; } }) instanceof Object is true
</span><del>-PASS new (class extends Base { constructor() { return undefined } }) is undefined
</del><ins>+PASS new (class extends Base { constructor() { return undefined } }) threw exception ReferenceError: Cannot access uninitialized variable..
+PASS new (class extends Base { constructor() { super(); return undefined } }) instanceof Object is true
</ins><span class="cx"> PASS x = { }; new (class extends Base { constructor() { return x } }); is x
</span><span class="cx"> PASS x instanceof Base is false
</span><span class="cx"> PASS new (class extends Base { constructor() { } }) threw exception ReferenceError: Cannot access uninitialized variable..
</span><span class="cx"> PASS new (class extends Base { constructor() { return 1; } }) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
</span><del>-PASS new (class extends null { constructor() { return undefined } }) is undefined
</del><ins>+PASS new (class extends null { constructor() { return undefined } }) threw exception ReferenceError: Cannot access uninitialized variable..
+PASS new (class extends null { constructor() { super(); return undefined } }) instanceof Object is true
</ins><span class="cx"> PASS x = { }; new (class extends null { constructor() { return x } }); is x
</span><span class="cx"> PASS x instanceof Object is true
</span><span class="cx"> PASS new (class extends null { constructor() { } }) threw exception ReferenceError: Cannot access uninitialized variable..
</span></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsclassconstructorreturnjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/script-tests/class-constructor-return.js (0 => 181924)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/class-constructor-return.js                                (rev 0)
+++ trunk/LayoutTests/js/script-tests/class-constructor-return.js        2015-03-25 01:18:18 UTC (rev 181924)
</span><span class="lines">@@ -0,0 +1,192 @@
</span><ins>+description('Tests for ES6 class constructor return values');
+
+// ES6
+// - 9.2.2 [[Construct]] (ECMAScript Function Objects)
+// - 12.3.5.1 Runtime Semantics: Evaluation (The super Keyword)
+// - 14.5.14 Runtime Semantics: ClassDefinitionEvaluation (Default Constructor)
+
+var globalVariable = {name:&quot;globalVariable&quot;};
+var globalSymbol = Symbol();
+
+debug('Base class');
+class BaseNoReturn { constructor() { } };
+class BaseReturnImplicit { constructor() { return; } };
+class BaseReturnUndefined { constructor() { return undefined; } };
+class BaseReturnThis { constructor() { return this; } };
+class BaseReturnObject { constructor() { return {a:1}; } };
+class BaseReturnObject2 { constructor() { return globalVariable; } };
+class BaseReturnString { constructor() { return &quot;test&quot;; } };
+class BaseReturnNumber { constructor() { return 1; } };
+class BaseReturnNull { constructor() { return null; } };
+class BaseReturnSymbol { constructor() { return Symbol(); } };
+class BaseThrow { constructor() { throw &quot;Thrown Exception String&quot;; } };
+
+// Base - Implicit =&gt; return this.
+shouldBeTrue('(new BaseNoReturn) instanceof BaseNoReturn');
+
+// Base - Early return =&gt; return this.
+shouldBeTrue('(new BaseReturnImplicit) instanceof BaseReturnImplicit');
+shouldBeTrue('(new BaseReturnImplicit) !== undefined');
+shouldBeTrue('(new BaseReturnUndefined) instanceof BaseReturnUndefined');
+shouldBeTrue('(new BaseReturnUndefined) !== undefined');
+
+// Base - return this =&gt; return this.
+shouldBeTrue('(new BaseReturnThis) instanceof BaseReturnThis');
+
+// Base - return Object =&gt; return object, not instance.
+shouldBeFalse('(new BaseReturnObject) instanceof BaseReturnObject');
+shouldBeTrue('typeof (new BaseReturnObject) === &quot;object&quot;');
+shouldBeFalse('(new BaseReturnObject2) instanceof BaseReturnObject');
+shouldBeTrue('(new BaseReturnObject2) === globalVariable');
+
+// Base - return non-Object =&gt; return this.
+shouldBeTrue('(new BaseReturnString) instanceof BaseReturnString');
+shouldBeTrue('typeof (new BaseReturnString) !== &quot;string&quot;');
+shouldBeTrue('(new BaseReturnNumber) instanceof BaseReturnNumber');
+shouldBeTrue('typeof (new BaseReturnNumber) !== &quot;number&quot;');
+shouldBeTrue('(new BaseReturnNull) instanceof BaseReturnNull');
+shouldBeTrue('(new BaseReturnNull) !== null');
+shouldBeTrue('(new BaseReturnSymbol) instanceof BaseReturnSymbol');
+shouldBeTrue('(new BaseReturnSymbol) !== globalSymbol');
+
+// Base - throw =&gt; throw
+shouldThrow('(new BaseThrow)');
+
+// Same behavior for Functions.
+debug(''); debug('Function constructor (non-class)');
+function FunctionNoReturn() { };
+function FunctionReturnImplicit() { return; };
+function FunctionReturnUndefined() { return undefined; };
+function FunctionReturnThis() { return this; };
+function FunctionReturnObject() { return {a:1}; };
+function FunctionReturnObject2() { return globalVariable; };
+function FunctionReturnString() { return &quot;test&quot;; };
+function FunctionReturnNumber() { return 1; };
+function FunctionReturnNull() { return null; };
+function FunctionReturnSymbol() { return Symbol(); };
+function FunctionThrow() { throw &quot;Thrown Exception String&quot;; };
+
+shouldBeTrue('(new FunctionNoReturn) instanceof FunctionNoReturn');
+shouldBeTrue('(new FunctionReturnImplicit) instanceof FunctionReturnImplicit');
+shouldBeTrue('(new FunctionReturnImplicit) !== undefined');
+shouldBeTrue('(new FunctionReturnUndefined) instanceof FunctionReturnUndefined');
+shouldBeTrue('(new FunctionReturnUndefined) !== undefined');
+shouldBeTrue('(new FunctionReturnThis) instanceof FunctionReturnThis');
+shouldBeFalse('(new FunctionReturnObject) instanceof FunctionReturnObject');
+shouldBeTrue('typeof (new FunctionReturnObject) === &quot;object&quot;');
+shouldBeFalse('(new FunctionReturnObject2) instanceof FunctionReturnObject');
+shouldBeTrue('(new FunctionReturnObject2) === globalVariable');
+shouldBeTrue('(new FunctionReturnString) instanceof FunctionReturnString');
+shouldBeTrue('typeof (new FunctionReturnString) !== &quot;string&quot;');
+shouldBeTrue('(new FunctionReturnNumber) instanceof FunctionReturnNumber');
+shouldBeTrue('typeof (new FunctionReturnNumber) !== &quot;number&quot;');
+shouldBeTrue('(new FunctionReturnNull) instanceof FunctionReturnNull');
+shouldBeTrue('(new FunctionReturnNull) !== null');
+shouldBeTrue('(new FunctionReturnSymbol) instanceof FunctionReturnSymbol');
+shouldBeTrue('(new FunctionReturnSymbol) !== globalSymbol');
+shouldThrow('(new FunctionThrow)');
+
+
+debug(''); debug('Derived class calling super()');
+class DerivedNoReturn extends BaseNoReturn { constructor() { super(); } };
+class DerivedReturnImplicit extends BaseNoReturn { constructor() { super(); return; } };
+class DerivedReturnUndefined extends BaseNoReturn { constructor() { super(); return undefined; } };
+class DerivedReturnThis extends BaseNoReturn { constructor() { super(); return this; } };
+class DerivedReturnObject extends BaseNoReturn { constructor() { super(); return {a:1}; } };
+class DerivedReturnObject2 extends BaseNoReturn { constructor() { super(); return globalVariable; } };
+class DerivedReturnString extends BaseNoReturn { constructor() { super(); return &quot;test&quot;; } };
+class DerivedReturnNumber extends BaseNoReturn { constructor() { super(); return 1; } };
+class DerivedReturnNull extends BaseNoReturn { constructor() { super(); return null; } };
+class DerivedReturnSymbol extends BaseNoReturn { constructor() { super(); return globalSymbol; } };
+class DerivedThrow extends BaseNoReturn { constructor() { super(); throw &quot;Thrown Exception String&quot;; } };
+
+// Derived - Implicit =&gt; return this.
+shouldBeTrue('(new DerivedNoReturn) instanceof DerivedNoReturn');
+
+// Derived - Early return =&gt; return this.
+shouldBeTrue('(new DerivedReturnImplicit) instanceof DerivedReturnImplicit');
+shouldBeTrue('(new DerivedReturnImplicit) !== undefined');
+shouldBeTrue('(new DerivedReturnUndefined) instanceof DerivedReturnUndefined');
+shouldBeTrue('(new DerivedReturnUndefined) !== undefined');
+
+// Derived - return this =&gt; return this.
+shouldBeTrue('(new DerivedReturnThis) instanceof DerivedReturnThis');
+
+// Derived - return Object =&gt; return object, not instance.
+shouldBeFalse('(new DerivedReturnObject) instanceof DerivedReturnObject');
+shouldBeTrue('typeof (new DerivedReturnObject) === &quot;object&quot;');
+shouldBeFalse('(new DerivedReturnObject2) instanceof DerivedReturnObject2');
+shouldBeTrue('(new DerivedReturnObject2) === globalVariable');
+
+// Derived - return non-Object =&gt; exception.
+shouldThrow('(new DerivedReturnString)');
+shouldThrow('(new DerivedReturnNumber)');
+shouldThrow('(new DerivedReturnNull)');
+shouldThrow('(new DerivedReturnSymbol)');
+shouldThrow('(new DerivedThrow)');
+
+
+debug(''); debug('Derived class not calling super()');
+class DerivedNoSuperNoReturn extends BaseNoReturn { constructor() { } };
+class DerivedNoSuperReturn extends BaseNoReturn { constructor() { return; } };
+class DerivedNoSuperReturnUndefined extends BaseNoReturn { constructor() { return undefined; } };
+class DerivedNoSuperReturnObject extends BaseNoReturn { constructor() { return {a:1}; } };
+class DerivedNoSuperReturnObject2 extends BaseNoReturn { constructor() { return globalVariable; } };
+class DerivedNoSuperReturnThis extends BaseNoReturn { constructor() { return this; } };
+class DerivedNoSuperReturnString extends BaseNoReturn { constructor() { return &quot;test&quot;; } };
+class DerivedNoSuperReturnNumber extends BaseNoReturn { constructor() { return 1; } };
+class DerivedNoSuperReturnNull extends BaseNoReturn { constructor() { return null; } };
+class DerivedNoSuperReturnSymbol extends BaseNoReturn { constructor() { return globalSymbol; } };
+class DerivedNoSuperThrow extends BaseNoReturn { constructor() { throw &quot;Thrown Exception String&quot;; } };
+
+// Derived without super() - Implicit =&gt; return this =&gt; TDZ.
+shouldThrow('(new DerivedNoSuperNoReturn)');
+
+// Derived without super() - Early return =&gt; return this =&gt; TDZ.
+shouldThrow('(new DerivedNoSuperReturnImplicit)');
+shouldThrow('(new DerivedNoSuperReturnUndefined)');
+
+// Derived without super() - return this =&gt; return this =&gt; TDZ
+shouldThrow('(new DerivedNoSuperReturnThis)');
+
+// Derived without super() - return Object =&gt; no this access =&gt; return object, not instance
+shouldNotThrow('(new DerivedNoSuperReturnObject)');
+shouldNotThrow('(new DerivedNoSuperReturnObject2)');
+
+// Derived without super() - return non-Object =&gt; exception
+shouldThrow('(new DerivedNoSuperReturnString)'); // TypeError
+shouldThrow('(new DerivedNoSuperReturnNumber)'); // TypeError
+shouldThrow('(new DerivedNoSuperReturnNull)'); // TypeError
+shouldThrow('(new DerivedNoSuperReturnSymbol)'); // TypeError
+shouldThrow('(new DerivedNoSuperThrow)'); // Thrown exception
+
+
+debug(''); debug('Derived class with default constructor and base class returning different values');
+class DerivedDefaultConstructorWithBaseNoReturn extends BaseNoReturn { };
+class DerivedDefaultConstructorWithBaseReturnImplicit extends BaseReturnImplicit { };
+class DerivedDefaultConstructorWithBaseReturnUndefined extends BaseReturnUndefined { };
+class DerivedDefaultConstructorWithBaseReturnThis extends BaseReturnThis { };
+class DerivedDefaultConstructorWithBaseReturnObject extends BaseReturnObject { };
+class DerivedDefaultConstructorWithBaseReturnObject2 extends BaseReturnObject2 { };
+class DerivedDefaultConstructorWithBaseReturnString extends BaseReturnString { };
+class DerivedDefaultConstructorWithBaseReturnNumber extends BaseReturnNumber { };
+class DerivedDefaultConstructorWithBaseReturnNull extends BaseReturnNull { };
+class DerivedDefaultConstructorWithBaseReturnSymbol extends BaseReturnSymbol { };
+class DerivedDefaultConstructorWithBaseThrow extends BaseThrow { };
+
+// Derived default constructor - implicit &quot;super(...arguments)&quot; return the result of the base (Object or this).
+shouldBeTrue('(new DerivedDefaultConstructorWithBaseNoReturn) instanceof DerivedDefaultConstructorWithBaseNoReturn');
+shouldBeTrue('(new DerivedDefaultConstructorWithBaseReturnImplicit) instanceof DerivedDefaultConstructorWithBaseReturnImplicit');
+shouldBeTrue('(new DerivedDefaultConstructorWithBaseReturnUndefined) instanceof DerivedDefaultConstructorWithBaseReturnUndefined');
+shouldBeFalse('(new DerivedDefaultConstructorWithBaseReturnObject) instanceof DerivedDefaultConstructorWithBaseReturnObject');
+shouldBeTrue('typeof (new DerivedDefaultConstructorWithBaseReturnObject) === &quot;object&quot;');
+shouldBeFalse('(new DerivedDefaultConstructorWithBaseReturnObject2) instanceof DerivedDefaultConstructorWithBaseReturnObject2');
+shouldBeTrue('(new DerivedDefaultConstructorWithBaseReturnObject2) === globalVariable');
+shouldBeTrue('(new DerivedDefaultConstructorWithBaseReturnThis) instanceof DerivedDefaultConstructorWithBaseReturnThis');
+shouldBeTrue('(new DerivedDefaultConstructorWithBaseReturnString) instanceof DerivedDefaultConstructorWithBaseReturnString');
+shouldBeTrue('(new DerivedDefaultConstructorWithBaseReturnNumber) instanceof DerivedDefaultConstructorWithBaseReturnNumber');
+shouldBeTrue('(new DerivedDefaultConstructorWithBaseReturnNull) instanceof DerivedDefaultConstructorWithBaseReturnNull');
+shouldBeTrue('(new DerivedDefaultConstructorWithBaseReturnSymbol) instanceof DerivedDefaultConstructorWithBaseReturnSymbol');
+shouldThrow('(new DerivedDefaultConstructorWithBaseThrow)');
+
+var successfullyParsed = true;
</ins></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsclasssyntaxsuperjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/class-syntax-super.js (181923 => 181924)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/class-syntax-super.js        2015-03-25 00:55:11 UTC (rev 181923)
+++ trunk/LayoutTests/js/script-tests/class-syntax-super.js        2015-03-25 01:18:18 UTC (rev 181924)
</span><span class="lines">@@ -49,12 +49,14 @@
</span><span class="cx"> shouldThrow('(new x).method2()', '&quot;ReferenceError: Cannot delete a super property&quot;');
</span><span class="cx"> shouldBeTrue('new (class { constructor() { return undefined; } }) instanceof Object');
</span><span class="cx"> shouldBeTrue('new (class { constructor() { return 1; } }) instanceof Object');
</span><del>-shouldBe('new (class extends Base { constructor() { return undefined } })', 'undefined');
</del><ins>+shouldThrow('new (class extends Base { constructor() { return undefined } })');
+shouldBeTrue('new (class extends Base { constructor() { super(); return undefined } }) instanceof Object');
</ins><span class="cx"> shouldBe('x = { }; new (class extends Base { constructor() { return x } });', 'x');
</span><span class="cx"> shouldBeFalse('x instanceof Base');
</span><span class="cx"> shouldThrow('new (class extends Base { constructor() { } })', '&quot;ReferenceError: Cannot access uninitialized variable.&quot;');
</span><span class="cx"> shouldThrow('new (class extends Base { constructor() { return 1; } })', '&quot;TypeError: Cannot return a non-object type in the constructor of a derived class.&quot;');
</span><del>-shouldBe('new (class extends null { constructor() { return undefined } })', 'undefined');
</del><ins>+shouldThrow('new (class extends null { constructor() { return undefined } })');
+shouldBeTrue('new (class extends null { constructor() { super(); return undefined } }) instanceof Object');
</ins><span class="cx"> shouldBe('x = { }; new (class extends null { constructor() { return x } });', 'x');
</span><span class="cx"> shouldBeTrue('x instanceof Object');
</span><span class="cx"> shouldThrow('new (class extends null { constructor() { } })', '&quot;ReferenceError: Cannot access uninitialized variable.&quot;');
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (181923 => 181924)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-03-25 00:55:11 UTC (rev 181923)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-03-25 01:18:18 UTC (rev 181924)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2015-03-24  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        ES6: Classes: Early return in sub-class constructor results in returning undefined instead of instance
+        https://bugs.webkit.org/show_bug.cgi?id=143012
+
+        Reviewed by Ryosuke Niwa.
+
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::emitReturn):
+        Fix handling of &quot;undefined&quot; when returned from a Derived class. It was
+        returning &quot;undefined&quot; when it should have returned &quot;this&quot;.
+
</ins><span class="cx"> 2015-03-24  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r181458): Heap use-after-free in JSSetIterator destructor
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp (181923 => 181924)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp        2015-03-25 00:55:11 UTC (rev 181923)
+++ trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp        2015-03-25 01:18:18 UTC (rev 181924)
</span><span class="lines">@@ -1930,24 +1930,28 @@
</span><span class="cx">         instructions().append(m_lexicalEnvironmentRegister ? m_lexicalEnvironmentRegister-&gt;index() : emitLoad(0, JSValue())-&gt;index());
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    bool thisMightBeUninitialized = constructorKind() == ConstructorKind::Derived;
-    bool srcIsThis = src-&gt;index() == m_thisRegister.index();
-    if (isConstructor() &amp;&amp; (!srcIsThis || thisMightBeUninitialized)) {
-        RefPtr&lt;Label&gt; isObjectOrUndefinedLabel = newLabel();
-
-        if (srcIsThis &amp;&amp; thisMightBeUninitialized)
</del><ins>+    if (isConstructor()) {
+        bool derived = constructorKind() == ConstructorKind::Derived;
+        if (derived &amp;&amp; src-&gt;index() == m_thisRegister.index())
</ins><span class="cx">             emitTDZCheck(src);
</span><span class="cx"> 
</span><del>-        emitJumpIfTrue(emitIsObject(newTemporary(), src), isObjectOrUndefinedLabel.get());
</del><ins>+        RefPtr&lt;Label&gt; isObjectLabel = newLabel();
+        emitJumpIfTrue(emitIsObject(newTemporary(), src), isObjectLabel.get());
</ins><span class="cx"> 
</span><del>-        if (thisMightBeUninitialized) {
-            emitJumpIfTrue(emitIsUndefined(newTemporary(), src), isObjectOrUndefinedLabel.get());
</del><ins>+        if (derived) {
+            RefPtr&lt;Label&gt; isUndefinedLabel = newLabel();
+            emitJumpIfTrue(emitIsUndefined(newTemporary(), src), isUndefinedLabel.get());
</ins><span class="cx">             emitThrowTypeError(&quot;Cannot return a non-object type in the constructor of a derived class.&quot;);
</span><del>-        } else
-            emitUnaryNoDstOp(op_ret, &amp;m_thisRegister);
</del><ins>+            emitLabel(isUndefinedLabel.get());
+            if (constructorKind() == ConstructorKind::Derived)
+                emitTDZCheck(&amp;m_thisRegister);
+        }
</ins><span class="cx"> 
</span><del>-        emitLabel(isObjectOrUndefinedLabel.get());
</del><ins>+        emitUnaryNoDstOp(op_ret, &amp;m_thisRegister);
+
+        emitLabel(isObjectLabel.get());
</ins><span class="cx">     }
</span><ins>+
</ins><span class="cx">     return emitUnaryNoDstOp(op_ret, src);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>