Modified: trunk/Source/_javascript_Core/ChangeLog (173025 => 173026)
--- trunk/Source/_javascript_Core/ChangeLog 2014-08-27 22:25:33 UTC (rev 173025)
+++ trunk/Source/_javascript_Core/ChangeLog 2014-08-27 22:34:02 UTC (rev 173026)
@@ -1,3 +1,23 @@
+2014-08-27 Saam Barati <[email protected]>
+
+ Deconstruction object pattern node emits the wrong start/end text positions
+ https://bugs.webkit.org/show_bug.cgi?id=136304
+
+ Reviewed by Geoffrey Garen.
+
+ Object pattern nodes that used the syntactic sugar binding:
+ 'var {foo} = {foo:20}' instead of 'var {foo:foo} = {foo:20}'
+ would get the wrong text position for variable 'foo'. The position
+ would be placed on the comma(s)/closing brace instead of the identifier.
+ This patch fixes this bug by caching the identifier's JSToken before
+ trying to parse an optional colon.
+
+ * parser/Parser.cpp:
+ (JSC::Parser<LexerType>::parseVarDeclarationList):
+ (JSC::Parser<LexerType>::createBindingPattern):
+ (JSC::Parser<LexerType>::parseDeconstructionPattern):
+ * parser/Parser.h:
+
2014-08-27 Brent Fulgham <[email protected]>
[Win] Build fix after last commit.
Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (173025 => 173026)
--- trunk/Source/_javascript_Core/parser/Parser.cpp 2014-08-27 22:25:33 UTC (rev 173025)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp 2014-08-27 22:34:02 UTC (rev 173026)
@@ -498,12 +498,12 @@
varDecls = context.combineCommaNodes(location, varDecls, node);
} while (match(COMMA));
if (lastIdent)
- lastPattern = createBindingPattern(context, DeconstructToVariables, *lastIdent, 0);
+ lastPattern = createBindingPattern(context, DeconstructToVariables, *lastIdent, 0, m_token);
return varDecls;
}
template <typename LexerType>
-template <class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, DeconstructionKind kind, const Identifier& name, int depth)
+template <class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, DeconstructionKind kind, const Identifier& name, int depth, JSToken token)
{
ASSERT(!name.isEmpty());
ASSERT(!name.isNull());
@@ -552,7 +552,7 @@
}
}
}
- return context.createBindingLocation(m_token.m_location, name, m_token.m_startPosition, m_token.m_endPosition);
+ return context.createBindingLocation(token.m_location, name, token.m_startPosition, token.m_endPosition);
}
template <typename LexerType>
@@ -610,11 +610,12 @@
JSTokenLocation location = m_token.m_location;
if (match(IDENT)) {
propertyName = *m_token.m_data.ident;
+ JSToken identifierToken = m_token;
next();
if (consume(COLON))
innerPattern = parseDeconstructionPattern(context, kind, depth + 1);
else
- innerPattern = createBindingPattern(context, kind, propertyName, depth);
+ innerPattern = createBindingPattern(context, kind, propertyName, depth, identifierToken);
} else {
JSTokenType tokenType = m_token.m_type;
switch (m_token.m_type) {
@@ -665,7 +666,7 @@
semanticFailureDueToKeyword("variable name");
failWithMessage("Expected a parameter pattern or a ')' in parameter list");
}
- pattern = createBindingPattern(context, kind, *m_token.m_data.ident, depth);
+ pattern = createBindingPattern(context, kind, *m_token.m_data.ident, depth, m_token);
next();
break;
}
Modified: trunk/Source/_javascript_Core/parser/Parser.h (173025 => 173026)
--- trunk/Source/_javascript_Core/parser/Parser.h 2014-08-27 22:25:33 UTC (rev 173025)
+++ trunk/Source/_javascript_Core/parser/Parser.h 2014-08-27 22:34:02 UTC (rev 173026)
@@ -727,7 +727,7 @@
template <class TreeBuilder> TreeExpression parseVarDeclarationList(TreeBuilder&, int& declarations, TreeDeconstructionPattern& lastPattern, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd);
template <class TreeBuilder> NEVER_INLINE TreeConstDeclList parseConstDeclarationList(TreeBuilder&);
- template <class TreeBuilder> NEVER_INLINE TreeDeconstructionPattern createBindingPattern(TreeBuilder&, DeconstructionKind, const Identifier&, int depth);
+ template <class TreeBuilder> NEVER_INLINE TreeDeconstructionPattern createBindingPattern(TreeBuilder&, DeconstructionKind, const Identifier&, int depth, JSToken);
template <class TreeBuilder> NEVER_INLINE TreeDeconstructionPattern parseDeconstructionPattern(TreeBuilder&, DeconstructionKind, int depth = 0);
template <class TreeBuilder> NEVER_INLINE TreeDeconstructionPattern tryParseDeconstructionPatternExpression(TreeBuilder&);
template <class TreeBuilder> NEVER_INLINE bool parseFunctionInfo(TreeBuilder&, FunctionRequirements, FunctionParseMode, bool nameIsInContainingScope, const Identifier*&, TreeFormalParameterList&, TreeFunctionBody&, unsigned& openBraceOffset, unsigned& closeBraceOffset, int& bodyStartLine, unsigned& bodyStartColumn);