<!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>[181404] 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/181404">181404</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2015-03-11 14:03:24 -0700 (Wed, 11 Mar 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Calling super() in a base class results in a crash
https://bugs.webkit.org/show_bug.cgi?id=142563
Reviewed by Filip Pizlo.
Source/JavaScriptCore:
The bug was caused by BytecodeGenerator trying to generate "super" expression inside the constructor of a base class.
Disallow that by keeping track of whether "super" has been used in the current scope or not (needsSuperBinding flag)
and then throwing a syntax error in parseFunctionInfo if it was used and the current scope wasn't the constructor of
a derived class.
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseFunctionInfo): Don't allow super() or super.foo outside the constructor of a derived class.
(JSC::Parser<LexerType>::parseClass): Pass in the constructor kind to parseGetterSetter.
(JSC::Parser<LexerType>::parseGetterSetter): Ditto to parseFunctionInfo.
(JSC::Parser<LexerType>::parseMemberExpression): Set needsSuperBinding flag true on the containing scope.
* parser/Parser.h:
(JSC::Scope::Scope):
(JSC::Scope::needsSuperBinding): Added.
(JSC::Scope::setNeedsSuperBinding): Added.
LayoutTests:
Added more test cases to an existing test.
* js/class-syntax-super-expected.txt:
* js/script-tests/class-syntax-super.js:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsjsclasssyntaxsuperexpectedtxt">trunk/LayoutTests/js/class-syntax-super-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsclasssyntaxsuperjs">trunk/LayoutTests/js/script-tests/class-syntax-super.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserParsercpp">trunk/Source/JavaScriptCore/parser/Parser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserParserh">trunk/Source/JavaScriptCore/parser/Parser.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (181403 => 181404)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-03-11 20:27:42 UTC (rev 181403)
+++ trunk/LayoutTests/ChangeLog        2015-03-11 21:03:24 UTC (rev 181404)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2015-03-11 Ryosuke Niwa <rniwa@webkit.org>
+
+ Calling super() in a base class results in a crash
+ https://bugs.webkit.org/show_bug.cgi?id=142563
+
+ Reviewed by Filip Pizlo.
+
+ Added more test cases to an existing test.
+
+ * js/class-syntax-super-expected.txt:
+ * js/script-tests/class-syntax-super.js:
+
</ins><span class="cx"> 2015-03-11 Said Abou-Hallawa <sabouhallawa@apple.com>
</span><span class="cx">
</span><span class="cx"> svg/animations/smil-leak-*.svg tests are flaky.
</span></span></pre></div>
<a id="trunkLayoutTestsjsclasssyntaxsuperexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/class-syntax-super-expected.txt (181403 => 181404)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/class-syntax-super-expected.txt        2015-03-11 20:27:42 UTC (rev 181403)
+++ trunk/LayoutTests/js/class-syntax-super-expected.txt        2015-03-11 21:03:24 UTC (rev 181404)
</span><span class="lines">@@ -35,6 +35,12 @@
</span><span class="cx"> PASS new (class extends null { constructor() { } }) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
</span><span class="cx"> PASS new (class extends null { constructor() { return 1; } }) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
</span><span class="cx"> PASS new (class extends null { constructor() { super() } }) did not throw exception.
</span><ins>+PASS new (class { constructor() { super() } }) threw exception SyntaxError: Cannot call super() in a base class constructor..
+PASS function x() { super(); } threw exception SyntaxError: Cannot call super() outside of a class constructor..
+PASS new (class extends Object { constructor() { function x() { super() } } }) threw exception SyntaxError: Cannot call super() outside of a class constructor..
+PASS new (class extends Object { constructor() { function x() { super.method } } }) threw exception SyntaxError: super can only be used in a method of a derived class..
+PASS function x() { super.method(); } threw exception SyntaxError: super can only be used in a method of a derived class..
+PASS function x() { super(); } threw exception SyntaxError: Cannot call super() outside of a class constructor..
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx">
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsclasssyntaxsuperjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/class-syntax-super.js (181403 => 181404)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/class-syntax-super.js        2015-03-11 20:27:42 UTC (rev 181403)
+++ trunk/LayoutTests/js/script-tests/class-syntax-super.js        2015-03-11 21:03:24 UTC (rev 181404)
</span><span class="lines">@@ -61,5 +61,11 @@
</span><span class="cx"> shouldThrow('new (class extends null { constructor() { } })', '"TypeError: Cannot return a non-object type in the constructor of a derived class."');
</span><span class="cx"> shouldThrow('new (class extends null { constructor() { return 1; } })', '"TypeError: Cannot return a non-object type in the constructor of a derived class."');
</span><span class="cx"> shouldNotThrow('new (class extends null { constructor() { super() } })');
</span><ins>+shouldThrow('new (class { constructor() { super() } })', '"SyntaxError: Cannot call super() in a base class constructor."');
+shouldThrow('function x() { super(); }', '"SyntaxError: Cannot call super() outside of a class constructor."');
+shouldThrow('new (class extends Object { constructor() { function x() { super() } } })', '"SyntaxError: Cannot call super() outside of a class constructor."');
+shouldThrow('new (class extends Object { constructor() { function x() { super.method } } })', '"SyntaxError: super can only be used in a method of a derived class."');
+shouldThrow('function x() { super.method(); }', '"SyntaxError: super can only be used in a method of a derived class."');
+shouldThrow('function x() { super(); }', '"SyntaxError: Cannot call super() outside of a class constructor."');
</ins><span class="cx">
</span><span class="cx"> var successfullyParsed = true;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (181403 => 181404)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-03-11 20:27:42 UTC (rev 181403)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-03-11 21:03:24 UTC (rev 181404)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2015-03-11 Ryosuke Niwa <rniwa@webkit.org>
+
+ Calling super() in a base class results in a crash
+ https://bugs.webkit.org/show_bug.cgi?id=142563
+
+ Reviewed by Filip Pizlo.
+
+ The bug was caused by BytecodeGenerator trying to generate "super" expression inside the constructor of a base class.
+ Disallow that by keeping track of whether "super" has been used in the current scope or not (needsSuperBinding flag)
+ and then throwing a syntax error in parseFunctionInfo if it was used and the current scope wasn't the constructor of
+ a derived class.
+
+ * parser/Parser.cpp:
+ (JSC::Parser<LexerType>::parseFunctionInfo): Don't allow super() or super.foo outside the constructor of a derived class.
+ (JSC::Parser<LexerType>::parseClass): Pass in the constructor kind to parseGetterSetter.
+ (JSC::Parser<LexerType>::parseGetterSetter): Ditto to parseFunctionInfo.
+ (JSC::Parser<LexerType>::parseMemberExpression): Set needsSuperBinding flag true on the containing scope.
+ * parser/Parser.h:
+ (JSC::Scope::Scope):
+ (JSC::Scope::needsSuperBinding): Added.
+ (JSC::Scope::setNeedsSuperBinding): Added.
+
</ins><span class="cx"> 2015-03-10 Darin Adler <darin@apple.com>
</span><span class="cx">
</span><span class="cx"> Some event handler fixes
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Parser.cpp (181403 => 181404)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Parser.cpp        2015-03-11 20:27:42 UTC (rev 181403)
+++ trunk/Source/JavaScriptCore/parser/Parser.cpp        2015-03-11 21:03:24 UTC (rev 181404)
</span><span class="lines">@@ -1377,9 +1377,13 @@
</span><span class="cx"> semanticFailIfTrue(m_vm->propertyNames->eval == *info.name, "'", info.name->impl(), "' is not a valid function name in strict mode");
</span><span class="cx"> }
</span><span class="cx"> if (functionScope->hasDirectSuper()) {
</span><del>- bool nameIsConstructor = info.name && *info.name == m_vm->propertyNames->constructor;
- semanticFailIfTrue(mode != MethodMode || !nameIsConstructor, "Cannot call super() outside of a class constructor");
</del><ins>+ bool isClassConstructor = mode == MethodMode && info.name && *info.name == m_vm->propertyNames->constructor;
+ semanticFailIfTrue(!isClassConstructor, "Cannot call super() outside of a class constructor");
+ semanticFailIfTrue(constructorKind == ConstructorKind::Base, "Cannot call super() in a base class constructor");
</ins><span class="cx"> }
</span><ins>+ if (functionScope->needsSuperBinding())
+ semanticFailIfTrue(constructorKind == ConstructorKind::Base, "super can only be used in a method of a derived class");
+
</ins><span class="cx"> info.closeBraceOffset = m_token.m_data.offset;
</span><span class="cx"> unsigned closeBraceLine = m_token.m_data.line;
</span><span class="cx"> unsigned closeBraceLineStartOffset = m_token.m_data.lineStartOffset;
</span><span class="lines">@@ -1503,7 +1507,7 @@
</span><span class="cx"> if (isGetter || isSetter) {
</span><span class="cx"> semanticFailIfTrue(isStaticMethod, "Cannot declare a static", stringForFunctionMode(isGetter ? GetterMode : SetterMode));
</span><span class="cx"> nextExpectIdentifier(LexerFlagsIgnoreReservedWords);
</span><del>- property = parseGetterSetter(context, alwaysStrictInsideClass, isGetter ? PropertyNode::Getter : PropertyNode::Setter, methodStart, SuperBinding::Needed);
</del><ins>+ property = parseGetterSetter(context, alwaysStrictInsideClass, isGetter ? PropertyNode::Getter : PropertyNode::Setter, methodStart, constructorKind, SuperBinding::Needed);
</ins><span class="cx"> failIfFalse(property, "Cannot parse this method");
</span><span class="cx"> } else {
</span><span class="cx"> ParserFunctionInfo<TreeBuilder> methodInfo;
</span><span class="lines">@@ -2018,7 +2022,8 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> template <typename LexerType>
</span><del>-template <class TreeBuilder> TreeProperty Parser<LexerType>::parseGetterSetter(TreeBuilder& context, bool strict, PropertyNode::Type type, unsigned getterOrSetterStartOffset, SuperBinding superBinding)
</del><ins>+template <class TreeBuilder> TreeProperty Parser<LexerType>::parseGetterSetter(TreeBuilder& context, bool strict, PropertyNode::Type type, unsigned getterOrSetterStartOffset,
+ ConstructorKind constructorKind, SuperBinding superBinding)
</ins><span class="cx"> {
</span><span class="cx"> const Identifier* stringPropertyName = 0;
</span><span class="cx"> double numericPropertyName = 0;
</span><span class="lines">@@ -2033,10 +2038,10 @@
</span><span class="cx"> ParserFunctionInfo<TreeBuilder> info;
</span><span class="cx"> if (type == PropertyNode::Getter) {
</span><span class="cx"> failIfFalse(match(OPENPAREN), "Expected a parameter list for getter definition");
</span><del>- failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, GetterMode, false, ConstructorKind::Base, info)), "Cannot parse getter definition");
</del><ins>+ failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, GetterMode, false, constructorKind, info)), "Cannot parse getter definition");
</ins><span class="cx"> } else {
</span><span class="cx"> failIfFalse(match(OPENPAREN), "Expected a parameter list for setter definition");
</span><del>- failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SetterMode, false, ConstructorKind::Base, info)), "Cannot parse setter definition");
</del><ins>+ failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SetterMode, false, constructorKind, info)), "Cannot parse setter definition");
</ins><span class="cx"> }
</span><span class="cx"> if (stringPropertyName)
</span><span class="cx"> return context.createGetterOrSetterProperty(location, type, strict, stringPropertyName, info, getterOrSetterStartOffset, superBinding);
</span><span class="lines">@@ -2384,6 +2389,7 @@
</span><span class="cx"> if (baseIsSuper) {
</span><span class="cx"> base = context.superExpr(location);
</span><span class="cx"> next();
</span><ins>+ currentScope()->setNeedsSuperBinding();
</ins><span class="cx"> } else
</span><span class="cx"> base = parsePrimaryExpression(context);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Parser.h (181403 => 181404)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Parser.h        2015-03-11 20:27:42 UTC (rev 181403)
+++ trunk/Source/JavaScriptCore/parser/Parser.h        2015-03-11 21:03:24 UTC (rev 181404)
</span><span class="lines">@@ -114,6 +114,7 @@
</span><span class="cx"> , m_usesEval(false)
</span><span class="cx"> , m_needsFullActivation(false)
</span><span class="cx"> , m_hasDirectSuper(false)
</span><ins>+ , m_needsSuperBinding(false)
</ins><span class="cx"> , m_allowsNewDecls(true)
</span><span class="cx"> , m_strictMode(strictMode)
</span><span class="cx"> , m_isFunction(isFunction)
</span><span class="lines">@@ -130,6 +131,7 @@
</span><span class="cx"> , m_usesEval(rhs.m_usesEval)
</span><span class="cx"> , m_needsFullActivation(rhs.m_needsFullActivation)
</span><span class="cx"> , m_hasDirectSuper(rhs.m_hasDirectSuper)
</span><ins>+ , m_needsSuperBinding(rhs.m_needsSuperBinding)
</ins><span class="cx"> , m_allowsNewDecls(rhs.m_allowsNewDecls)
</span><span class="cx"> , m_strictMode(rhs.m_strictMode)
</span><span class="cx"> , m_isFunction(rhs.m_isFunction)
</span><span class="lines">@@ -272,6 +274,13 @@
</span><span class="cx"> #endif
</span><span class="cx"> void setHasDirectSuper() { m_hasDirectSuper = true; }
</span><span class="cx">
</span><ins>+#if ENABLE(ES6_CLASS_SYNTAX)
+ bool needsSuperBinding() { return m_needsSuperBinding; }
+#else
+ bool needsSuperBinding() { return false; }
+#endif
+ void setNeedsSuperBinding() { m_needsSuperBinding = true; }
+
</ins><span class="cx"> bool collectFreeVariables(Scope* nestedScope, bool shouldTrackClosedVariables)
</span><span class="cx"> {
</span><span class="cx"> if (nestedScope->m_usesEval)
</span><span class="lines">@@ -366,6 +375,7 @@
</span><span class="cx"> bool m_usesEval : 1;
</span><span class="cx"> bool m_needsFullActivation : 1;
</span><span class="cx"> bool m_hasDirectSuper : 1;
</span><ins>+ bool m_needsSuperBinding : 1;
</ins><span class="cx"> bool m_allowsNewDecls : 1;
</span><span class="cx"> bool m_strictMode : 1;
</span><span class="cx"> bool m_isFunction : 1;
</span><span class="lines">@@ -748,7 +758,7 @@
</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><span class="cx"> template <class TreeBuilder> TreeExpression parsePropertyMethod(TreeBuilder& context, const Identifier* methodName);
</span><del>- template <class TreeBuilder> TreeProperty parseGetterSetter(TreeBuilder&, bool strict, PropertyNode::Type, unsigned getterOrSetterStartOffset, SuperBinding = SuperBinding::NotNeeded);
</del><ins>+ template <class TreeBuilder> TreeProperty parseGetterSetter(TreeBuilder&, bool strict, PropertyNode::Type, unsigned getterOrSetterStartOffset, ConstructorKind = ConstructorKind::Base, SuperBinding = SuperBinding::NotNeeded);
</ins><span class="cx"> template <class TreeBuilder> ALWAYS_INLINE TreeFunctionBody parseFunctionBody(TreeBuilder&, ConstructorKind);
</span><span class="cx"> template <class TreeBuilder> ALWAYS_INLINE TreeFormalParameterList parseFormalParameters(TreeBuilder&);
</span><span class="cx"> enum VarDeclarationListContext { ForLoopContext, VarDeclarationContext };
</span></span></pre>
</div>
</div>
</body>
</html>