Title: [179682] trunk
Revision
179682
Author
saambara...@gmail.com
Date
2015-02-05 00:58:38 -0800 (Thu, 05 Feb 2015)

Log Message

Crash in uninitialized deconstructing variable.
https://bugs.webkit.org/show_bug.cgi?id=141070

Reviewed by Michael Saboff.

Source/_javascript_Core:

According to the ES6 spec, when a destructuring pattern occurs
as the left hand side of an assignment inside a var declaration 
statement, the assignment must also have a right hand side value.
"var {x} = {};" is a legal syntactic statement, but,
"var {x};" is a syntactic error.

Section 13.2.2 of the latest draft ES6 spec specifies this requirement:
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-variable-statement

* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseVarDeclaration):
(JSC::Parser<LexerType>::parseVarDeclarationList):
(JSC::Parser<LexerType>::parseForStatement):
* parser/Parser.h:

LayoutTests:

* js/parser-syntax-check-expected.txt:
* js/script-tests/parser-syntax-check.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (179681 => 179682)


--- trunk/LayoutTests/ChangeLog	2015-02-05 08:58:14 UTC (rev 179681)
+++ trunk/LayoutTests/ChangeLog	2015-02-05 08:58:38 UTC (rev 179682)
@@ -1,3 +1,13 @@
+2015-02-05  Saam Barati  <saambara...@gmail.com>
+
+        Crash in uninitialized deconstructing variable.
+        https://bugs.webkit.org/show_bug.cgi?id=141070
+
+        Reviewed by Michael Saboff.
+
+        * js/parser-syntax-check-expected.txt:
+        * js/script-tests/parser-syntax-check.js:
+
 2015-02-04  Brent Fulgham  <bfulg...@apple.com>
 
         [Win] Reactive (some) Media tests. Test results gardening.

Modified: trunk/LayoutTests/js/parser-syntax-check-expected.txt (179681 => 179682)


--- trunk/LayoutTests/js/parser-syntax-check-expected.txt	2015-02-05 08:58:14 UTC (rev 179681)
+++ trunk/LayoutTests/js/parser-syntax-check-expected.txt	2015-02-05 08:58:38 UTC (rev 179682)
@@ -678,6 +678,12 @@
 PASS Valid:   "function f() { for ([of] in of){} }"
 PASS Valid:   "for ({of} in of){}" with ReferenceError
 PASS Valid:   "function f() { for ({of} in of){} }"
+PASS Invalid: "for (var of = x of of){}"
+PASS Invalid: "function f() { for (var of = x of of){} }"
+PASS Invalid: "for (var {of} = x of of){}"
+PASS Invalid: "function f() { for (var {of} = x of of){} }"
+PASS Invalid: "for (var [of] = x of of){}"
+PASS Invalid: "function f() { for (var [of] = x of of){} }"
 PASS Invalid: "for (of of of of){}"
 PASS Invalid: "function f() { for (of of of of){} }"
 PASS Invalid: "for (of of; of; of){}"
@@ -765,6 +771,14 @@
 PASS Valid:   "function f() { 'use strict'; ({a: b}=null) }"
 PASS Valid:   "var {1:x}=1"
 PASS Valid:   "function f() { var {1:x}=1 }"
+PASS Valid:   "var {x}=1"
+PASS Valid:   "function f() { var {x}=1 }"
+PASS Valid:   "var {x, y}=1"
+PASS Valid:   "function f() { var {x, y}=1 }"
+PASS Valid:   "var [x]=1"
+PASS Valid:   "function f() { var [x]=1 }"
+PASS Valid:   "var [x, y]=1"
+PASS Valid:   "function f() { var [x, y]=1 }"
 PASS Valid:   "[x]=1"
 PASS Valid:   "function f() { [x]=1 }"
 PASS Valid:   "var [x]=1"
@@ -787,6 +801,20 @@
 PASS Valid:   "function f() { ({a}=1=1) }"
 PASS Valid:   "({a:a}=1=1)" with ReferenceError
 PASS Valid:   "function f() { ({a:a}=1=1) }"
+PASS Invalid: "var {x}"
+PASS Invalid: "function f() { var {x} }"
+PASS Invalid: "var {x, y}"
+PASS Invalid: "function f() { var {x, y} }"
+PASS Invalid: "var {x} = 20, {x, y}"
+PASS Invalid: "function f() { var {x} = 20, {x, y} }"
+PASS Invalid: "var {foo:bar, bar:baz}"
+PASS Invalid: "function f() { var {foo:bar, bar:baz} }"
+PASS Invalid: "var [x]"
+PASS Invalid: "function f() { var [x] }"
+PASS Invalid: "var [x, y]"
+PASS Invalid: "function f() { var [x, y] }"
+PASS Invalid: "var [x] = [], [x, y]"
+PASS Invalid: "function f() { var [x] = [], [x, y] }"
 PASS Invalid: "({get [x](){}})"
 PASS Invalid: "function f() { ({get [x](){}}) }"
 PASS Invalid: "({set [x](){}})"

Modified: trunk/LayoutTests/js/script-tests/parser-syntax-check.js (179681 => 179682)


--- trunk/LayoutTests/js/script-tests/parser-syntax-check.js	2015-02-05 08:58:14 UTC (rev 179681)
+++ trunk/LayoutTests/js/script-tests/parser-syntax-check.js	2015-02-05 08:58:38 UTC (rev 179682)
@@ -428,6 +428,9 @@
 valid("for (var {of} in of){}")
 valid("for ([of] in of){}")
 valid("for ({of} in of){}")
+invalid("for (var of = x of of){}")
+invalid("for (var {of} = x of of){}")
+invalid("for (var [of] = x of of){}")
 
 
 invalid("for (of of of of){}")
@@ -475,6 +478,10 @@
 valid("'use strict'; ({1: x}=null)")
 valid("'use strict'; ({a: b}=null)")
 valid("var {1:x}=1")
+valid("var {x}=1")
+valid("var {x, y}=1")
+valid("var [x]=1")
+valid("var [x, y]=1")
 valid("[x]=1")
 valid("var [x]=1")
 valid("({[x]: 1})")
@@ -486,6 +493,13 @@
 valid("({a:a}=1)=1")
 valid("({a}=1=1)")
 valid("({a:a}=1=1)")
+invalid("var {x}")
+invalid("var {x, y}")
+invalid("var {x} = 20, {x, y}")
+invalid("var {foo:bar, bar:baz}")
+invalid("var [x]")
+invalid("var [x, y]")
+invalid("var [x] = [], [x, y]")
 invalid("({get [x](){}})")
 invalid("({set [x](){}})")
 invalid("({[...x]: 1})")

Modified: trunk/Source/_javascript_Core/ChangeLog (179681 => 179682)


--- trunk/Source/_javascript_Core/ChangeLog	2015-02-05 08:58:14 UTC (rev 179681)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-02-05 08:58:38 UTC (rev 179682)
@@ -1,3 +1,25 @@
+2015-02-05  Saam Barati  <saambara...@gmail.com>
+
+        Crash in uninitialized deconstructing variable.
+        https://bugs.webkit.org/show_bug.cgi?id=141070
+
+        Reviewed by Michael Saboff.
+
+        According to the ES6 spec, when a destructuring pattern occurs
+        as the left hand side of an assignment inside a var declaration 
+        statement, the assignment must also have a right hand side value.
+        "var {x} = {};" is a legal syntactic statement, but,
+        "var {x};" is a syntactic error.
+
+        Section 13.2.2 of the latest draft ES6 spec specifies this requirement:
+        https://people.mozilla.org/~jorendorff/es6-draft.html#sec-variable-statement
+
+        * parser/Parser.cpp:
+        (JSC::Parser<LexerType>::parseVarDeclaration):
+        (JSC::Parser<LexerType>::parseVarDeclarationList):
+        (JSC::Parser<LexerType>::parseForStatement):
+        * parser/Parser.h:
+
 2015-02-04  Gyuyoung Kim  <gyuyoung....@samsung.com>
 
         Unreviewed, fix a build break on EFL port since r179648.

Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (179681 => 179682)


--- trunk/Source/_javascript_Core/parser/Parser.cpp	2015-02-05 08:58:14 UTC (rev 179681)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp	2015-02-05 08:58:38 UTC (rev 179682)
@@ -378,7 +378,7 @@
     TreeDeconstructionPattern scratch1 = 0;
     TreeExpression scratch2 = 0;
     JSTextPosition scratch3;
-    TreeExpression varDecls = parseVarDeclarationList(context, scratch, scratch1, scratch2, scratch3, scratch3, scratch3);
+    TreeExpression varDecls = parseVarDeclarationList(context, scratch, scratch1, scratch2, scratch3, scratch3, scratch3, VarDeclarationContext);
     propagateError();
     failIfFalse(autoSemiColon(), "Expected ';' after var declaration");
     
@@ -447,7 +447,7 @@
 }
 
 template <typename LexerType>
-template <class TreeBuilder> TreeExpression Parser<LexerType>::parseVarDeclarationList(TreeBuilder& context, int& declarations, TreeDeconstructionPattern& lastPattern, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd)
+template <class TreeBuilder> TreeExpression Parser<LexerType>::parseVarDeclarationList(TreeBuilder& context, int& declarations, TreeDeconstructionPattern& lastPattern, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd, VarDeclarationListContext declarationListContext)
 {
     TreeExpression head = 0;
     TreeExpression tail = 0;
@@ -487,6 +487,7 @@
             auto pattern = parseDeconstructionPattern(context, DeconstructToVariables);
             failIfFalse(pattern, "Cannot parse this deconstruction pattern");
             hasInitializer = match(EQUAL);
+            failIfTrue(declarationListContext == VarDeclarationContext && !hasInitializer, "Expected an initializer in destructuring variable declaration");
             lastPattern = pattern;
             if (hasInitializer) {
                 next(TreeBuilder::DontBuildStrings); // consume '='
@@ -735,7 +736,7 @@
         m_allowsIn = false;
         JSTextPosition initStart;
         JSTextPosition initEnd;
-        decls = parseVarDeclarationList(context, declarations, forInTarget, forInInitializer, declsStart, initStart, initEnd);
+        decls = parseVarDeclarationList(context, declarations, forInTarget, forInInitializer, declsStart, initStart, initEnd, ForLoopContext);
         m_allowsIn = true;
         propagateError();
 

Modified: trunk/Source/_javascript_Core/parser/Parser.h (179681 => 179682)


--- trunk/Source/_javascript_Core/parser/Parser.h	2015-02-05 08:58:14 UTC (rev 179681)
+++ trunk/Source/_javascript_Core/parser/Parser.h	2015-02-05 08:58:38 UTC (rev 179682)
@@ -742,7 +742,8 @@
     template <class TreeBuilder> TreeProperty parseGetterSetter(TreeBuilder&, bool strict, PropertyNode::Type, unsigned getterOrSetterStartOffset);
     template <class TreeBuilder> ALWAYS_INLINE TreeFunctionBody parseFunctionBody(TreeBuilder&);
     template <class TreeBuilder> ALWAYS_INLINE TreeFormalParameterList parseFormalParameters(TreeBuilder&);
-    template <class TreeBuilder> TreeExpression parseVarDeclarationList(TreeBuilder&, int& declarations, TreeDeconstructionPattern& lastPattern, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd);
+    enum VarDeclarationListContext { ForLoopContext, VarDeclarationContext };
+    template <class TreeBuilder> TreeExpression parseVarDeclarationList(TreeBuilder&, int& declarations, TreeDeconstructionPattern& lastPattern, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd, VarDeclarationListContext);
     template <class TreeBuilder> NEVER_INLINE TreeConstDeclList parseConstDeclarationList(TreeBuilder&);
 
     template <class TreeBuilder> NEVER_INLINE TreeDeconstructionPattern createBindingPattern(TreeBuilder&, DeconstructionKind, const Identifier&, int depth, JSToken);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to