<!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>[179371] 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/179371">179371</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2015-01-29 14:59:19 -0800 (Thu, 29 Jan 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Implement ES6 class syntax without inheritance support
https://bugs.webkit.org/show_bug.cgi?id=140918
Reviewed by Geoffrey Garen.
Source/JavaScriptCore:
Added the most basic support for ES6 class syntax. After this patch, we support basic class definition like:
class A {
constructor() { }
someMethod() { }
}
We'll add the support for "extends" keyword and automatically generating a constructor in follow up patches.
We also don't support block scoping of a class declaration.
We support both class declaration and class expression. A class expression is implemented by the newly added
ClassExprNode AST node. A class declaration is implemented by ClassDeclNode, which is a thin wrapper around
AssignResolveNode.
Tests: js/class-syntax-declaration.html
js/class-syntax-expression.html
* bytecompiler/NodesCodegen.cpp:
(JSC::ObjectLiteralNode::emitBytecode): Create a new object instead of delegating the work to PropertyListNode.
Also fixed the 5-space indentation.
(JSC::PropertyListNode::emitBytecode): Don't create a new object now that ObjectLiteralNode does this.
(JSC::ClassDeclNode::emitBytecode): Added. Just let the AssignResolveNode node emit the byte code.
(JSC::ClassExprNode::emitBytecode): Create the class constructor and add static methods to the constructor by
emitting the byte code for PropertyListNode. Add instance methods to the class's prototype object the same way.
* parser/ASTBuilder.h:
(JSC::ASTBuilder::createClassExpr): Added. Creates a ClassExprNode.
(JSC::ASTBuilder::createClassDeclStatement): Added. Creates a AssignResolveNode and wraps it by a ClassDeclNode.
* parser/NodeConstructors.h:
(JSC::ClassDeclNode::ClassDeclNode): Added.
(JSC::ClassExprNode::ClassExprNode): Added.
* parser/Nodes.h:
(JSC::ClassExprNode): Added.
(JSC::ClassDeclNode): Added.
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseStatement): Added the support for class declaration.
(JSC::stringForFunctionMode): Return "method" for MethodMode.
(JSC::Parser<LexerType>::parseClassDeclaration): Added. Uses parseClass to create a class expression and wraps
it with ClassDeclNode as described above.
(JSC::Parser<LexerType>::parseClass): Parses a class expression.
(JSC::Parser<LexerType>::parseProperty):
(JSC::Parser<LexerType>::parseGetterSetter): Extracted from parseProperty to share the code between parseProperty
and parseClass.
(JSC::Parser<LexerType>::parsePrimaryExpression): Added the support for class expression.
* parser/Parser.h:
(FunctionParseMode): Added MethodMode.
* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::createClassExpr): Added.
(JSC::SyntaxChecker::createClassDeclStatement): Added.
LayoutTests:
Added two tests for class declarations and class expressions.
* TestExpectations:
* js/class-syntax-declaration-expected.txt: Added.
* js/class-syntax-declaration.html: Added.
* js/class-syntax-expression-expected.txt: Added.
* js/class-syntax-expression.html: Added.
* js/script-tests/class-syntax-declaration.js: Added.
* js/script-tests/class-syntax-expression.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="#trunkSourceJavaScriptCorebytecompilerNodesCodegencpp">trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserASTBuilderh">trunk/Source/JavaScriptCore/parser/ASTBuilder.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserNodeConstructorsh">trunk/Source/JavaScriptCore/parser/NodeConstructors.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserNodesh">trunk/Source/JavaScriptCore/parser/Nodes.h</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>
<li><a href="#trunkSourceJavaScriptCoreparserSyntaxCheckerh">trunk/Source/JavaScriptCore/parser/SyntaxChecker.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsclasssyntaxdeclarationexpectedtxt">trunk/LayoutTests/js/class-syntax-declaration-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsclasssyntaxdeclarationhtml">trunk/LayoutTests/js/class-syntax-declaration.html</a></li>
<li><a href="#trunkLayoutTestsjsclasssyntaxexpressionexpectedtxt">trunk/LayoutTests/js/class-syntax-expression-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsclasssyntaxexpressionhtml">trunk/LayoutTests/js/class-syntax-expression.html</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsclasssyntaxdeclarationjs">trunk/LayoutTests/js/script-tests/class-syntax-declaration.js</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsclasssyntaxexpressionjs">trunk/LayoutTests/js/script-tests/class-syntax-expression.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (179370 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-01-29 22:58:22 UTC (rev 179370)
+++ trunk/LayoutTests/ChangeLog        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2015-01-29 Ryosuke Niwa <rniwa@webkit.org>
+
+ Implement ES6 class syntax without inheritance support
+ https://bugs.webkit.org/show_bug.cgi?id=140918
+
+ Reviewed by Geoffrey Garen.
+
+ Added two tests for class declarations and class expressions.
+
+ * TestExpectations:
+ * js/class-syntax-declaration-expected.txt: Added.
+ * js/class-syntax-declaration.html: Added.
+ * js/class-syntax-expression-expected.txt: Added.
+ * js/class-syntax-expression.html: Added.
+ * js/script-tests/class-syntax-declaration.js: Added.
+ * js/script-tests/class-syntax-expression.js: Added.
+
</ins><span class="cx"> 2015-01-29 Simon Fraser <simon.fraser@apple.com>
</span><span class="cx">
</span><span class="cx"> Border-radius clipping on a stacking context causes descendants to not render
</span></span></pre></div>
<a id="trunkLayoutTestsTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/TestExpectations (179370 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/TestExpectations        2015-01-29 22:58:22 UTC (rev 179370)
+++ trunk/LayoutTests/TestExpectations        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -66,6 +66,10 @@
</span><span class="cx">
</span><span class="cx"> webkit.org/b/127860 [ Debug ] js/function-apply-aliased.html [ Skip ]
</span><span class="cx">
</span><ins>+# ES6 class syntax hasn't been enabled yet.
+webkit.org/b/140491 js/class-syntax-declaration.html [ Failure ]
+webkit.org/b/140491 js/class-syntax-expression.html [ Failure ]
+
</ins><span class="cx"> # This test verifies dynamic manipulation of the mroot and msqrt elements.
</span><span class="cx"> mathml/roots-removeChild.html [ ImageOnlyFailure ]
</span><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsjsclasssyntaxdeclarationexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/class-syntax-declaration-expected.txt (0 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-syntax-declaration-expected.txt         (rev 0)
+++ trunk/LayoutTests/js/class-syntax-declaration-expected.txt        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -0,0 +1,26 @@
</span><ins>+PASS constructorCallCount is 0
+PASS A.someStaticMethod() is staticMethodValue
+PASS (new A).someInstanceMethod() is instanceMethodValue
+PASS constructorCallCount is 1
+PASS (new A).someGetter is getterValue
+PASS constructorCallCount is 2
+PASS (new A).someGetter is getterValue
+PASS setterValue is undefined
+PASS (new A).someSetter = 789 did not throw exception.
+PASS setterValue is 789
+PASS (new A).__proto__ is A.prototype
+PASS A.prototype.constructor is A
+PASS class threw exception SyntaxError: Unexpected end of script.
+PASS class X { threw exception SyntaxError: Unexpected end of script.
+PASS class X { ( } threw exception SyntaxError: Unexpected token '('. Expected an indentifier..
+PASS class X {} threw exception SyntaxError: Class declaration without a constructor is not supported yet..
+PASS class X { constructor() {} constructor() {} } threw exception SyntaxError: Cannot declare multiple constructors in a single class..
+PASS class X { constructor() {} static constructor() { return staticMethodValue; } } did not throw exception.
+PASS X.constructor() is staticMethodValue
+PASS class X { constructor() {} static prototype() {} } threw exception SyntaxError: Cannot declare a static method named 'prototype'..
+PASS class X { constructor() {} prototype() { return instanceMethodValue; } } did not throw exception.
+PASS (new X).prototype() is instanceMethodValue
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsclasssyntaxdeclarationhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/class-syntax-declaration.html (0 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-syntax-declaration.html         (rev 0)
+++ trunk/LayoutTests/js/class-syntax-declaration.html        2015-01-29 22:59:19 UTC (rev 179371)
</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-declaration.js"></script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsjsclasssyntaxexpressionexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/class-syntax-expression-expected.txt (0 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-syntax-expression-expected.txt         (rev 0)
+++ trunk/LayoutTests/js/class-syntax-expression-expected.txt        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -0,0 +1,26 @@
</span><ins>+PASS constructorCallCount is 0
+PASS A.someStaticMethod() is staticMethodValue
+PASS (new A).someInstanceMethod() is instanceMethodValue
+PASS constructorCallCount is 1
+PASS (new A).someGetter is getterValue
+PASS constructorCallCount is 2
+PASS (new A).someGetter is getterValue
+PASS setterValue is undefined
+PASS (new A).someSetter = 789 did not throw exception.
+PASS setterValue is 789
+PASS (new A).__proto__ is A.prototype
+PASS A.prototype.constructor is A
+PASS x = class threw exception SyntaxError: Unexpected end of script.
+PASS x = class { threw exception SyntaxError: Unexpected end of script.
+PASS x = class { ( } threw exception SyntaxError: Unexpected token '('. Expected an indentifier..
+PASS x = class {} threw exception SyntaxError: Class declaration without a constructor is not supported yet..
+PASS x = class { constructor() {} constructor() {} } threw exception SyntaxError: Cannot declare multiple constructors in a single class..
+PASS x = class { constructor() {} static constructor() { return staticMethodValue; } } did not throw exception.
+PASS x.constructor() is staticMethodValue
+PASS x = class { constructor() {} static prototype() {} } threw exception SyntaxError: Cannot declare a static method named 'prototype'..
+PASS x = class { constructor() {} prototype() { return instanceMethodValue; } } did not throw exception.
+PASS (new x).prototype() is instanceMethodValue
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsclasssyntaxexpressionhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/class-syntax-expression.html (0 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-syntax-expression.html         (rev 0)
+++ trunk/LayoutTests/js/class-syntax-expression.html        2015-01-29 22:59:19 UTC (rev 179371)
</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-expression.js"></script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsclasssyntaxdeclarationjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/script-tests/class-syntax-declaration.js (0 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/class-syntax-declaration.js         (rev 0)
+++ trunk/LayoutTests/js/script-tests/class-syntax-declaration.js        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -0,0 +1,38 @@
</span><ins>+var constructorCallCount = 0;
+const staticMethodValue = [1];
+const instanceMethodValue = [2];
+const getterValue = [3];
+var setterValue = undefined;
+class A {
+ constructor() { constructorCallCount++; }
+ static someStaticMethod() { return staticMethodValue; }
+ someInstanceMethod() { return instanceMethodValue; }
+ get someGetter() { return getterValue; }
+ set someSetter(value) { setterValue = value; }
+}
+
+shouldBe("constructorCallCount", "0");
+shouldBe("A.someStaticMethod()", "staticMethodValue");
+shouldBe("(new A).someInstanceMethod()", "instanceMethodValue");
+shouldBe("constructorCallCount", "1");
+shouldBe("(new A).someGetter", "getterValue");
+shouldBe("constructorCallCount", "2");
+shouldBe("(new A).someGetter", "getterValue");
+shouldBe("setterValue", "undefined");
+shouldNotThrow("(new A).someSetter = 789");
+shouldBe("setterValue", "789");
+shouldBe("(new A).__proto__", "A.prototype");
+shouldBe("A.prototype.constructor", "A");
+
+shouldThrow("class", "'SyntaxError: Unexpected end of script'");
+shouldThrow("class X {", "'SyntaxError: Unexpected end of script'");
+shouldThrow("class X { ( }", "'SyntaxError: Unexpected token \\'(\\'. Expected an indentifier.'");
+shouldThrow("class X {}", "'SyntaxError: Class declaration without a constructor is not supported yet.'");
+shouldThrow("class X { constructor() {} constructor() {} }", "'SyntaxError: Cannot declare multiple constructors in a single class.'");
+shouldNotThrow("class X { constructor() {} static constructor() { return staticMethodValue; } }");
+shouldBe("X.constructor()", "staticMethodValue");
+shouldThrow("class X { constructor() {} static prototype() {} }", "'SyntaxError: Cannot declare a static method named \\'prototype\\'.'");
+shouldNotThrow("class X { constructor() {} prototype() { return instanceMethodValue; } }");
+shouldBe("(new X).prototype()", "instanceMethodValue");
+
+var successfullyParsed = true;
</ins></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsclasssyntaxexpressionjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/script-tests/class-syntax-expression.js (0 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/class-syntax-expression.js         (rev 0)
+++ trunk/LayoutTests/js/script-tests/class-syntax-expression.js        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -0,0 +1,38 @@
</span><ins>+var constructorCallCount = 0;
+const staticMethodValue = [1];
+const instanceMethodValue = [2];
+const getterValue = [3];
+var setterValue = undefined;
+var A = class {
+ constructor() { constructorCallCount++; }
+ static someStaticMethod() { return staticMethodValue; }
+ someInstanceMethod() { return instanceMethodValue; }
+ get someGetter() { return getterValue; }
+ set someSetter(value) { setterValue = value; }
+};
+
+shouldBe("constructorCallCount", "0");
+shouldBe("A.someStaticMethod()", "staticMethodValue");
+shouldBe("(new A).someInstanceMethod()", "instanceMethodValue");
+shouldBe("constructorCallCount", "1");
+shouldBe("(new A).someGetter", "getterValue");
+shouldBe("constructorCallCount", "2");
+shouldBe("(new A).someGetter", "getterValue");
+shouldBe("setterValue", "undefined");
+shouldNotThrow("(new A).someSetter = 789");
+shouldBe("setterValue", "789");
+shouldBe("(new A).__proto__", "A.prototype");
+shouldBe("A.prototype.constructor", "A");
+
+shouldThrow("x = class", "'SyntaxError: Unexpected end of script'");
+shouldThrow("x = class {", "'SyntaxError: Unexpected end of script'");
+shouldThrow("x = class { ( }", "'SyntaxError: Unexpected token \\'(\\'. Expected an indentifier.'");
+shouldThrow("x = class {}", "'SyntaxError: Class declaration without a constructor is not supported yet.'");
+shouldThrow("x = class { constructor() {} constructor() {} }", "'SyntaxError: Cannot declare multiple constructors in a single class.'");
+shouldNotThrow("x = class { constructor() {} static constructor() { return staticMethodValue; } }");
+shouldBe("x.constructor()", "staticMethodValue");
+shouldThrow("x = class { constructor() {} static prototype() {} }", "'SyntaxError: Cannot declare a static method named \\'prototype\\'.'");
+shouldNotThrow("x = class { constructor() {} prototype() { return instanceMethodValue; } }");
+shouldBe("(new x).prototype()", "instanceMethodValue");
+
+var successfullyParsed = true;
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (179370 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-01-29 22:58:22 UTC (rev 179370)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -1,3 +1,64 @@
</span><ins>+2015-01-29 Ryosuke Niwa <rniwa@webkit.org>
+
+ Implement ES6 class syntax without inheritance support
+ https://bugs.webkit.org/show_bug.cgi?id=140918
+
+ Reviewed by Geoffrey Garen.
+
+ Added the most basic support for ES6 class syntax. After this patch, we support basic class definition like:
+ class A {
+ constructor() { }
+ someMethod() { }
+ }
+
+ We'll add the support for "extends" keyword and automatically generating a constructor in follow up patches.
+ We also don't support block scoping of a class declaration.
+
+ We support both class declaration and class expression. A class expression is implemented by the newly added
+ ClassExprNode AST node. A class declaration is implemented by ClassDeclNode, which is a thin wrapper around
+ AssignResolveNode.
+
+ Tests: js/class-syntax-declaration.html
+ js/class-syntax-expression.html
+
+ * bytecompiler/NodesCodegen.cpp:
+ (JSC::ObjectLiteralNode::emitBytecode): Create a new object instead of delegating the work to PropertyListNode.
+ Also fixed the 5-space indentation.
+ (JSC::PropertyListNode::emitBytecode): Don't create a new object now that ObjectLiteralNode does this.
+ (JSC::ClassDeclNode::emitBytecode): Added. Just let the AssignResolveNode node emit the byte code.
+ (JSC::ClassExprNode::emitBytecode): Create the class constructor and add static methods to the constructor by
+ emitting the byte code for PropertyListNode. Add instance methods to the class's prototype object the same way.
+
+ * parser/ASTBuilder.h:
+ (JSC::ASTBuilder::createClassExpr): Added. Creates a ClassExprNode.
+ (JSC::ASTBuilder::createClassDeclStatement): Added. Creates a AssignResolveNode and wraps it by a ClassDeclNode.
+
+ * parser/NodeConstructors.h:
+ (JSC::ClassDeclNode::ClassDeclNode): Added.
+ (JSC::ClassExprNode::ClassExprNode): Added.
+
+ * parser/Nodes.h:
+ (JSC::ClassExprNode): Added.
+ (JSC::ClassDeclNode): Added.
+
+ * parser/Parser.cpp:
+ (JSC::Parser<LexerType>::parseStatement): Added the support for class declaration.
+ (JSC::stringForFunctionMode): Return "method" for MethodMode.
+ (JSC::Parser<LexerType>::parseClassDeclaration): Added. Uses parseClass to create a class expression and wraps
+ it with ClassDeclNode as described above.
+ (JSC::Parser<LexerType>::parseClass): Parses a class expression.
+ (JSC::Parser<LexerType>::parseProperty):
+ (JSC::Parser<LexerType>::parseGetterSetter): Extracted from parseProperty to share the code between parseProperty
+ and parseClass.
+ (JSC::Parser<LexerType>::parsePrimaryExpression): Added the support for class expression.
+
+ * parser/Parser.h:
+ (FunctionParseMode): Added MethodMode.
+
+ * parser/SyntaxChecker.h:
+ (JSC::SyntaxChecker::createClassExpr): Added.
+ (JSC::SyntaxChecker::createClassDeclStatement): Added.
+
</ins><span class="cx"> 2015-01-29 Geoffrey Garen <ggaren@apple.com>
</span><span class="cx">
</span><span class="cx"> Try to fix the Windows build.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerNodesCodegencpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp (179370 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp        2015-01-29 22:58:22 UTC (rev 179370)
+++ trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -273,26 +273,24 @@
</span><span class="cx">
</span><span class="cx"> RegisterID* ObjectLiteralNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst)
</span><span class="cx"> {
</span><del>- if (!m_list) {
- if (dst == generator.ignoredResult())
- return 0;
- return generator.emitNewObject(generator.finalDestination(dst));
- }
- return generator.emitNode(dst, m_list);
</del><ins>+ if (!m_list) {
+ if (dst == generator.ignoredResult())
+ return 0;
+ return generator.emitNewObject(generator.finalDestination(dst));
+ }
+ RefPtr<RegisterID> newObj = generator.emitNewObject(generator.tempDestination(dst));
+ generator.emitNode(newObj.get(), m_list);
+ return generator.moveToDestinationIfNeeded(dst, newObj.get());
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // ------------------------------ PropertyListNode -----------------------------
</span><span class="cx">
</span><span class="cx"> RegisterID* PropertyListNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst)
</span><span class="cx"> {
</span><del>- RefPtr<RegisterID> newObj = generator.tempDestination(dst);
-
- generator.emitNewObject(newObj.get());
-
</del><span class="cx"> // Fast case: this loop just handles regular value properties.
</span><span class="cx"> PropertyListNode* p = this;
</span><span class="cx"> for (; p && p->m_node->m_type == PropertyNode::Constant; p = p->m_next)
</span><del>- emitPutConstantProperty(generator, newObj.get(), *p->m_node);
</del><ins>+ emitPutConstantProperty(generator, dst, *p->m_node);
</ins><span class="cx">
</span><span class="cx"> // Were there any get/set properties?
</span><span class="cx"> if (p) {
</span><span class="lines">@@ -318,7 +316,7 @@
</span><span class="cx">
</span><span class="cx"> // Handle regular values.
</span><span class="cx"> if (node->m_type == PropertyNode::Constant) {
</span><del>- emitPutConstantProperty(generator, newObj.get(), *node);
</del><ins>+ emitPutConstantProperty(generator, dst, *node);
</ins><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -359,11 +357,11 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- generator.emitPutGetterSetter(newObj.get(), *node->name(), getterReg.get(), setterReg.get());
</del><ins>+ generator.emitPutGetterSetter(dst, *node->name(), getterReg.get(), setterReg.get());
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- return generator.moveToDestinationIfNeeded(dst, newObj.get());
</del><ins>+ return dst;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PropertyListNode::emitPutConstantProperty(BytecodeGenerator& generator, RegisterID* newObj, PropertyNode& node)
</span><span class="lines">@@ -2753,6 +2751,33 @@
</span><span class="cx"> {
</span><span class="cx"> return generator.emitNewFunctionExpression(generator.finalDestination(dst), this);
</span><span class="cx"> }
</span><ins>+
+#if ENABLE(ES6_CLASS_SYNTAX)
+// ------------------------------ ClassDeclNode ---------------------------------
+
+void ClassDeclNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst)
+{
+ generator.emitNode(dst, m_classDeclaration);
+}
+
+// ------------------------------ ClassExprNode ---------------------------------
+
+RegisterID* ClassExprNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst)
+{
+ ASSERT(!m_parentClassExpression);
+
+ RefPtr<RegisterID> constructor = generator.emitNode(dst, m_constructorExpression);
+ RefPtr<RegisterID> prototype = generator.emitGetById(generator.newTemporary(), constructor.get(), generator.propertyNames().prototype);
+
+ if (m_staticMethods)
+ generator.emitNode(constructor.get(), m_staticMethods);
+
+ if (m_instanceMethods)
+ generator.emitNode(prototype.get(), m_instanceMethods);
+
+ return generator.moveToDestinationIfNeeded(dst, constructor.get());
+}
+#endif
</ins><span class="cx">
</span><span class="cx"> // ------------------------------ DeconstructingAssignmentNode -----------------
</span><span class="cx"> RegisterID* DeconstructingAssignmentNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserASTBuilderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/ASTBuilder.h (179370 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/ASTBuilder.h        2015-01-29 22:58:22 UTC (rev 179370)
+++ trunk/Source/JavaScriptCore/parser/ASTBuilder.h        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -104,6 +104,9 @@
</span><span class="cx"> typedef ArgumentListNode* ArgumentsList;
</span><span class="cx"> typedef ParameterNode* FormalParameterList;
</span><span class="cx"> typedef FunctionBodyNode* FunctionBody;
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ typedef ClassExprNode* ClassExpression;
+#endif
</ins><span class="cx"> typedef StatementNode* Statement;
</span><span class="cx"> typedef ClauseListNode* ClauseList;
</span><span class="cx"> typedef CaseClauseNode* Clause;
</span><span class="lines">@@ -273,6 +276,14 @@
</span><span class="cx"> return node;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ ClassExprNode* createClassExpr(const JSTokenLocation& location, const Identifier& name, ExpressionNode* constructor,
+ ExpressionNode* parentClass, PropertyListNode* instanceMethods, PropertyListNode* staticMethods)
+ {
+ return new (m_parserArena) ClassExprNode(location, name, constructor, parentClass, instanceMethods, staticMethods);
+ }
+#endif
+
</ins><span class="cx"> ExpressionNode* createFunctionExpr(const JSTokenLocation& location, const ParserFunctionInfo<ASTBuilder>& info, unsigned functionKeywordStart)
</span><span class="cx"> {
</span><span class="cx"> FuncExprNode* result = new (m_parserArena) FuncExprNode(location, *info.name, info.body,
</span><span class="lines">@@ -353,6 +364,18 @@
</span><span class="cx"> return decl;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ StatementNode* createClassDeclStatement(const JSTokenLocation& location, ClassExprNode* classExpression,
+ const JSTextPosition& classStart, const JSTextPosition& classEnd, unsigned startLine, unsigned endLine)
+ {
+ // FIXME: Use "let" declaration.
+ ExpressionNode* assign = createAssignResolve(location, classExpression->name(), classExpression, classStart, classStart + 1, classEnd);
+ ClassDeclNode* decl = new (m_parserArena) ClassDeclNode(location, assign);
+ decl->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset);
+ return decl;
+ }
+#endif
+
</ins><span class="cx"> StatementNode* createBlockStatement(const JSTokenLocation& location, JSC::SourceElements* elements, int startLine, int endLine)
</span><span class="cx"> {
</span><span class="cx"> BlockNode* block = new (m_parserArena) BlockNode(location, elements);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserNodeConstructorsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/NodeConstructors.h (179370 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/NodeConstructors.h        2015-01-29 22:58:22 UTC (rev 179370)
+++ trunk/Source/JavaScriptCore/parser/NodeConstructors.h        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -768,6 +768,24 @@
</span><span class="cx"> m_body->finishParsing(source, parameter, ident, FunctionDeclaration);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ inline ClassDeclNode::ClassDeclNode(const JSTokenLocation& location, ExpressionNode* classDeclaration)
+ : StatementNode(location)
+ , m_classDeclaration(classDeclaration)
+ {
+ }
+
+ inline ClassExprNode::ClassExprNode(const JSTokenLocation& location, const Identifier& name, ExpressionNode* constructorExpression, ExpressionNode* parentClassExpression, PropertyListNode* instanceMethods, PropertyListNode* staticMethods)
+ : ExpressionNode(location)
+ , m_name(name)
+ , m_constructorExpression(constructorExpression)
+ , m_parentClassExpression(parentClassExpression)
+ , m_instanceMethods(instanceMethods)
+ , m_staticMethods(staticMethods)
+ {
+ }
+#endif
+
</ins><span class="cx"> inline CaseClauseNode::CaseClauseNode(ExpressionNode* expr, SourceElements* statements)
</span><span class="cx"> : m_expr(expr)
</span><span class="cx"> , m_statements(statements)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserNodesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Nodes.h (179370 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Nodes.h        2015-01-29 22:58:22 UTC (rev 179370)
+++ trunk/Source/JavaScriptCore/parser/Nodes.h        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -1611,6 +1611,25 @@
</span><span class="cx"> FunctionBodyNode* m_body;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ class ClassExprNode final : public ExpressionNode {
+ public:
+ ClassExprNode(const JSTokenLocation&, const Identifier&, ExpressionNode* constructorExpresssion,
+ ExpressionNode* parentClass, PropertyListNode* instanceMethods, PropertyListNode* staticMethods);
+
+ const Identifier& name() { return m_name; }
+
+ private:
+ virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override;
+
+ const Identifier& m_name;
+ ExpressionNode* m_constructorExpression;
+ ExpressionNode* m_parentClassExpression;
+ PropertyListNode* m_instanceMethods;
+ PropertyListNode* m_staticMethods;
+ };
+#endif
+
</ins><span class="cx"> class DeconstructionPatternNode : public RefCounted<DeconstructionPatternNode> {
</span><span class="cx"> WTF_MAKE_NONCOPYABLE(DeconstructionPatternNode);
</span><span class="cx"> WTF_MAKE_FAST_ALLOCATED;
</span><span class="lines">@@ -1724,6 +1743,18 @@
</span><span class="cx"> FunctionBodyNode* m_body;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ class ClassDeclNode final : public StatementNode {
+ public:
+ ClassDeclNode(const JSTokenLocation&, ExpressionNode* classExpression);
+
+ private:
+ virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override;
+
+ ExpressionNode* m_classDeclaration;
+ };
+#endif
+
</ins><span class="cx"> class CaseClauseNode : public ParserArenaFreeable {
</span><span class="cx"> public:
</span><span class="cx"> CaseClauseNode(ExpressionNode*, SourceElements* = 0);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Parser.cpp (179370 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Parser.cpp        2015-01-29 22:58:22 UTC (rev 179370)
+++ trunk/Source/JavaScriptCore/parser/Parser.cpp        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -1150,6 +1150,12 @@
</span><span class="cx"> case CONSTTOKEN:
</span><span class="cx"> result = parseConstDeclaration(context);
</span><span class="cx"> break;
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ case CLASSTOKEN:
+ failIfFalse(m_statementDepth == 1, "Class declaration is not allowed in a lexically nested statement");
+ result = parseClassDeclaration(context);
+ break;
+#endif
</ins><span class="cx"> case FUNCTION:
</span><span class="cx"> failIfFalseIfStrict(m_statementDepth == 1, "Strict mode does not allow function declarations in a lexically nested statement");
</span><span class="cx"> result = parseFunctionDeclaration(context);
</span><span class="lines">@@ -1267,6 +1273,10 @@
</span><span class="cx"> return "setter";
</span><span class="cx"> case FunctionMode:
</span><span class="cx"> return "function";
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ case MethodMode:
+ return "method";
+#endif
</ins><span class="cx"> }
</span><span class="cx"> RELEASE_ASSERT_NOT_REACHED();
</span><span class="cx"> return nullptr;
</span><span class="lines">@@ -1404,6 +1414,129 @@
</span><span class="cx"> return context.createFuncDeclStatement(location, info, functionKeywordStart);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+template <typename LexerType>
+template <class TreeBuilder> TreeStatement Parser<LexerType>::parseClassDeclaration(TreeBuilder& context)
+{
+ ASSERT(match(CLASSTOKEN));
+ JSTokenLocation location(tokenLocation());
+ JSTextPosition classStart = tokenStartPosition();
+ unsigned classStartLine = tokenLine();
+
+ TreeClassExpression classExpr = parseClass(context, FunctionNeedsName);
+ failIfFalse(classExpr, "Failed to parse class");
+
+ JSTextPosition classEnd = lastTokenEndPosition();
+ unsigned classEndLine = tokenLine();
+
+ return context.createClassDeclStatement(location, classExpr, classStart, classEnd, classStartLine, classEndLine);
+}
+
+template <typename LexerType>
+template <class TreeBuilder> TreeClassExpression Parser<LexerType>::parseClass(TreeBuilder& context, FunctionRequirements requirements)
+{
+ ASSERT(match(CLASSTOKEN));
+ JSTokenLocation location(tokenLocation());
+ next();
+
+ AutoPopScopeRef classScope(this, pushScope());
+ classScope->setStrictMode();
+
+ const Identifier* className = nullptr;
+ if (match(IDENT)) {
+ className = m_token.m_data.ident;
+ next();
+ failIfFalse(classScope->declareVariable(className), "'", className->impl(), "' is not a valid class name");
+ } else if (requirements == FunctionNeedsName) {
+ semanticFailureDueToKeyword("class name");
+ failDueToUnexpectedToken();
+ } else
+ className = &m_vm->propertyNames->nullIdentifier;
+ ASSERT(className);
+
+ TreeExpression parentClass = 0;
+ if (consume(EXTENDS)) {
+ parentClass = parsePrimaryExpression(context);
+ failIfFalse(parentClass, "Cannot parse the parent class name");
+ failWithMessage("Inheritance is not supported yet");
+ }
+
+ consumeOrFailWithFlags(OPENBRACE, TreeBuilder::DontBuildStrings, "Expected opening '{' at the start of a class body");
+
+ TreeExpression constructor = 0;
+ TreePropertyList staticMethods = 0;
+ TreePropertyList instanceMethods = 0;
+ TreePropertyList instanceMethodsTail = 0;
+ TreePropertyList staticMethodsTail = 0;
+ while (!match(CLOSEBRACE)) {
+ if (match(SEMICOLON))
+ next();
+
+ JSTokenLocation methodLocation(tokenLocation());
+ unsigned methodStart = tokenStart();
+
+ bool isStaticMethod = match(STATICTOKEN);
+ if (isStaticMethod)
+ next();
+
+ matchOrFail(IDENT, "Expected an indentifier");
+
+ const CommonIdentifiers& propertyNames = *m_vm->propertyNames;
+ const Identifier& ident = *m_token.m_data.ident;
+ bool isGetter = ident == propertyNames.get;
+ bool isSetter = ident == propertyNames.set;
+
+ TreeProperty property;
+ const bool alwaysStrictInsideClass = true;
+ if (isGetter || isSetter) {
+ semanticFailIfTrue(isStaticMethod, "Cannot declare a static", stringForFunctionMode(isGetter ? GetterMode : SetterMode));
+ nextExpectIdentifier(LexerFlagsIgnoreReservedWords);
+ property = parseGetterSetter(context, alwaysStrictInsideClass, isGetter ? PropertyNode::Getter : PropertyNode::Setter, methodStart);
+ failIfFalse(property, "Cannot parse this method");
+ } else {
+ ParserFunctionInfo<TreeBuilder> methodInfo;
+ failIfFalse((parseFunctionInfo(context, FunctionNeedsName, FunctionMode, false, methodInfo)), "Cannot parse this method");
+ failIfFalse(methodInfo.name, "method must have a name");
+ failIfFalse(declareVariable(methodInfo.name), "Cannot declare a method named '", methodInfo.name->impl(), "'");
+
+ bool isConstructor = !isStaticMethod && *methodInfo.name == propertyNames.constructor;
+ if (isConstructor)
+ methodInfo.name = className;
+
+ TreeExpression method = context.createFunctionExpr(methodLocation, methodInfo, methodStart);
+ if (isConstructor) {
+ semanticFailIfTrue(constructor, "Cannot declare multiple constructors in a single class");
+ constructor = method;
+ continue;
+ }
+
+ // FIXME: Syntax error when super() is called
+ semanticFailIfTrue(isStaticMethod && *methodInfo.name == propertyNames.prototype,
+ "Cannot declare a static method named 'prototype'");
+ property = context.createProperty(methodInfo.name, method, PropertyNode::Constant, alwaysStrictInsideClass);
+ }
+
+ TreePropertyList& tail = isStaticMethod ? staticMethodsTail : instanceMethodsTail;
+ if (tail)
+ tail = context.createPropertyList(methodLocation, property, tail);
+ else {
+ tail = context.createPropertyList(methodLocation, property);
+ if (isStaticMethod)
+ staticMethods = tail;
+ else
+ instanceMethods = tail;
+ }
+ }
+
+ // FIXME: Create a Miranda function instead.
+ semanticFailIfFalse(constructor, "Class declaration without a constructor is not supported yet");
+
+ consumeOrFail(CLOSEBRACE, "Expected a closing '}' after a class body");
+
+ return context.createClassExpr(location, *className, constructor, parentClass, instanceMethods, staticMethods);
+}
+#endif
+
</ins><span class="cx"> struct LabelInfo {
</span><span class="cx"> LabelInfo(const Identifier* ident, const JSTextPosition& start, const JSTextPosition& end)
</span><span class="cx"> : m_ident(ident)
</span><span class="lines">@@ -1802,27 +1935,7 @@
</span><span class="cx"> type = PropertyNode::Setter;
</span><span class="cx"> else
</span><span class="cx"> failWithMessage("Expected a ':' following the property name '", ident->impl(), "'");
</span><del>- const Identifier* stringPropertyName = 0;
- double numericPropertyName = 0;
- if (m_token.m_type == IDENT || m_token.m_type == STRING)
- stringPropertyName = m_token.m_data.ident;
- else if (m_token.m_type == NUMBER)
- numericPropertyName = m_token.m_data.doubleValue;
- else
- failDueToUnexpectedToken();
- JSTokenLocation location(tokenLocation());
- next();
- ParserFunctionInfo<TreeBuilder> info;
- if (type == PropertyNode::Getter) {
- failIfFalse(match(OPENPAREN), "Expected a parameter list for getter definition");
- failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, GetterMode, false, info)), "Cannot parse getter definition");
- } else {
- failIfFalse(match(OPENPAREN), "Expected a parameter list for setter definition");
- failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SetterMode, false, info)), "Cannot parse setter definition");
- }
- if (stringPropertyName)
- return context.createGetterOrSetterProperty(location, type, complete, stringPropertyName, info, getterOrSetterStartOffset);
- return context.createGetterOrSetterProperty(const_cast<VM*>(m_vm), m_parserArena, location, type, complete, numericPropertyName, info, getterOrSetterStartOffset);
</del><ins>+ return parseGetterSetter(context, complete, type, getterOrSetterStartOffset);
</ins><span class="cx"> }
</span><span class="cx"> case NUMBER: {
</span><span class="cx"> double propertyName = m_token.m_data.doubleValue;
</span><span class="lines">@@ -1852,6 +1965,32 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> template <typename LexerType>
</span><ins>+template <class TreeBuilder> TreeProperty Parser<LexerType>::parseGetterSetter(TreeBuilder& context, bool strict, PropertyNode::Type type, unsigned getterOrSetterStartOffset)
+{
+ const Identifier* stringPropertyName = 0;
+ double numericPropertyName = 0;
+ if (m_token.m_type == IDENT || m_token.m_type == STRING)
+ stringPropertyName = m_token.m_data.ident;
+ else if (m_token.m_type == NUMBER)
+ numericPropertyName = m_token.m_data.doubleValue;
+ else
+ failDueToUnexpectedToken();
+ JSTokenLocation location(tokenLocation());
+ next();
+ ParserFunctionInfo<TreeBuilder> info;
+ if (type == PropertyNode::Getter) {
+ failIfFalse(match(OPENPAREN), "Expected a parameter list for getter definition");
+ failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, GetterMode, false, info)), "Cannot parse getter definition");
+ } else {
+ failIfFalse(match(OPENPAREN), "Expected a parameter list for setter definition");
+ failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SetterMode, false, info)), "Cannot parse setter definition");
+ }
+ if (stringPropertyName)
+ return context.createGetterOrSetterProperty(location, type, strict, stringPropertyName, info, getterOrSetterStartOffset);
+ return context.createGetterOrSetterProperty(const_cast<VM*>(m_vm), m_parserArena, location, type, strict, numericPropertyName, info, getterOrSetterStartOffset);
+}
+
+template <typename LexerType>
</ins><span class="cx"> template <class TreeBuilder> TreeExpression Parser<LexerType>::parseObjectLiteral(TreeBuilder& context)
</span><span class="cx"> {
</span><span class="cx"> auto savePoint = createSavePoint();
</span><span class="lines">@@ -2036,6 +2175,10 @@
</span><span class="cx"> failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, FunctionMode, false, info)), "Cannot parse function expression");
</span><span class="cx"> return context.createFunctionExpr(location, info, functionKeywordStart);
</span><span class="cx"> }
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ case CLASSTOKEN:
+ return parseClass(context, FunctionNoRequirements);
+#endif
</ins><span class="cx"> case OPENBRACE:
</span><span class="cx"> if (strictMode())
</span><span class="cx"> return parseStrictObjectLiteral(context);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Parser.h (179370 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Parser.h        2015-01-29 22:58:22 UTC (rev 179370)
+++ trunk/Source/JavaScriptCore/parser/Parser.h        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -70,6 +70,9 @@
</span><span class="cx"> #define TreeArguments typename TreeBuilder::Arguments
</span><span class="cx"> #define TreeArgumentsList typename TreeBuilder::ArgumentsList
</span><span class="cx"> #define TreeFunctionBody typename TreeBuilder::FunctionBody
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+#define TreeClassExpression typename TreeBuilder::ClassExpression
+#endif
</ins><span class="cx"> #define TreeProperty typename TreeBuilder::Property
</span><span class="cx"> #define TreePropertyList typename TreeBuilder::PropertyList
</span><span class="cx"> #define TreeDeconstructionPattern typename TreeBuilder::DeconstructionPattern
</span><span class="lines">@@ -78,7 +81,14 @@
</span><span class="cx">
</span><span class="cx"> enum SourceElementsMode { CheckForStrictMode, DontCheckForStrictMode };
</span><span class="cx"> enum FunctionRequirements { FunctionNoRequirements, FunctionNeedsName };
</span><del>-enum FunctionParseMode { FunctionMode, GetterMode, SetterMode };
</del><ins>+enum FunctionParseMode {
+ FunctionMode,
+ GetterMode,
+ SetterMode,
+#if ENABLE(ES6_CLASS_SYNTAX)
+ MethodMode
+#endif
+};
</ins><span class="cx"> enum DeconstructionKind {
</span><span class="cx"> DeconstructToVariables,
</span><span class="cx"> DeconstructToParameters,
</span><span class="lines">@@ -693,6 +703,9 @@
</span><span class="cx">
</span><span class="cx"> template <class TreeBuilder> TreeSourceElements parseSourceElements(TreeBuilder&, SourceElementsMode);
</span><span class="cx"> template <class TreeBuilder> TreeStatement parseStatement(TreeBuilder&, const Identifier*& directive, unsigned* directiveLiteralLength = 0);
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ template <class TreeBuilder> TreeStatement parseClassDeclaration(TreeBuilder&);
+#endif
</ins><span class="cx"> template <class TreeBuilder> TreeStatement parseFunctionDeclaration(TreeBuilder&);
</span><span class="cx"> template <class TreeBuilder> TreeStatement parseVarDeclaration(TreeBuilder&);
</span><span class="cx"> template <class TreeBuilder> TreeStatement parseConstDeclaration(TreeBuilder&);
</span><span class="lines">@@ -726,6 +739,7 @@
</span><span class="cx"> enum SpreadMode { AllowSpread, DontAllowSpread };
</span><span class="cx"> template <class TreeBuilder> ALWAYS_INLINE TreeArguments parseArguments(TreeBuilder&, SpreadMode);
</span><span class="cx"> template <class TreeBuilder> TreeProperty parseProperty(TreeBuilder&, bool strict);
</span><ins>+ template <class TreeBuilder> TreeProperty parseGetterSetter(TreeBuilder&, bool strict, PropertyNode::Type, unsigned getterOrSetterStartOffset);
</ins><span class="cx"> template <class TreeBuilder> ALWAYS_INLINE TreeFunctionBody parseFunctionBody(TreeBuilder&);
</span><span class="cx"> template <class TreeBuilder> ALWAYS_INLINE TreeFormalParameterList parseFormalParameters(TreeBuilder&);
</span><span class="cx"> template <class TreeBuilder> TreeExpression parseVarDeclarationList(TreeBuilder&, int& declarations, TreeDeconstructionPattern& lastPattern, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd);
</span><span class="lines">@@ -736,6 +750,9 @@
</span><span class="cx"> template <class TreeBuilder> NEVER_INLINE TreeDeconstructionPattern tryParseDeconstructionPatternExpression(TreeBuilder&);
</span><span class="cx">
</span><span class="cx"> template <class TreeBuilder> NEVER_INLINE bool parseFunctionInfo(TreeBuilder&, FunctionRequirements, FunctionParseMode, bool nameIsInContainingScope, ParserFunctionInfo<TreeBuilder>&);
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ template <class TreeBuilder> NEVER_INLINE TreeClassExpression parseClass(TreeBuilder&, FunctionRequirements);
+#endif
</ins><span class="cx">
</span><span class="cx"> ALWAYS_INLINE int isBinaryOperator(JSTokenType);
</span><span class="cx"> bool allowAutomaticSemicolon();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserSyntaxCheckerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/SyntaxChecker.h (179370 => 179371)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/SyntaxChecker.h        2015-01-29 22:58:22 UTC (rev 179370)
+++ trunk/Source/JavaScriptCore/parser/SyntaxChecker.h        2015-01-29 22:59:19 UTC (rev 179371)
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx"> enum { NoneExpr = 0,
</span><span class="cx"> ResolveEvalExpr, ResolveExpr, NumberExpr, StringExpr,
</span><span class="cx"> ThisExpr, NullExpr, BoolExpr, RegExpExpr, ObjectLiteralExpr,
</span><del>- FunctionExpr, BracketExpr, DotExpr, CallExpr,
</del><ins>+ FunctionExpr, ClassExpr, BracketExpr, DotExpr, CallExpr,
</ins><span class="cx"> NewExpr, PreExpr, PostExpr, UnaryExpr, BinaryExpr,
</span><span class="cx"> ConditionalExpr, AssignmentExpr, TypeofExpr,
</span><span class="cx"> DeleteExpr, ArrayLiteralExpr, BindingDeconstruction,
</span><span class="lines">@@ -113,6 +113,9 @@
</span><span class="cx"> typedef int ArgumentsList;
</span><span class="cx"> typedef int FormalParameterList;
</span><span class="cx"> typedef int FunctionBody;
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ typedef int ClassExpression;
+#endif
</ins><span class="cx"> typedef int Statement;
</span><span class="cx"> typedef int ClauseList;
</span><span class="cx"> typedef int Clause;
</span><span class="lines">@@ -160,6 +163,9 @@
</span><span class="cx"> ExpressionType createConditionalExpr(const JSTokenLocation&, ExpressionType, ExpressionType, ExpressionType) { return ConditionalExpr; }
</span><span class="cx"> ExpressionType createAssignResolve(const JSTokenLocation&, const Identifier&, ExpressionType, int, int, int) { return AssignmentExpr; }
</span><span class="cx"> ExpressionType createEmptyVarExpression(const JSTokenLocation&, const Identifier&) { return AssignmentExpr; }
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ ClassExpression createClassExpr(const JSTokenLocation&, const Identifier&, ExpressionType, ExpressionType, PropertyList, PropertyList) { return ClassExpr; }
+#endif
</ins><span class="cx"> ExpressionType createFunctionExpr(const JSTokenLocation&, const ParserFunctionInfo<SyntaxChecker>&, int) { return FunctionExpr; }
</span><span class="cx"> int createFunctionBody(const JSTokenLocation&, const JSTokenLocation&, int, int, bool) { return FunctionBodyResult; }
</span><span class="cx"> void setFunctionNameStart(int, int) { }
</span><span class="lines">@@ -195,7 +201,10 @@
</span><span class="cx"> int createClauseList(int) { return ClauseListResult; }
</span><span class="cx"> int createClauseList(int, int) { return ClauseListResult; }
</span><span class="cx"> int createFuncDeclStatement(const JSTokenLocation&, const ParserFunctionInfo<SyntaxChecker>&, int) { return StatementResult; }
</span><del>- int createClassDeclStatement(const JSTokenLocation&, const Identifier&, ExpressionType, ExpressionType, PropertyList, PropertyList, int, int) { return StatementResult; }
</del><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ int createClassDeclStatement(const JSTokenLocation&, ClassExpression,
+ const JSTextPosition&, const JSTextPosition&, int, int) { return StatementResult; }
+#endif
</ins><span class="cx"> int createBlockStatement(const JSTokenLocation&, int, int, int) { return StatementResult; }
</span><span class="cx"> int createExprStatement(const JSTokenLocation&, int, int, int) { return StatementResult; }
</span><span class="cx"> int createIfStatement(const JSTokenLocation&, int, int, int, int) { return StatementResult; }
</span></span></pre>
</div>
</div>
</body>
</html>