<!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>[181611] 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/181611">181611</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2015-03-16 21:02:52 -0700 (Mon, 16 Mar 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Source/JavaScriptCore:
Add support for default constructor
https://bugs.webkit.org/show_bug.cgi?id=142388
Reviewed by Filip Pizlo.
Added the support for default constructors. They're generated by ClassExprNode::emitBytecode
via BuiltinExecutables::createDefaultConstructor.
UnlinkedFunctionExecutable now has the ability to override SourceCode provided by the owner
executable. We can't make store SourceCode in UnlinkedFunctionExecutable since CodeCache can use
the same UnlinkedFunctionExecutable to generate code blocks for multiple functions.
Parser now has the ability to treat any function expression as a constructor of the kind specified
by m_defaultConstructorKind member variable.
* builtins/BuiltinExecutables.cpp:
(JSC::BuiltinExecutables::createDefaultConstructor): Added.
(JSC::BuiltinExecutables::createExecutableInternal): Generalized from createBuiltinExecutable.
Parse default constructors as normal non-builtin functions. Override SourceCode in the unlinked
function executable since the Miranda function's code is definitely not in the owner executable's
source code. That's the whole point.
* builtins/BuiltinExecutables.h:
(UnlinkedFunctionExecutable::createBuiltinExecutable): Added. Wraps createExecutableInternal.
* bytecode/UnlinkedCodeBlock.cpp:
(JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
(JSC::UnlinkedFunctionExecutable::linkInsideExecutable):
(JSC::UnlinkedFunctionExecutable::linkGlobalCode):
* bytecode/UnlinkedCodeBlock.h:
(JSC::UnlinkedFunctionExecutable::create):
(JSC::UnlinkedFunctionExecutable::symbolTable): Deleted.
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitNewDefaultConstructor): Added.
* bytecompiler/BytecodeGenerator.h:
* bytecompiler/NodesCodegen.cpp:
(JSC::ClassExprNode::emitBytecode): Generate the default constructor if needed.
* parser/Parser.cpp:
(JSC::Parser<LexerType>::Parser):
(JSC::Parser<LexerType>::parseFunctionInfo): Override ownerClassKind and assume the function as
a constructor if we're parsing a default constructor.
(JSC::Parser<LexerType>::parseClass): Allow omission of the class constructor.
* parser/Parser.h:
(JSC::parse):
LayoutTests:
Implement default constructor
Add support for default constructor
https://bugs.webkit.org/show_bug.cgi?id=142388
Reviewed by Filip Pizlo.
Added tests for default constructors.
* TestExpectations: Skipped the test since ES6 class syntax isn't enabled by default.
* js/class-syntax-default-constructor-expected.txt: Added.
* js/class-syntax-default-constructor.html: Added.
* js/script-tests/class-syntax-default-constructor.js: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsTestExpectations">trunk/LayoutTests/TestExpectations</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebuiltinsBuiltinExecutablescpp">trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorebuiltinsBuiltinExecutablesh">trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.h</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeUnlinkedCodeBlockcpp">trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeUnlinkedCodeBlockh">trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorcpp">trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorh">trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerNodesCodegencpp">trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserParsercpp">trunk/Source/JavaScriptCore/parser/Parser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserParserh">trunk/Source/JavaScriptCore/parser/Parser.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsclasssyntaxdefaultconstructorexpectedtxt">trunk/LayoutTests/js/class-syntax-default-constructor-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsclasssyntaxdefaultconstructorhtml">trunk/LayoutTests/js/class-syntax-default-constructor.html</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsclasssyntaxdefaultconstructorjs">trunk/LayoutTests/js/script-tests/class-syntax-default-constructor.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/LayoutTests/ChangeLog        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2015-03-16 Ryosuke Niwa <rniwa@webkit.org>
+
+ Implement default constructor
+
+ Add support for default constructor
+ https://bugs.webkit.org/show_bug.cgi?id=142388
+
+ Reviewed by Filip Pizlo.
+
+ Added tests for default constructors.
+
+ * TestExpectations: Skipped the test since ES6 class syntax isn't enabled by default.
+ * js/class-syntax-default-constructor-expected.txt: Added.
+ * js/class-syntax-default-constructor.html: Added.
+ * js/script-tests/class-syntax-default-constructor.js: Added.
+
</ins><span class="cx"> 2015-03-16 Hunseop Jeong <hs85.jeong@samsung.com>
</span><span class="cx">
</span><span class="cx"> [EFL] fast/css/outline-auto-empty-rects.html is failing
</span></span></pre></div>
<a id="trunkLayoutTestsTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/TestExpectations (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/TestExpectations        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/LayoutTests/TestExpectations        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -69,6 +69,7 @@
</span><span class="cx"> # ES6 class syntax hasn't been enabled yet.
</span><span class="cx"> webkit.org/b/140491 js/class-syntax-call.html [ Failure ]
</span><span class="cx"> webkit.org/b/140491 js/class-syntax-declaration.html [ Failure ]
</span><ins>+webkit.org/b/140491 js/class-syntax-default-constructor.html [ Failure ]
</ins><span class="cx"> webkit.org/b/140491 js/class-syntax-expression.html [ Failure ]
</span><span class="cx"> webkit.org/b/140491 js/class-syntax-extends.html [ Failure ]
</span><span class="cx"> webkit.org/b/140491 js/class-syntax-scoping.html [ Failure ]
</span></span></pre></div>
<a id="trunkLayoutTestsjsclasssyntaxdefaultconstructorexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/class-syntax-default-constructor-expected.txt (0 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-syntax-default-constructor-expected.txt         (rev 0)
+++ trunk/LayoutTests/js/class-syntax-default-constructor-expected.txt        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+Tests for ES6 class syntax default constructor
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS class A { }; window.A = A; new A instanceof A is true
+PASS A() threw exception TypeError: Cannot call a class constructor.
+PASS A.prototype.constructor instanceof Function is true
+PASS A.prototype.constructor.name is "A"
+PASS class B extends A { }; new B instanceof A; new B instanceof A is true
+PASS B() threw exception TypeError: Cannot call a class constructor.
+PASS B.prototype.constructor.name is "B"
+PASS A is not B
+FAIL A.prototype.constructor should be function B() { super(...arguments); }. Was function A() { }.
+PASS new (class extends (class { constructor(a, b) { return [a, b]; } }) {})(1, 2) is [1, 2]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsclasssyntaxdefaultconstructorhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/class-syntax-default-constructor.html (0 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-syntax-default-constructor.html         (rev 0)
+++ trunk/LayoutTests/js/class-syntax-default-constructor.html        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<body>
+<script src="../resources/js-test-pre.js"></script>
+<script src="script-tests/class-syntax-default-constructor.js"></script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsclasssyntaxdefaultconstructorjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/script-tests/class-syntax-default-constructor.js (0 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/class-syntax-default-constructor.js         (rev 0)
+++ trunk/LayoutTests/js/script-tests/class-syntax-default-constructor.js        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -0,0 +1,16 @@
</span><ins>+//@ skip
+
+description('Tests for ES6 class syntax default constructor');
+
+shouldBeTrue('class A { }; window.A = A; new A instanceof A');
+shouldThrow('A()', '"TypeError: Cannot call a class constructor"');
+shouldBeTrue('A.prototype.constructor instanceof Function');
+shouldBe('A.prototype.constructor.name', '"A"');
+shouldBeTrue('class B extends A { }; new B instanceof A; new B instanceof A');
+shouldThrow('B()', '"TypeError: Cannot call a class constructor"');
+shouldBe('B.prototype.constructor.name', '"B"');
+shouldNotBe('A', 'B');
+shouldBe('A.prototype.constructor', 'B.prototype.constructor');
+shouldBe('new (class extends (class { constructor(a, b) { return [a, b]; } }) {})(1, 2)', '[1, 2]');
+
+var successfullyParsed = true;
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -1,3 +1,48 @@
</span><ins>+2015-03-16 Ryosuke Niwa <rniwa@webkit.org>
+
+ Add support for default constructor
+ https://bugs.webkit.org/show_bug.cgi?id=142388
+
+ Reviewed by Filip Pizlo.
+
+ Added the support for default constructors. They're generated by ClassExprNode::emitBytecode
+ via BuiltinExecutables::createDefaultConstructor.
+
+ UnlinkedFunctionExecutable now has the ability to override SourceCode provided by the owner
+ executable. We can't make store SourceCode in UnlinkedFunctionExecutable since CodeCache can use
+ the same UnlinkedFunctionExecutable to generate code blocks for multiple functions.
+
+ Parser now has the ability to treat any function expression as a constructor of the kind specified
+ by m_defaultConstructorKind member variable.
+
+ * builtins/BuiltinExecutables.cpp:
+ (JSC::BuiltinExecutables::createDefaultConstructor): Added.
+ (JSC::BuiltinExecutables::createExecutableInternal): Generalized from createBuiltinExecutable.
+ Parse default constructors as normal non-builtin functions. Override SourceCode in the unlinked
+ function executable since the Miranda function's code is definitely not in the owner executable's
+ source code. That's the whole point.
+ * builtins/BuiltinExecutables.h:
+ (UnlinkedFunctionExecutable::createBuiltinExecutable): Added. Wraps createExecutableInternal.
+ * bytecode/UnlinkedCodeBlock.cpp:
+ (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
+ (JSC::UnlinkedFunctionExecutable::linkInsideExecutable):
+ (JSC::UnlinkedFunctionExecutable::linkGlobalCode):
+ * bytecode/UnlinkedCodeBlock.h:
+ (JSC::UnlinkedFunctionExecutable::create):
+ (JSC::UnlinkedFunctionExecutable::symbolTable): Deleted.
+ * bytecompiler/BytecodeGenerator.cpp:
+ (JSC::BytecodeGenerator::emitNewDefaultConstructor): Added.
+ * bytecompiler/BytecodeGenerator.h:
+ * bytecompiler/NodesCodegen.cpp:
+ (JSC::ClassExprNode::emitBytecode): Generate the default constructor if needed.
+ * parser/Parser.cpp:
+ (JSC::Parser<LexerType>::Parser):
+ (JSC::Parser<LexerType>::parseFunctionInfo): Override ownerClassKind and assume the function as
+ a constructor if we're parsing a default constructor.
+ (JSC::Parser<LexerType>::parseClass): Allow omission of the class constructor.
+ * parser/Parser.h:
+ (JSC::parse):
+
</ins><span class="cx"> 2015-03-16 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> Progress towards CMake on Mac
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebuiltinsBuiltinExecutablescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.cpp (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.cpp        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.cpp        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include "Executable.h"
</span><span class="cx"> #include "JSCInlines.h"
</span><span class="cx"> #include "Parser.h"
</span><ins>+#include <wtf/NeverDestroyed.h>
</ins><span class="cx">
</span><span class="cx"> namespace JSC {
</span><span class="cx">
</span><span class="lines">@@ -42,11 +43,33 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><del>-UnlinkedFunctionExecutable* BuiltinExecutables::createBuiltinExecutable(const SourceCode& source, const Identifier& name)
</del><ins>+UnlinkedFunctionExecutable* BuiltinExecutables::createDefaultConstructor(ConstructorKind constructorKind, const Identifier& name)
</ins><span class="cx"> {
</span><ins>+ static NeverDestroyed<const String> baseConstructorCode(ASCIILiteral("(function () { })"));
+ static NeverDestroyed<const String> derivedConstructorCode(ASCIILiteral("(function () { super(...arguments); })"));
+
+ switch (constructorKind) {
+ case ConstructorKind::None:
+ break;
+ case ConstructorKind::Base:
+ return createExecutableInternal(makeSource(baseConstructorCode), name, constructorKind);
+ case ConstructorKind::Derived:
+ return createExecutableInternal(makeSource(derivedConstructorCode), name, constructorKind);
+ }
+ ASSERT_NOT_REACHED();
+ return nullptr;
+}
+
+UnlinkedFunctionExecutable* BuiltinExecutables::createExecutableInternal(const SourceCode& source, const Identifier& name, ConstructorKind constructorKind)
+{
</ins><span class="cx"> JSTextPosition positionBeforeLastNewline;
</span><span class="cx"> ParserError error;
</span><del>- std::unique_ptr<ProgramNode> program = parse<ProgramNode>(&m_vm, source, 0, Identifier(), JSParseBuiltin, JSParseProgramCode, error, &positionBeforeLastNewline);
</del><ins>+ bool isParsingDefaultConstructor = constructorKind != ConstructorKind::None;
+ JSParserStrictness strictness = isParsingDefaultConstructor ? JSParseNormal : JSParseBuiltin;
+ UnlinkedFunctionKind kind = isParsingDefaultConstructor ? UnlinkedNormalFunction : UnlinkedBuiltinFunction;
+ RefPtr<SourceProvider> sourceOverride = isParsingDefaultConstructor ? source.provider() : nullptr;
+ std::unique_ptr<ProgramNode> program = parse<ProgramNode>(&m_vm, source, 0, Identifier(), strictness, JSParseProgramCode,
+ error, &positionBeforeLastNewline, false, constructorKind);
</ins><span class="cx">
</span><span class="cx"> if (!program) {
</span><span class="cx"> dataLog("Fatal error compiling builtin function '", name.string(), "': ", error.message());
</span><span class="lines">@@ -78,7 +101,7 @@
</span><span class="cx"> RELEASE_ASSERT(closedVariable->isUnique());
</span><span class="cx"> }
</span><span class="cx"> body->overrideName(name);
</span><del>- UnlinkedFunctionExecutable* functionExecutable = UnlinkedFunctionExecutable::create(&m_vm, source, body, UnlinkedBuiltinFunction);
</del><ins>+ UnlinkedFunctionExecutable* functionExecutable = UnlinkedFunctionExecutable::create(&m_vm, source, body, kind, WTF::move(sourceOverride));
</ins><span class="cx"> functionExecutable->m_nameValue.set(m_vm, functionExecutable, jsString(&m_vm, name.string()));
</span><span class="cx"> return functionExecutable;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebuiltinsBuiltinExecutablesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.h (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.h        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.h        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #define BuiltinExecutables_h
</span><span class="cx">
</span><span class="cx"> #include "JSCBuiltins.h"
</span><ins>+#include "ParserModes.h"
</ins><span class="cx"> #include "SourceCode.h"
</span><span class="cx"> #include "Weak.h"
</span><span class="cx"> #include "WeakHandleOwner.h"
</span><span class="lines">@@ -48,12 +49,20 @@
</span><span class="cx">
</span><span class="cx"> JSC_FOREACH_BUILTIN(EXPOSE_BUILTIN_EXECUTABLES)
</span><span class="cx"> #undef EXPOSE_BUILTIN_SOURCES
</span><del>-
</del><ins>+
+ UnlinkedFunctionExecutable* createDefaultConstructor(ConstructorKind, const Identifier& name);
+
</ins><span class="cx"> private:
</span><span class="cx"> void finalize(Handle<Unknown>, void* context) override;
</span><span class="cx">
</span><span class="cx"> VM& m_vm;
</span><del>- UnlinkedFunctionExecutable* createBuiltinExecutable(const SourceCode&, const Identifier&);
</del><ins>+
+ UnlinkedFunctionExecutable* createBuiltinExecutable(const SourceCode& code, const Identifier& name)
+ {
+ return createExecutableInternal(code, name, ConstructorKind::None);
+ }
+ UnlinkedFunctionExecutable* createExecutableInternal(const SourceCode&, const Identifier&, ConstructorKind);
+
</ins><span class="cx"> #define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, length)\
</span><span class="cx"> SourceCode m_##name##Source; \
</span><span class="cx"> Weak<UnlinkedFunctionExecutable> m_##name##Executable;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeUnlinkedCodeBlockcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -80,7 +80,7 @@
</span><span class="cx"> return addConstant(v);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM* vm, Structure* structure, const SourceCode& source, FunctionBodyNode* node, UnlinkedFunctionKind kind)
</del><ins>+UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM* vm, Structure* structure, const SourceCode& source, RefPtr<SourceProvider>&& sourceOverride, FunctionBodyNode* node, UnlinkedFunctionKind kind)
</ins><span class="cx"> : Base(*vm, structure)
</span><span class="cx"> , m_isInStrictContext(node->isInStrictContext())
</span><span class="cx"> , m_hasCapturedVariables(false)
</span><span class="lines">@@ -98,6 +98,7 @@
</span><span class="cx"> , m_sourceLength(node->source().length())
</span><span class="cx"> , m_typeProfilingStartOffset(node->functionKeywordStart())
</span><span class="cx"> , m_typeProfilingEndOffset(node->startStartOffset() + node->source().length() - 1)
</span><ins>+ , m_sourceOverride(sourceOverride)
</ins><span class="cx"> , m_features(0)
</span><span class="cx"> , m_functionMode(node->functionMode())
</span><span class="cx"> {
</span><span class="lines">@@ -121,8 +122,9 @@
</span><span class="cx"> visitor.append(&thisObject->m_symbolTableForConstruct);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-FunctionExecutable* UnlinkedFunctionExecutable::linkInsideExecutable(VM& vm, const SourceCode& source)
</del><ins>+FunctionExecutable* UnlinkedFunctionExecutable::linkInsideExecutable(VM& vm, const SourceCode& ownerSource)
</ins><span class="cx"> {
</span><ins>+ SourceCode source = m_sourceOverride ? SourceCode(m_sourceOverride) : ownerSource;
</ins><span class="cx"> unsigned firstLine = source.firstLine() + m_firstLineOffset;
</span><span class="cx"> unsigned startOffset = source.startOffset() + m_startOffset;
</span><span class="cx">
</span><span class="lines">@@ -137,6 +139,7 @@
</span><span class="cx">
</span><span class="cx"> FunctionExecutable* UnlinkedFunctionExecutable::linkGlobalCode(VM& vm, const SourceCode& source)
</span><span class="cx"> {
</span><ins>+ ASSERT(!m_sourceOverride);
</ins><span class="cx"> unsigned firstLine = source.firstLine() + m_firstLineOffset;
</span><span class="cx"> unsigned startOffset = source.startOffset() + m_startOffset;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeUnlinkedCodeBlockh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -103,9 +103,10 @@
</span><span class="cx"> friend class CodeCache;
</span><span class="cx"> friend class VM;
</span><span class="cx"> typedef JSCell Base;
</span><del>- static UnlinkedFunctionExecutable* create(VM* vm, const SourceCode& source, FunctionBodyNode* node, UnlinkedFunctionKind unlinkedFunctionKind)
</del><ins>+ static UnlinkedFunctionExecutable* create(VM* vm, const SourceCode& source, FunctionBodyNode* node, UnlinkedFunctionKind unlinkedFunctionKind, RefPtr<SourceProvider>&& sourceOverride = nullptr)
</ins><span class="cx"> {
</span><del>- UnlinkedFunctionExecutable* instance = new (NotNull, allocateCell<UnlinkedFunctionExecutable>(vm->heap)) UnlinkedFunctionExecutable(vm, vm->unlinkedFunctionExecutableStructure.get(), source, node, unlinkedFunctionKind);
</del><ins>+ UnlinkedFunctionExecutable* instance = new (NotNull, allocateCell<UnlinkedFunctionExecutable>(vm->heap))
+ UnlinkedFunctionExecutable(vm, vm->unlinkedFunctionExecutableStructure.get(), source, WTF::move(sourceOverride), node, unlinkedFunctionKind);
</ins><span class="cx"> instance->finishCreation(*vm);
</span><span class="cx"> return instance;
</span><span class="cx"> }
</span><span class="lines">@@ -173,7 +174,7 @@
</span><span class="cx"> bool isBuiltinFunction() const { return m_isBuiltinFunction; }
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- UnlinkedFunctionExecutable(VM*, Structure*, const SourceCode&, FunctionBodyNode*, UnlinkedFunctionKind);
</del><ins>+ UnlinkedFunctionExecutable(VM*, Structure*, const SourceCode&, RefPtr<SourceProvider>&& sourceOverride, FunctionBodyNode*, UnlinkedFunctionKind);
</ins><span class="cx"> WriteBarrier<UnlinkedFunctionCodeBlock> m_codeBlockForCall;
</span><span class="cx"> WriteBarrier<UnlinkedFunctionCodeBlock> m_codeBlockForConstruct;
</span><span class="cx">
</span><span class="lines">@@ -197,6 +198,7 @@
</span><span class="cx"> unsigned m_sourceLength;
</span><span class="cx"> unsigned m_typeProfilingStartOffset;
</span><span class="cx"> unsigned m_typeProfilingEndOffset;
</span><ins>+ RefPtr<SourceProvider> m_sourceOverride;
</ins><span class="cx">
</span><span class="cx"> CodeFeatures m_features;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "BytecodeGenerator.h"
</span><span class="cx">
</span><ins>+#include "BuiltinExecutables.h"
</ins><span class="cx"> #include "Interpreter.h"
</span><span class="cx"> #include "JSFunction.h"
</span><span class="cx"> #include "JSLexicalEnvironment.h"
</span><span class="lines">@@ -1692,6 +1693,19 @@
</span><span class="cx"> return r0;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+RegisterID* BytecodeGenerator::emitNewDefaultConstructor(RegisterID* dst, ConstructorKind constructorKind, const Identifier& name)
+{
+ UnlinkedFunctionExecutable* executable = m_vm->builtinExecutables()->createDefaultConstructor(constructorKind, name);
+
+ unsigned index = m_codeBlock->addFunctionExpr(executable);
+
+ emitOpcode(op_new_func_exp);
+ instructions().append(dst->index());
+ instructions().append(scopeRegister()->index());
+ instructions().append(index);
+ return dst;
+}
+
</ins><span class="cx"> RegisterID* BytecodeGenerator::emitCall(RegisterID* dst, RegisterID* func, ExpectedFunction expectedFunction, CallArguments& callArguments, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd)
</span><span class="cx"> {
</span><span class="cx"> return emitCall(op_call, dst, func, expectedFunction, callArguments, divot, divotStart, divotEnd);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -466,6 +466,7 @@
</span><span class="cx"> RegisterID* emitLazyNewFunction(RegisterID* dst, FunctionBodyNode* body);
</span><span class="cx"> RegisterID* emitNewFunctionInternal(RegisterID* dst, unsigned index, bool shouldNullCheck);
</span><span class="cx"> RegisterID* emitNewFunctionExpression(RegisterID* dst, FuncExprNode* func);
</span><ins>+ RegisterID* emitNewDefaultConstructor(RegisterID* dst, ConstructorKind, const Identifier& name);
</ins><span class="cx"> RegisterID* emitNewRegExp(RegisterID* dst, RegExp*);
</span><span class="cx">
</span><span class="cx"> RegisterID* emitMove(RegisterID* dst, RegisterID* src);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerNodesCodegencpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -2885,10 +2885,19 @@
</span><span class="cx"> generator.emitNode(superclass.get(), m_classHeritage);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- RefPtr<RegisterID> constructor = generator.emitNode(dst, m_constructorExpression);
</del><ins>+ RefPtr<RegisterID> constructor;
+ RefPtr<RegisterID> prototype;
+
</ins><span class="cx"> // FIXME: Make the prototype non-configurable & non-writable.
</span><del>- RefPtr<RegisterID> prototype = generator.emitGetById(generator.newTemporary(), constructor.get(), generator.propertyNames().prototype);
</del><ins>+ if (m_constructorExpression)
+ constructor = generator.emitNode(dst, m_constructorExpression);
+ else {
+ constructor = generator.emitNewDefaultConstructor(generator.finalDestination(dst),
+ m_classHeritage ? ConstructorKind::Derived : ConstructorKind::Base, m_name);
+ }
</ins><span class="cx">
</span><ins>+ prototype = generator.emitGetById(generator.newTemporary(), constructor.get(), generator.propertyNames().prototype);
+
</ins><span class="cx"> if (superclass) {
</span><span class="cx"> RefPtr<RegisterID> tempRegister = generator.newTemporary();
</span><span class="cx"> RefPtr<Label> superclassIsNullLabel = generator.newLabel();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Parser.cpp (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Parser.cpp        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/Source/JavaScriptCore/parser/Parser.cpp        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -190,7 +190,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> template <typename LexerType>
</span><del>-Parser<LexerType>::Parser(VM* vm, const SourceCode& source, FunctionParameters* parameters, const Identifier& name, JSParserStrictness strictness, JSParserMode parserMode)
</del><ins>+Parser<LexerType>::Parser(VM* vm, const SourceCode& source, FunctionParameters* parameters, const Identifier& name, JSParserStrictness strictness, JSParserMode parserMode, ConstructorKind defaultConstructorKind)
</ins><span class="cx"> : m_vm(vm)
</span><span class="cx"> , m_source(&source)
</span><span class="cx"> , m_hasStackOverflow(false)
</span><span class="lines">@@ -204,6 +204,7 @@
</span><span class="cx"> , m_lastFunctionName(nullptr)
</span><span class="cx"> , m_sourceElements(0)
</span><span class="cx"> , m_parsingBuiltin(strictness == JSParseBuiltin)
</span><ins>+ , m_defaultConstructorKind(defaultConstructorKind)
</ins><span class="cx"> {
</span><span class="cx"> m_lexer = std::make_unique<LexerType>(vm, strictness);
</span><span class="cx"> m_lexer->setCode(source, &m_parserArena);
</span><span class="lines">@@ -1325,6 +1326,10 @@
</span><span class="cx"> // BytecodeGenerator emits code to throw TypeError when a class constructor is "call"ed.
</span><span class="cx"> // Set ConstructorKind to None for non-constructor methods of classes.
</span><span class="cx"> bool isClassConstructor = mode == MethodMode && info.name && *info.name == m_vm->propertyNames->constructor;
</span><ins>+ if (m_defaultConstructorKind != ConstructorKind::None) {
+ ownerClassKind = m_defaultConstructorKind;
+ isClassConstructor = true;
+ }
</ins><span class="cx"> ConstructorKind constructorKind = isClassConstructor ? ownerClassKind : ConstructorKind::None;
</span><span class="cx">
</span><span class="cx"> info.openBraceOffset = m_token.m_data.offset;
</span><span class="lines">@@ -1549,9 +1554,6 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // FIXME: Create a Miranda function instead.
- semanticFailIfFalse(constructor, "Class declaration without a constructor is not supported yet");
-
</del><span class="cx"> failIfFalse(popScope(classScope, TreeBuilder::NeedsFreeVariableInfo), "Parser error");
</span><span class="cx"> consumeOrFail(CLOSEBRACE, "Expected a closing '}' after a class body");
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Parser.h (181610 => 181611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Parser.h        2015-03-17 03:56:18 UTC (rev 181610)
+++ trunk/Source/JavaScriptCore/parser/Parser.h        2015-03-17 04:02:52 UTC (rev 181611)
</span><span class="lines">@@ -426,7 +426,8 @@
</span><span class="cx"> WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx">
</span><span class="cx"> public:
</span><del>- Parser(VM*, const SourceCode&, FunctionParameters*, const Identifier&, JSParserStrictness, JSParserMode);
</del><ins>+ Parser(VM*, const SourceCode&, FunctionParameters*, const Identifier&, JSParserStrictness, JSParserMode,
+ ConstructorKind defaultConstructorKind = ConstructorKind::None);
</ins><span class="cx"> ~Parser();
</span><span class="cx">
</span><span class="cx"> template <class ParsedNode>
</span><span class="lines">@@ -872,6 +873,7 @@
</span><span class="cx"> RefPtr<SourceProviderCache> m_functionCache;
</span><span class="cx"> SourceElements* m_sourceElements;
</span><span class="cx"> bool m_parsingBuiltin;
</span><ins>+ ConstructorKind m_defaultConstructorKind;
</ins><span class="cx"> DeclarationStacks::VarStack m_varDeclarations;
</span><span class="cx"> DeclarationStacks::FunctionStack m_funcDeclarations;
</span><span class="cx"> IdentifierSet m_capturedVariables;
</span><span class="lines">@@ -979,13 +981,15 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> template <class ParsedNode>
</span><del>-std::unique_ptr<ParsedNode> parse(VM* vm, const SourceCode& source, FunctionParameters* parameters, const Identifier& name, JSParserStrictness strictness, JSParserMode parserMode, ParserError& error, JSTextPosition* positionBeforeLastNewline = 0, bool needReparsingAdjustment = false)
</del><ins>+std::unique_ptr<ParsedNode> parse(VM* vm, const SourceCode& source, FunctionParameters* parameters, const Identifier& name,
+ JSParserStrictness strictness, JSParserMode parserMode, ParserError& error, JSTextPosition* positionBeforeLastNewline = 0,
+ bool needReparsingAdjustment = false, ConstructorKind defaultConstructorKind = ConstructorKind::None)
</ins><span class="cx"> {
</span><span class="cx"> SamplingRegion samplingRegion("Parsing");
</span><span class="cx">
</span><span class="cx"> ASSERT(!source.provider()->source().isNull());
</span><span class="cx"> if (source.provider()->source().is8Bit()) {
</span><del>- Parser<Lexer<LChar>> parser(vm, source, parameters, name, strictness, parserMode);
</del><ins>+ Parser<Lexer<LChar>> parser(vm, source, parameters, name, strictness, parserMode, defaultConstructorKind);
</ins><span class="cx"> std::unique_ptr<ParsedNode> result = parser.parse<ParsedNode>(error, needReparsingAdjustment);
</span><span class="cx"> if (positionBeforeLastNewline)
</span><span class="cx"> *positionBeforeLastNewline = parser.positionBeforeLastNewline();
</span></span></pre>
</div>
</div>
</body>
</html>