<!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>[195070] 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/195070">195070</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2016-01-14 12:45:48 -0800 (Thu, 14 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[ES6] Support subclassing Function.
https://bugs.webkit.org/show_bug.cgi?id=153081

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

This patch enables subclassing the Function object. It also fixes an existing
bug that prevented users from subclassing functions that have a function in
the superclass's prototype property.

* bytecompiler/NodesCodegen.cpp:
(JSC::ClassExprNode::emitBytecode):
* runtime/FunctionConstructor.cpp:
(JSC::constructWithFunctionConstructor):
(JSC::constructFunction):
(JSC::constructFunctionSkippingEvalEnabledCheck):
* runtime/FunctionConstructor.h:
* runtime/JSFunction.cpp:
(JSC::JSFunction::create):
* runtime/JSFunction.h:
(JSC::JSFunction::createImpl):
* runtime/JSFunctionInlines.h:
(JSC::JSFunction::createWithInvalidatedReallocationWatchpoint):
(JSC::JSFunction::JSFunction): Deleted.
* tests/stress/class-subclassing-function.js: Added.

LayoutTests:

Rebasline tests with the new clearer error message.

* js/class-syntax-extends-expected.txt:
* js/script-tests/class-syntax-extends.js:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsjsclasssyntaxextendsexpectedtxt">trunk/LayoutTests/js/class-syntax-extends-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsclasssyntaxextendsjs">trunk/LayoutTests/js/script-tests/class-syntax-extends.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerNodesCodegencpp">trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeFunctionConstructorcpp">trunk/Source/JavaScriptCore/runtime/FunctionConstructor.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeFunctionConstructorh">trunk/Source/JavaScriptCore/runtime/FunctionConstructor.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSFunctioncpp">trunk/Source/JavaScriptCore/runtime/JSFunction.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSFunctionh">trunk/Source/JavaScriptCore/runtime/JSFunction.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSFunctionInlinesh">trunk/Source/JavaScriptCore/runtime/JSFunctionInlines.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstressclasssubclassingfunctionjs">trunk/Source/JavaScriptCore/tests/stress/class-subclassing-function.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (195069 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-01-14 20:09:51 UTC (rev 195069)
+++ trunk/LayoutTests/ChangeLog        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-01-14  Keith Miller  &lt;keith_miller@apple.com&gt;
+
+        [ES6] Support subclassing Function.
+        https://bugs.webkit.org/show_bug.cgi?id=153081
+
+        Reviewed by Geoffrey Garen.
+
+        Rebasline tests with the new clearer error message.
+
+        * js/class-syntax-extends-expected.txt:
+        * js/script-tests/class-syntax-extends.js:
+
</ins><span class="cx"> 2016-01-14  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         ASSERTION FAILED: !newRelayoutRoot.container() || !newRelayoutRoot.container()-&gt;needsLayout() in WebCore::FrameView::scheduleRelayoutOfSubtree
</span></span></pre></div>
<a id="trunkLayoutTestsjsclasssyntaxextendsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/class-syntax-extends-expected.txt (195069 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-syntax-extends-expected.txt        2016-01-14 20:09:51 UTC (rev 195069)
+++ trunk/LayoutTests/js/class-syntax-extends-expected.txt        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -26,9 +26,9 @@
</span><span class="cx"> PASS x = class extends 3 { constructor() { } }; x.__proto__:::TypeError: The superclass is not an object.
</span><span class="cx"> PASS x = class extends &quot;abc&quot; { constructor() { } }; x.__proto__:::TypeError: The superclass is not an object.
</span><span class="cx"> PASS baseWithBadPrototype = function () {}; baseWithBadPrototype.prototype = 3; new baseWithBadPrototype
</span><del>-PASS x = class extends baseWithBadPrototype { constructor() { } }:::TypeError: The superclass's prototype is not an object.
</del><ins>+PASS x = class extends baseWithBadPrototype { constructor() { } }:::TypeError: The value of the superclass's prototype property is not an object.
</ins><span class="cx"> PASS baseWithBadPrototype.prototype = &quot;abc&quot;
</span><del>-PASS x = class extends baseWithBadPrototype { constructor() { } }:::TypeError: The superclass's prototype is not an object.
</del><ins>+PASS x = class extends baseWithBadPrototype { constructor() { } }:::TypeError: The value of the superclass's prototype property is not an object.
</ins><span class="cx"> PASS baseWithBadPrototype.prototype = null; x = class extends baseWithBadPrototype { constructor() { } }
</span><span class="cx"> PASS x = 1; c = class extends ++x { constructor() { } };:::SyntaxError: Unexpected token '++'
</span><span class="cx"> PASS x = 1; c = class extends x++ { constructor() { } };:::SyntaxError: Unexpected token '++'. Expected opening '{' at the start of a class body.
</span><span class="lines">@@ -48,8 +48,8 @@
</span><span class="cx"> PASS namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends false||null||namespace.A { constructor() { } }:::SyntaxError: Unexpected token '||'. Expected opening '{' at the start of a class body.
</span><span class="cx"> PASS x = 1; namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends (x++, namespace.A) { constructor() { } };
</span><span class="cx"> PASS x = 1; namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends (namespace.A, x++) { constructor() { } };:::TypeError: The superclass is not an object.
</span><del>-PASS namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends new namespace.A { constructor() { } }:::TypeError: The superclass's prototype is not an object.
-PASS namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends new namespace.A() { constructor() { } }:::TypeError: The superclass's prototype is not an object.
</del><ins>+PASS namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends new namespace.A { constructor() { } }:::TypeError: The value of the superclass's prototype property is not an object.
+PASS namespace = {}; namespace.A = class { constructor() { } }; namespace.B = class extends new namespace.A() { constructor() { } }:::TypeError: The value of the superclass's prototype property is not an object.
</ins><span class="cx"> PASS x = 1; namespace = {}; namespace.A = class { constructor() { } }; try { namespace.B = class extends (x++, namespace.A) { constructor() { } } } catch (e) { } x:::2
</span><span class="cx"> PASS x = 1; namespace = {}; namespace.A = class { constructor() { } }; try { namespace.B = class extends (namespace.A, x++) { constructor() { } } } catch (e) { } x:::2
</span><span class="cx"> PASS Object.getPrototypeOf((class { constructor () { } }).prototype):::Object.prototype
</span></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsclasssyntaxextendsjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/class-syntax-extends.js (195069 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/class-syntax-extends.js        2016-01-14 20:09:51 UTC (rev 195069)
+++ trunk/LayoutTests/js/script-tests/class-syntax-extends.js        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -81,9 +81,9 @@
</span><span class="cx"> shouldThrow('x = class extends 3 { constructor() { } }; x.__proto__', '&quot;TypeError: The superclass is not an object.&quot;');
</span><span class="cx"> shouldThrow('x = class extends &quot;abc&quot; { constructor() { } }; x.__proto__', '&quot;TypeError: The superclass is not an object.&quot;');
</span><span class="cx"> shouldNotThrow('baseWithBadPrototype = function () {}; baseWithBadPrototype.prototype = 3; new baseWithBadPrototype');
</span><del>-shouldThrow('x = class extends baseWithBadPrototype { constructor() { } }', '&quot;TypeError: The superclass\'s prototype is not an object.&quot;');
</del><ins>+shouldThrow('x = class extends baseWithBadPrototype { constructor() { } }', '&quot;TypeError: The value of the superclass\'s prototype property is not an object.&quot;');
</ins><span class="cx"> shouldNotThrow('baseWithBadPrototype.prototype = &quot;abc&quot;');
</span><del>-shouldThrow('x = class extends baseWithBadPrototype { constructor() { } }', '&quot;TypeError: The superclass\'s prototype is not an object.&quot;');
</del><ins>+shouldThrow('x = class extends baseWithBadPrototype { constructor() { } }', '&quot;TypeError: The value of the superclass\'s prototype property is not an object.&quot;');
</ins><span class="cx"> shouldNotThrow('baseWithBadPrototype.prototype = null; x = class extends baseWithBadPrototype { constructor() { } }');
</span><span class="cx"> 
</span><span class="cx"> shouldThrow('x = 1; c = class extends ++x { constructor() { } };');
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (195069 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-01-14 20:09:51 UTC (rev 195069)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2016-01-14  Keith Miller  &lt;keith_miller@apple.com&gt;
+
+        [ES6] Support subclassing Function.
+        https://bugs.webkit.org/show_bug.cgi?id=153081
+
+        Reviewed by Geoffrey Garen.
+
+        This patch enables subclassing the Function object. It also fixes an existing
+        bug that prevented users from subclassing functions that have a function in
+        the superclass's prototype property.
+
+        * bytecompiler/NodesCodegen.cpp:
+        (JSC::ClassExprNode::emitBytecode):
+        * runtime/FunctionConstructor.cpp:
+        (JSC::constructWithFunctionConstructor):
+        (JSC::constructFunction):
+        (JSC::constructFunctionSkippingEvalEnabledCheck):
+        * runtime/FunctionConstructor.h:
+        * runtime/JSFunction.cpp:
+        (JSC::JSFunction::create):
+        * runtime/JSFunction.h:
+        (JSC::JSFunction::createImpl):
+        * runtime/JSFunctionInlines.h:
+        (JSC::JSFunction::createWithInvalidatedReallocationWatchpoint):
+        (JSC::JSFunction::JSFunction): Deleted.
+        * tests/stress/class-subclassing-function.js: Added.
+
</ins><span class="cx"> 2016-01-13  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [CMake] Do not use LLVM static libraries for FTL JIT
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerNodesCodegencpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp (195069 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp        2016-01-14 20:09:51 UTC (rev 195069)
+++ trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -3228,7 +3228,8 @@
</span><span class="cx"> 
</span><span class="cx">         RefPtr&lt;Label&gt; protoParentIsObjectOrNullLabel = generator.newLabel();
</span><span class="cx">         generator.emitJumpIfTrue(generator.emitUnaryOp(op_is_object_or_null, tempRegister.get(), protoParent.get()), protoParentIsObjectOrNullLabel.get());
</span><del>-        generator.emitThrowTypeError(ASCIILiteral(&quot;The superclass's prototype is not an object.&quot;));
</del><ins>+        generator.emitJumpIfTrue(generator.emitUnaryOp(op_is_function, tempRegister.get(), protoParent.get()), protoParentIsObjectOrNullLabel.get());
+        generator.emitThrowTypeError(ASCIILiteral(&quot;The value of the superclass's prototype property is not an object.&quot;));
</ins><span class="cx">         generator.emitLabel(protoParentIsObjectOrNullLabel.get());
</span><span class="cx"> 
</span><span class="cx">         generator.emitDirectPutById(constructor.get(), generator.propertyNames().underscoreProto, superclass.get(), PropertyNode::Unknown);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeFunctionConstructorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/FunctionConstructor.cpp (195069 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/FunctionConstructor.cpp        2016-01-14 20:09:51 UTC (rev 195069)
+++ trunk/Source/JavaScriptCore/runtime/FunctionConstructor.cpp        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -56,7 +56,7 @@
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL constructWithFunctionConstructor(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx">     ArgList args(exec);
</span><del>-    return JSValue::encode(constructFunction(exec, asInternalFunction(exec-&gt;callee())-&gt;globalObject(), args));
</del><ins>+    return JSValue::encode(constructFunction(exec, asInternalFunction(exec-&gt;callee())-&gt;globalObject(), args, FunctionConstructionMode::Function, exec-&gt;newTarget()));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ConstructType FunctionConstructor::getConstructData(JSCell*, ConstructData&amp; constructData)
</span><span class="lines">@@ -79,17 +79,17 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // ECMA 15.3.2 The Function Constructor
</span><del>-JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList&amp; args, const Identifier&amp; functionName, const String&amp; sourceURL, const TextPosition&amp; position, FunctionConstructionMode functionConstructionMode)
</del><ins>+JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList&amp; args, const Identifier&amp; functionName, const String&amp; sourceURL, const TextPosition&amp; position, FunctionConstructionMode functionConstructionMode, JSValue newTarget)
</ins><span class="cx"> {
</span><span class="cx">     if (!globalObject-&gt;evalEnabled())
</span><span class="cx">         return exec-&gt;vm().throwException(exec, createEvalError(exec, globalObject-&gt;evalDisabledErrorMessage()));
</span><del>-    return constructFunctionSkippingEvalEnabledCheck(exec, globalObject, args, functionName, sourceURL, position, -1, functionConstructionMode);
</del><ins>+    return constructFunctionSkippingEvalEnabledCheck(exec, globalObject, args, functionName, sourceURL, position, -1, functionConstructionMode, newTarget);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> JSObject* constructFunctionSkippingEvalEnabledCheck(
</span><span class="cx">     ExecState* exec, JSGlobalObject* globalObject, const ArgList&amp; args, 
</span><span class="cx">     const Identifier&amp; functionName, const String&amp; sourceURL, 
</span><del>-    const TextPosition&amp; position, int overrideLineNumber, FunctionConstructionMode functionConstructionMode)
</del><ins>+    const TextPosition&amp; position, int overrideLineNumber, FunctionConstructionMode functionConstructionMode, JSValue newTarget)
</ins><span class="cx"> {
</span><span class="cx">     // How we stringify functions is sometimes important for web compatibility.
</span><span class="cx">     // See https://bugs.webkit.org/show_bug.cgi?id=24350.
</span><span class="lines">@@ -124,13 +124,14 @@
</span><span class="cx">         return exec-&gt;vm().throwException(exec, exception);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    return JSFunction::create(exec-&gt;vm(), function, globalObject);
</del><ins>+
+    return JSFunction::create(exec-&gt;vm(), function, globalObject, InternalFunction::createSubclassStructure(exec, newTarget, globalObject-&gt;functionStructure()));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // ECMA 15.3.2 The Function Constructor
</span><del>-JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList&amp; args, FunctionConstructionMode functionConstructionMode)
</del><ins>+JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList&amp; args, FunctionConstructionMode functionConstructionMode, JSValue newTarget)
</ins><span class="cx"> {
</span><del>-    return constructFunction(exec, globalObject, args, exec-&gt;propertyNames().anonymous, String(), TextPosition::minimumPosition(), functionConstructionMode);
</del><ins>+    return constructFunction(exec, globalObject, args, exec-&gt;propertyNames().anonymous, String(), TextPosition::minimumPosition(), functionConstructionMode, newTarget);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeFunctionConstructorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/FunctionConstructor.h (195069 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/FunctionConstructor.h        2016-01-14 20:09:51 UTC (rev 195069)
+++ trunk/Source/JavaScriptCore/runtime/FunctionConstructor.h        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -61,12 +61,13 @@
</span><span class="cx">     Generator,
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&amp;, const Identifier&amp; functionName, const String&amp; sourceURL, const WTF::TextPosition&amp;, FunctionConstructionMode = FunctionConstructionMode::Function);
-JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&amp;, FunctionConstructionMode = FunctionConstructionMode::Function);
</del><ins>+JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&amp;, const Identifier&amp; functionName, const String&amp; sourceURL, const WTF::TextPosition&amp;, FunctionConstructionMode = FunctionConstructionMode::Function, JSValue newTarget = JSValue());
+JSObject* constructFunction(ExecState*, JSGlobalObject*, const ArgList&amp;, FunctionConstructionMode = FunctionConstructionMode::Function, JSValue newTarget = JSValue());
</ins><span class="cx"> 
</span><span class="cx"> JS_EXPORT_PRIVATE JSObject* constructFunctionSkippingEvalEnabledCheck(
</span><span class="cx">     ExecState*, JSGlobalObject*, const ArgList&amp;, const Identifier&amp;, 
</span><del>-    const String&amp;, const WTF::TextPosition&amp;, int overrideLineNumber = -1, FunctionConstructionMode = FunctionConstructionMode::Function);
</del><ins>+    const String&amp;, const WTF::TextPosition&amp;, int overrideLineNumber = -1,
+    FunctionConstructionMode = FunctionConstructionMode::Function, JSValue newTarget = JSValue());
</ins><span class="cx"> 
</span><span class="cx"> } // namespace JSC
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSFunctioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSFunction.cpp (195069 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSFunction.cpp        2016-01-14 20:09:51 UTC (rev 195069)
+++ trunk/Source/JavaScriptCore/runtime/JSFunction.cpp        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -63,7 +63,12 @@
</span><span class="cx"> 
</span><span class="cx"> JSFunction* JSFunction::create(VM&amp; vm, FunctionExecutable* executable, JSScope* scope)
</span><span class="cx"> {
</span><del>-    JSFunction* result = createImpl(vm, executable, scope);
</del><ins>+    return create(vm, executable, scope, scope-&gt;globalObject()-&gt;functionStructure());
+}
+
+JSFunction* JSFunction::create(VM&amp; vm, FunctionExecutable* executable, JSScope* scope, Structure* structure)
+{
+    JSFunction* result = createImpl(vm, executable, scope, structure);
</ins><span class="cx">     executable-&gt;singletonFunction()-&gt;notifyWrite(vm, result, &quot;Allocating a function&quot;);
</span><span class="cx">     return result;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSFunctionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSFunction.h (195069 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSFunction.h        2016-01-14 20:09:51 UTC (rev 195069)
+++ trunk/Source/JavaScriptCore/runtime/JSFunction.h        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -73,6 +73,7 @@
</span><span class="cx">     static JSFunction* createWithInvalidatedReallocationWatchpoint(VM&amp;, FunctionExecutable*, JSScope*);
</span><span class="cx"> 
</span><span class="cx">     static JSFunction* create(VM&amp;, FunctionExecutable*, JSScope*);
</span><ins>+    static JSFunction* create(VM&amp;, FunctionExecutable*, JSScope*, Structure*);
</ins><span class="cx"> #if ENABLE(WEBASSEMBLY)
</span><span class="cx">     static JSFunction* create(VM&amp;, WebAssemblyExecutable*, JSScope*);
</span><span class="cx"> #endif
</span><span class="lines">@@ -151,7 +152,6 @@
</span><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="cx">     JS_EXPORT_PRIVATE JSFunction(VM&amp;, JSGlobalObject*, Structure*);
</span><del>-    JSFunction(VM&amp;, FunctionExecutable*, JSScope*);
</del><span class="cx">     JSFunction(VM&amp;, FunctionExecutable*, JSScope*, Structure*);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(WEBASSEMBLY)
</span><span class="lines">@@ -179,9 +179,9 @@
</span><span class="cx">     static NativeExecutable* lookUpOrCreateNativeExecutable(VM&amp;, NativeFunction, Intrinsic, NativeFunction nativeConstructor, const String&amp; name);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    static JSFunction* createImpl(VM&amp; vm, FunctionExecutable* executable, JSScope* scope)
</del><ins>+    static JSFunction* createImpl(VM&amp; vm, FunctionExecutable* executable, JSScope* scope, Structure* structure)
</ins><span class="cx">     {
</span><del>-        JSFunction* function = new (NotNull, allocateCell&lt;JSFunction&gt;(vm.heap)) JSFunction(vm, executable, scope);
</del><ins>+        JSFunction* function = new (NotNull, allocateCell&lt;JSFunction&gt;(vm.heap)) JSFunction(vm, executable, scope, structure);
</ins><span class="cx">         ASSERT(function-&gt;structure()-&gt;globalObject());
</span><span class="cx">         function-&gt;finishCreation(vm);
</span><span class="cx">         return function;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSFunctionInlinesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSFunctionInlines.h (195069 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSFunctionInlines.h        2016-01-14 20:09:51 UTC (rev 195069)
+++ trunk/Source/JavaScriptCore/runtime/JSFunctionInlines.h        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -35,16 +35,9 @@
</span><span class="cx">     VM&amp; vm, FunctionExecutable* executable, JSScope* scope)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(executable-&gt;singletonFunction()-&gt;hasBeenInvalidated());
</span><del>-    return createImpl(vm, executable, scope);
</del><ins>+    return createImpl(vm, executable, scope, scope-&gt;globalObject()-&gt;functionStructure());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline JSFunction::JSFunction(VM&amp; vm, FunctionExecutable* executable, JSScope* scope)
-    : Base(vm, scope, scope-&gt;globalObject()-&gt;functionStructure())
-    , m_executable(vm, this, executable)
-    , m_rareData()
-{
-}
-    
</del><span class="cx"> inline JSFunction::JSFunction(VM&amp; vm, FunctionExecutable* executable, JSScope* scope, Structure* structure)
</span><span class="cx">     : Base(vm, scope, structure)
</span><span class="cx">     , m_executable(vm, this, executable)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressclasssubclassingfunctionjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/class-subclassing-function.js (0 => 195070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/class-subclassing-function.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/class-subclassing-function.js        2016-01-14 20:45:48 UTC (rev 195070)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+F = class extends Function { }
+
+function test(i) {
+
+    let f = new F(&quot;x&quot;, &quot;return x + &quot; + i + &quot;;&quot;);
+    let C = new F(&quot;x&quot;, &quot;this.x = x; this.i = &quot; + i);
+
+    if (!(f instanceof Function &amp;&amp; f instanceof F))
+        throw &quot;bad chain&quot;;
+
+    if (f(1) !== i+1)
+        throw &quot;function was not called correctly&quot;;
+
+    let o = new C(&quot;hello&quot;);
+    if (o.x !== &quot;hello&quot; || o.i !== i)
+        throw &quot;function as constructor was not correct&quot;;
+
+    let g = new F(&quot;x&quot;, &quot;y&quot;, &quot;return this.foo + x + y&quot;);
+    if (g.call({foo:1}, 1, 1) !== 3)
+        throw &quot;function was not .callable&quot;;
+
+    let g2 = g.bind({foo:1}, 1);
+    if (g2 instanceof F)
+        throw &quot;the binding of a subclass should not inherit from the original function&quot;;
+
+    if (g2(1) !== 3)
+        throw &quot;binding didn't work&quot;;
+
+}
+noInline(test);
+
+for (i = 0; i &lt; 10000; i++)
+    test(i);
</ins></span></pre>
</div>
</div>

</body>
</html>