#define TreeFunctionBody typename TreeBuilder::FunctionBody
#define TreeProperty typename TreeBuilder::Property
#define TreePropertyList typename TreeBuilder::PropertyList
+#define TreeDeconstructionPattern typename TreeBuilder::DeconstructionPattern
COMPILE_ASSERT(LastUntaggedToken < 64, LessThan64UntaggedTokens);
enum SourceElementsMode { CheckForStrictMode, DontCheckForStrictMode };
enum FunctionRequirements { FunctionNoRequirements, FunctionNeedsName };
+enum FunctionParseMode { FunctionMode, GetterMode, SetterMode };
+enum DeconstructionKind {
+ DeconstructToVariables,
+ DeconstructToParameters,
+ DeconstructToExpressions
+};
template <typename T> inline bool isEvalNode() { return false; }
template <> inline bool isEvalNode<EvalNode>() { return true; }
-struct DepthManager {
- DepthManager(int* depth)
- : m_originalDepth(*depth)
- , m_depth(depth)
- {
- }
-
- ~DepthManager()
- {
- *m_depth = m_originalDepth;
- }
-
-private:
- int m_originalDepth;
- int* m_depth;
-};
-
struct ScopeLabelInfo {
ScopeLabelInfo(StringImpl* ident, bool isLoop)
: m_ident(ident)
return isValidStrictMode;
}
+ bool hasDeclaredVariable(const Identifier& ident)
+ {
+ return m_declaredVariables.contains(ident.impl());
+ }
+
+ bool hasDeclaredParameter(const Identifier& ident)
+ {
+ return m_declaredParameters.contains(ident.impl()) || m_declaredVariables.contains(ident.impl());
+ }
+
void declareWrite(const Identifier* ident)
{
ASSERT(m_strictMode);
bool isArguments = m_vm->propertyNames->arguments == *ident;
bool isValidStrictMode = m_declaredVariables.add(ident->string().impl()).isNewEntry && m_vm->propertyNames->eval != *ident && !isArguments;
m_isValidStrictMode = m_isValidStrictMode && isValidStrictMode;
+ m_declaredParameters.add(ident->string().impl());
+
if (isArguments)
m_shadowsArguments = true;
return isValidStrictMode;
}
+
+ enum BindingResult {
+ BindingFailed,
+ StrictBindingFailed,
+ BindingSucceeded
+ };
+ BindingResult declareBoundParameter(const Identifier* ident)
+ {
+ bool isArguments = m_vm->propertyNames->arguments == *ident;
+ bool newEntry = m_declaredVariables.add(ident->string().impl()).isNewEntry;
+ bool isValidStrictMode = newEntry && m_vm->propertyNames->eval != *ident && !isArguments;
+ m_isValidStrictMode = m_isValidStrictMode && isValidStrictMode;
+
+ if (isArguments)
+ m_shadowsArguments = true;
+ if (!newEntry)
+ return BindingFailed;
+ return isValidStrictMode ? BindingSucceeded : StrictBindingFailed;
+ }
+
+ void getUsedVariables(IdentifierSet& usedVariables)
+ {
+ usedVariables.swap(m_usedVariables);
+ }
void useVariable(const Identifier* ident, bool isEval)
{
return true;
}
- void getUncapturedWrittenVariables(IdentifierSet& writtenVariables)
- {
- IdentifierSet::iterator end = m_writtenVariables.end();
- for (IdentifierSet::iterator ptr = m_writtenVariables.begin(); ptr != end; ++ptr) {
- if (!m_declaredVariables.contains(*ptr))
- writtenVariables.add(*ptr);
- }
- }
-
- void getCapturedVariables(IdentifierSet& capturedVariables)
+ void getCapturedVariables(IdentifierSet& capturedVariables, bool& modifiedParameter)
{
if (m_needsFullActivation || m_usesEval) {
+ modifiedParameter = true;
capturedVariables.swap(m_declaredVariables);
return;
}
continue;
capturedVariables.add(*ptr);
}
+ modifiedParameter = false;
+ if (m_declaredParameters.size()) {
+ IdentifierSet::iterator end = m_writtenVariables.end();
+ for (IdentifierSet::iterator ptr = m_writtenVariables.begin(); ptr != end; ++ptr) {
+ if (!m_declaredParameters.contains(*ptr))
+ continue;
+ modifiedParameter = true;
+ break;
+ }
+ }
}
void setStrictMode() { m_strictMode = true; }
bool strictMode() const { return m_strictMode; }
bool isValidStrictMode() const { return m_isValidStrictMode; }
bool shadowsArguments() const { return m_shadowsArguments; }
- void copyCapturedVariablesToVector(const IdentifierSet& capturedVariables, Vector<RefPtr<StringImpl> >& vector)
+ void copyCapturedVariablesToVector(const IdentifierSet& capturedVariables, Vector<RefPtr<StringImpl>>& vector)
{
IdentifierSet::iterator end = capturedVariables.end();
for (IdentifierSet::iterator it = capturedVariables.begin(); it != end; ++it) {
typedef Vector<ScopeLabelInfo, 2> LabelStack;
OwnPtr<LabelStack> m_labels;
+ IdentifierSet m_declaredParameters;
IdentifierSet m_declaredVariables;
IdentifierSet m_usedVariables;
IdentifierSet m_closedVariables;
~Parser();
template <class ParsedNode>
- PassRefPtr<ParsedNode> parse(ParserError&);
+ PassRefPtr<ParsedNode> parse(ParserError&, bool needReparsingAdjustment);
+
+ JSTextPosition positionBeforeLastNewline() const { return m_lexer->positionBeforeLastNewline(); }
+ Vector<RefPtr<StringImpl>>&& closedVariables() { return WTF::move(m_closedVariables); }
private:
struct AllowInOverride {
return m_scopeStack[i].declareVariable(ident);
}
+ NEVER_INLINE bool hasDeclaredVariable(const Identifier& ident)
+ {
+ unsigned i = m_scopeStack.size() - 1;
+ ASSERT(i < m_scopeStack.size());
+ while (!m_scopeStack[i].allowsNewDecls()) {
+ i--;
+ ASSERT(i < m_scopeStack.size());
+ }
+ return m_scopeStack[i].hasDeclaredVariable(ident);
+ }
+
+ NEVER_INLINE bool hasDeclaredParameter(const Identifier& ident)
+ {
+ unsigned i = m_scopeStack.size() - 1;
+ ASSERT(i < m_scopeStack.size());
+ while (!m_scopeStack[i].allowsNewDecls()) {
+ i--;
+ ASSERT(i < m_scopeStack.size());
+ }
+ return m_scopeStack[i].hasDeclaredParameter(ident);
+ }
+
void declareWrite(const Identifier* ident)
{
- if (!m_syntaxAlreadyValidated)
+ if (!m_syntaxAlreadyValidated || strictMode())
m_scopeStack.last().declareWrite(ident);
}
String parseInner();
void didFinishParsing(SourceElements*, ParserArenaData<DeclarationStacks::VarStack>*,
- ParserArenaData<DeclarationStacks::FunctionStack>*, CodeFeatures,
- int, int, IdentifierSet&);
+ ParserArenaData<DeclarationStacks::FunctionStack>*, CodeFeatures, int, IdentifierSet&, const Vector<RefPtr<StringImpl>>&&);
// Used to determine type of error to report.
bool isFunctionBodyNode(ScopeNode*) { return false; }
ALWAYS_INLINE void next(unsigned lexerFlags = 0)
{
- m_lastLine = m_token.m_location.line;
- m_lastTokenEnd = m_token.m_location.endOffset;
- m_lastTokenLineStart = m_token.m_location.lineStartOffset;
- m_lexer->setLastLineNumber(m_lastLine);
- m_token.m_type = m_lexer->lex(&m_token.m_data, &m_token.m_location, lexerFlags, strictMode());
+ int lastLine = m_token.m_location.line;
+ int lastTokenEnd = m_token.m_location.endOffset;
+ int lastTokenLineStart = m_token.m_location.lineStartOffset;
+ m_lastTokenEndPosition = JSTextPosition(lastLine, lastTokenEnd, lastTokenLineStart);
+ m_lexer->setLastLineNumber(lastLine);
+ m_token.m_type = m_lexer->lex(&m_token, lexerFlags, strictMode());
}
ALWAYS_INLINE void nextExpectIdentifier(unsigned lexerFlags = 0)
{
- m_lastLine = m_token.m_location.line;
- m_lastTokenEnd = m_token.m_location.endOffset;
- m_lastTokenLineStart = m_token.m_location.lineStartOffset;
- m_lexer->setLastLineNumber(m_lastLine);
- m_token.m_type = m_lexer->lexExpectIdentifier(&m_token.m_data, &m_token.m_location, lexerFlags, strictMode());
+ int lastLine = m_token.m_location.line;
+ int lastTokenEnd = m_token.m_location.endOffset;
+ int lastTokenLineStart = m_token.m_location.lineStartOffset;
+ m_lastTokenEndPosition = JSTextPosition(lastLine, lastTokenEnd, lastTokenLineStart);
+ m_lexer->setLastLineNumber(lastLine);
+ m_token.m_type = m_lexer->lexExpectIdentifier(&m_token, lexerFlags, strictMode());
}
ALWAYS_INLINE bool nextTokenIsColon()
next(flags);
return result;
}
-
+
+ void printUnexpectedTokenText(WTF::PrintStream&);
ALWAYS_INLINE String getToken() {
SourceProvider* sourceProvider = m_source->provider();
- return sourceProvider->getRange(tokenStart(), tokenEnd());
+ return sourceProvider->getRange(tokenStart(), tokenEndPosition().offset);
}
ALWAYS_INLINE bool match(JSTokenType expected)
return m_token.m_type == expected;
}
+ ALWAYS_INLINE bool isofToken()
+ {
+ return m_token.m_type == IDENT && *m_token.m_data.ident == m_vm->propertyNames->of;
+ }
+
ALWAYS_INLINE unsigned tokenStart()
{
return m_token.m_location.startOffset;
}
+ ALWAYS_INLINE const JSTextPosition& tokenStartPosition()
+ {
+ return m_token.m_startPosition;
+ }
+
ALWAYS_INLINE int tokenLine()
{
return m_token.m_location.line;
return tokenStart() - tokenLineStart();
}
- ALWAYS_INLINE unsigned tokenEnd()
+ ALWAYS_INLINE const JSTextPosition& tokenEndPosition()
{
- return m_token.m_location.endOffset;
+ return m_token.m_endPosition;
}
ALWAYS_INLINE unsigned tokenLineStart()
return m_token.m_location;
}
- const char* getTokenName(JSTokenType tok)
- {
- switch (tok) {
- case NULLTOKEN:
- return "null";
- case TRUETOKEN:
- return "true";
- case FALSETOKEN:
- return "false";
- case BREAK:
- return "break";
- case CASE:
- return "case";
- case DEFAULT:
- return "default";
- case FOR:
- return "for";
- case NEW:
- return "new";
- case VAR:
- return "var";
- case CONSTTOKEN:
- return "const";
- case CONTINUE:
- return "continue";
- case FUNCTION:
- return "function";
- case IF:
- return "if";
- case THISTOKEN:
- return "this";
- case DO:
- return "do";
- case WHILE:
- return "while";
- case SWITCH:
- return "switch";
- case WITH:
- return "with";
- case THROW:
- return "throw";
- case TRY:
- return "try";
- case CATCH:
- return "catch";
- case FINALLY:
- return "finally";
- case DEBUGGER:
- return "debugger";
- case ELSE:
- return "else";
- case OPENBRACE:
- return "{";
- case CLOSEBRACE:
- return "}";
- case OPENPAREN:
- return "(";
- case CLOSEPAREN:
- return ")";
- case OPENBRACKET:
- return "[";
- case CLOSEBRACKET:
- return "]";
- case COMMA:
- return ",";
- case QUESTION:
- return "?";
- case SEMICOLON:
- return ";";
- case COLON:
- return ":";
- case DOT:
- return ".";
- case EQUAL:
- return "=";
- case PLUSEQUAL:
- return "+=";
- case MINUSEQUAL:
- return "-=";
- case MULTEQUAL:
- return "*=";
- case DIVEQUAL:
- return "/=";
- case LSHIFTEQUAL:
- return "<<=";
- case RSHIFTEQUAL:
- return ">>=";
- case URSHIFTEQUAL:
- return ">>>=";
- case ANDEQUAL:
- return "&=";
- case MODEQUAL:
- return "%=";
- case XOREQUAL:
- return "^=";
- case OREQUAL:
- return "|=";
- case AUTOPLUSPLUS:
- case PLUSPLUS:
- return "++";
- case AUTOMINUSMINUS:
- case MINUSMINUS:
- return "--";
- case EXCLAMATION:
- return "!";
- case TILDE:
- return "~";
- case TYPEOF:
- return "typeof";
- case VOIDTOKEN:
- return "void";
- case DELETETOKEN:
- return "delete";
- case OR:
- return "||";
- case AND:
- return "&&";
- case BITOR:
- return "|";
- case BITXOR:
- return "^";
- case BITAND:
- return "&";
- case EQEQ:
- return "==";
- case NE:
- return "!=";
- case STREQ:
- return "===";
- case STRNEQ:
- return "!==";
- case LT:
- return "<";
- case GT:
- return ">";
- case LE:
- return "<=";
- case GE:
- return ">=";
- case INSTANCEOF:
- return "instanceof";
- case INTOKEN:
- return "in";
- case LSHIFT:
- return "<<";
- case RSHIFT:
- return ">>";
- case URSHIFT:
- return ">>>";
- case PLUS:
- return "+";
- case MINUS:
- return "-";
- case TIMES:
- return "*";
- case DIVIDE:
- return "/";
- case MOD:
- return "%";
- case RETURN:
- case RESERVED_IF_STRICT:
- case RESERVED:
- case NUMBER:
- case IDENT:
- case STRING:
- case UNTERMINATED_IDENTIFIER_ESCAPE_ERRORTOK:
- case UNTERMINATED_IDENTIFIER_UNICODE_ESCAPE_ERRORTOK:
- case UNTERMINATED_MULTILINE_COMMENT_ERRORTOK:
- case UNTERMINATED_NUMERIC_LITERAL_ERRORTOK:
- case UNTERMINATED_STRING_LITERAL_ERRORTOK:
- case INVALID_IDENTIFIER_ESCAPE_ERRORTOK:
- case INVALID_IDENTIFIER_UNICODE_ESCAPE_ERRORTOK:
- case INVALID_NUMERIC_LITERAL_ERRORTOK:
- case INVALID_OCTAL_NUMBER_ERRORTOK:
- case INVALID_STRING_LITERAL_ERRORTOK:
- case ERRORTOK:
- case EOFTOK:
- return 0;
- case LastUntaggedToken:
- break;
- }
- RELEASE_ASSERT_NOT_REACHED();
- return "internal error";
- }
-
- ALWAYS_INLINE void updateErrorMessageSpecialCase(JSTokenType expectedToken)
- {
- switch (expectedToken) {
- case RESERVED_IF_STRICT:
- m_errorMessage = "Use of reserved word '" + getToken() + "' in strict mode";
- return;
- case RESERVED:
- m_errorMessage = "Use of reserved word '" + getToken() + '\'';
- return;
- case NUMBER:
- m_errorMessage = "Unexpected number '" + getToken() + '\'';
- return;
- case IDENT:
- m_errorMessage = "Expected an identifier but found '" + getToken() + "' instead";
- return;
- case STRING:
- m_errorMessage = "Unexpected string " + getToken();
- return;
-
- case UNTERMINATED_IDENTIFIER_ESCAPE_ERRORTOK:
- case UNTERMINATED_IDENTIFIER_UNICODE_ESCAPE_ERRORTOK:
- m_errorMessage = "Incomplete unicode escape in identifier: '" + getToken() + '\'';
- return;
- case UNTERMINATED_MULTILINE_COMMENT_ERRORTOK:
- m_errorMessage = "Unterminated multiline comment";
- return;
- case UNTERMINATED_NUMERIC_LITERAL_ERRORTOK:
- m_errorMessage = "Unterminated numeric literal '" + getToken() + '\'';
- return;
- case UNTERMINATED_STRING_LITERAL_ERRORTOK:
- m_errorMessage = "Unterminated string literal '" + getToken() + '\'';
- return;
- case INVALID_IDENTIFIER_ESCAPE_ERRORTOK:
- m_errorMessage = "Invalid escape in identifier: '" + getToken() + '\'';
- return;
- case INVALID_IDENTIFIER_UNICODE_ESCAPE_ERRORTOK:
- m_errorMessage = "Invalid unicode escape in identifier: '" + getToken() + '\'';
- return;
- case INVALID_NUMERIC_LITERAL_ERRORTOK:
- m_errorMessage = "Invalid numeric literal: '" + getToken() + '\'';
- return;
- case INVALID_OCTAL_NUMBER_ERRORTOK:
- m_errorMessage = "Invalid use of octal: '" + getToken() + '\'';
- return;
- case INVALID_STRING_LITERAL_ERRORTOK:
- m_errorMessage = "Invalid string literal: '" + getToken() + '\'';
- return;
- case ERRORTOK:
- m_errorMessage = "Unrecognized token '" + getToken() + '\'';
- return;
- case EOFTOK:
- m_errorMessage = ASCIILiteral("Unexpected EOF");
- return;
- case RETURN:
- m_errorMessage = ASCIILiteral("Return statements are only valid inside functions");
- return;
- default:
- RELEASE_ASSERT_NOT_REACHED();
- m_errorMessage = ASCIILiteral("internal error");
- return;
- }
- }
-
- NEVER_INLINE void updateErrorMessage()
+ void setErrorMessage(String msg)
{
- const char* name = getTokenName(m_token.m_type);
- if (!name)
- updateErrorMessageSpecialCase(m_token.m_type);
- else
- m_errorMessage = String::format("Unexpected token '%s'", name);
- ASSERT(!m_errorMessage.isNull());
+ m_errorMessage = msg;
}
- NEVER_INLINE void updateErrorMessage(JSTokenType expectedToken)
- {
- const char* name = getTokenName(expectedToken);
- if (name)
- m_errorMessage = String::format("Expected token '%s'", name);
- else {
- if (!getTokenName(m_token.m_type))
- updateErrorMessageSpecialCase(m_token.m_type);
- else
- updateErrorMessageSpecialCase(expectedToken);
- }
- ASSERT(!m_errorMessage.isNull());
- }
+ NEVER_INLINE void logError(bool);
+ template <typename A> NEVER_INLINE void logError(bool, const A&);
+ template <typename A, typename B> NEVER_INLINE void logError(bool, const A&, const B&);
+ template <typename A, typename B, typename C> NEVER_INLINE void logError(bool, const A&, const B&, const C&);
+ template <typename A, typename B, typename C, typename D> NEVER_INLINE void logError(bool, const A&, const B&, const C&, const D&);
+ template <typename A, typename B, typename C, typename D, typename E> NEVER_INLINE void logError(bool, const A&, const B&, const C&, const D&, const E&);
+ template <typename A, typename B, typename C, typename D, typename E, typename F> NEVER_INLINE void logError(bool, const A&, const B&, const C&, const D&, const E&, const F&);
+ template <typename A, typename B, typename C, typename D, typename E, typename F, typename G> NEVER_INLINE void logError(bool, const A&, const B&, const C&, const D&, const E&, const F&, const G&);
NEVER_INLINE void updateErrorWithNameAndMessage(const char* beforeMsg, String name, const char* afterMsg)
{
bool strictMode() { return currentScope()->strictMode(); }
bool isValidStrictMode() { return currentScope()->isValidStrictMode(); }
bool declareParameter(const Identifier* ident) { return currentScope()->declareParameter(ident); }
+ Scope::BindingResult declareBoundParameter(const Identifier* ident) { return currentScope()->declareBoundParameter(ident); }
bool breakIsValid()
{
ScopeRef current = currentScope();
return result;
}
- template <SourceElementsMode mode, class TreeBuilder> TreeSourceElements parseSourceElements(TreeBuilder&);
+ template <class TreeBuilder> TreeSourceElements parseSourceElements(TreeBuilder&, SourceElementsMode);
template <class TreeBuilder> TreeStatement parseStatement(TreeBuilder&, const Identifier*& directive, unsigned* directiveLiteralLength = 0);
template <class TreeBuilder> TreeStatement parseFunctionDeclaration(TreeBuilder&);
template <class TreeBuilder> TreeStatement parseVarDeclaration(TreeBuilder&);
template <class TreeBuilder> TreeStatement parseExpressionStatement(TreeBuilder&);
template <class TreeBuilder> TreeStatement parseExpressionOrLabelStatement(TreeBuilder&);
template <class TreeBuilder> TreeStatement parseIfStatement(TreeBuilder&);
- template <class TreeBuilder> ALWAYS_INLINE TreeStatement parseBlockStatement(TreeBuilder&);
+ template <class TreeBuilder> TreeStatement parseBlockStatement(TreeBuilder&);
template <class TreeBuilder> TreeExpression parseExpression(TreeBuilder&);
template <class TreeBuilder> TreeExpression parseAssignmentExpression(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseConditionalExpression(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeExpression parsePrimaryExpression(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseArrayLiteral(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseObjectLiteral(TreeBuilder&);
- template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseStrictObjectLiteral(TreeBuilder&);
- template <class TreeBuilder> ALWAYS_INLINE TreeArguments parseArguments(TreeBuilder&);
- template <bool strict, class TreeBuilder> ALWAYS_INLINE TreeProperty parseProperty(TreeBuilder&);
+ template <class TreeBuilder> NEVER_INLINE TreeExpression parseStrictObjectLiteral(TreeBuilder&);
+ enum SpreadMode { AllowSpread, DontAllowSpread };
+ template <class TreeBuilder> ALWAYS_INLINE TreeArguments parseArguments(TreeBuilder&, SpreadMode);
+ template <class TreeBuilder> TreeProperty parseProperty(TreeBuilder&, bool strict);
template <class TreeBuilder> ALWAYS_INLINE TreeFunctionBody parseFunctionBody(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeFormalParameterList parseFormalParameters(TreeBuilder&);
- template <class TreeBuilder> ALWAYS_INLINE TreeExpression parseVarDeclarationList(TreeBuilder&, int& declarations, const Identifier*& lastIdent, TreeExpression& lastInitializer, int& identStart, int& initStart, int& initEnd);
- template <class TreeBuilder> ALWAYS_INLINE TreeConstDeclList parseConstDeclarationList(TreeBuilder& context);
- template <FunctionRequirements, bool nameIsInContainingScope, class TreeBuilder> bool parseFunctionInfo(TreeBuilder&, const Identifier*&, TreeFormalParameterList&, TreeFunctionBody&, unsigned& openBraceOffset, unsigned& closeBraceOffset, int& bodyStartLine, unsigned& bodyStartColumn);
+ 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 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);
ALWAYS_INLINE int isBinaryOperator(JSTokenType);
bool allowAutomaticSemicolon();
bool canRecurse()
{
- return m_stack.isSafeToRecurse();
+ return m_vm->isSafeToRecurse();
}
- int lastTokenEnd() const
+ const JSTextPosition& lastTokenEndPosition() const
{
- return m_lastTokenEnd;
+ return m_lastTokenEndPosition;
}
- unsigned lastTokenLine() const
+ bool hasError() const
{
- return m_lastLine;
+ return !m_errorMessage.isNull();
}
- unsigned lastTokenLineStart() const
+ struct SavePoint {
+ int startOffset;
+ unsigned oldLineStartOffset;
+ unsigned oldLastLineNumber;
+ unsigned oldLineNumber;
+ };
+
+ ALWAYS_INLINE SavePoint createSavePoint()
+ {
+ ASSERT(!hasError());
+ SavePoint result;
+ result.startOffset = m_token.m_location.startOffset;
+ result.oldLineStartOffset = m_token.m_location.lineStartOffset;
+ result.oldLastLineNumber = m_lexer->lastLineNumber();
+ result.oldLineNumber = m_lexer->lineNumber();
+ return result;
+ }
+
+ ALWAYS_INLINE void restoreSavePoint(const SavePoint& savePoint)
{
- return m_lastTokenLineStart;
+ m_errorMessage = String();
+ m_lexer->setOffset(savePoint.startOffset, savePoint.oldLineStartOffset);
+ next();
+ m_lexer->setLastLineNumber(savePoint.oldLastLineNumber);
+ m_lexer->setLineNumber(savePoint.oldLineNumber);
}
- bool hasError() const
+ struct ParserState {
+ int assignmentCount;
+ int nonLHSCount;
+ int nonTrivialExpressionCount;
+ };
+
+ ALWAYS_INLINE ParserState saveState()
{
- return !m_errorMessage.isNull();
+ ParserState result;
+ result.assignmentCount = m_assignmentCount;
+ result.nonLHSCount = m_nonLHSCount;
+ result.nonTrivialExpressionCount = m_nonTrivialExpressionCount;
+ return result;
}
+
+ ALWAYS_INLINE void restoreState(const ParserState& state)
+ {
+ m_assignmentCount = state.assignmentCount;
+ m_nonLHSCount = state.nonLHSCount;
+ m_nonTrivialExpressionCount = state.nonTrivialExpressionCount;
+
+ }
+
VM* m_vm;
const SourceCode* m_source;
ParserArena* m_arena;
OwnPtr<LexerType> m_lexer;
- StackBounds m_stack;
bool m_hasStackOverflow;
String m_errorMessage;
JSToken m_token;
bool m_allowsIn;
- unsigned m_lastLine;
- int m_lastTokenEnd;
- unsigned m_lastTokenLine;
- unsigned m_lastTokenLineStart;
+ JSTextPosition m_lastTokenEndPosition;
int m_assignmentCount;
int m_nonLHSCount;
bool m_syntaxAlreadyValidated;
int m_statementDepth;
int m_nonTrivialExpressionCount;
const Identifier* m_lastIdentifier;
+ const Identifier* m_lastFunctionName;
RefPtr<SourceProviderCache> m_functionCache;
SourceElements* m_sourceElements;
+ bool m_parsingBuiltin;
ParserArenaData<DeclarationStacks::VarStack>* m_varDeclarations;
ParserArenaData<DeclarationStacks::FunctionStack>* m_funcDeclarations;
IdentifierSet m_capturedVariables;
+ Vector<RefPtr<StringImpl>> m_closedVariables;
CodeFeatures m_features;
int m_numConstants;
template <typename LexerType>
template <class ParsedNode>
-PassRefPtr<ParsedNode> Parser<LexerType>::parse(ParserError& error)
+PassRefPtr<ParsedNode> Parser<LexerType>::parse(ParserError& error, bool needReparsingAdjustment)
{
int errLine;
String errMsg;
- if (ParsedNode::scopeIsFunction)
+ if (ParsedNode::scopeIsFunction && needReparsingAdjustment)
m_lexer->setIsReparsing();
m_sourceElements = 0;
errMsg = String();
JSTokenLocation startLocation(tokenLocation());
- unsigned startColumn = m_source->startColumn();
+ ASSERT(m_source->startColumn() > 0);
+ unsigned startColumn = m_source->startColumn() - 1;
String parseError = parseInner();
RefPtr<ParsedNode> result;
if (m_sourceElements) {
JSTokenLocation endLocation;
- endLocation.line = m_lexer->lastLineNumber();
+ endLocation.line = m_lexer->lineNumber();
endLocation.lineStartOffset = m_lexer->currentLineStartOffset();
endLocation.startOffset = m_lexer->currentOffset();
+ unsigned endColumn = endLocation.startOffset - endLocation.lineStartOffset;
result = ParsedNode::create(m_vm,
startLocation,
endLocation,
startColumn,
+ endColumn,
m_sourceElements,
m_varDeclarations ? &m_varDeclarations->data : 0,
m_funcDeclarations ? &m_funcDeclarations->data : 0,
*m_source,
m_features,
m_numConstants);
- result->setLoc(m_source->firstLine(), m_lastLine, m_lexer->currentOffset(), m_lexer->currentLineStartOffset());
+ result->setLoc(m_source->firstLine(), m_lexer->lineNumber(), m_lexer->currentOffset(), m_lexer->currentLineStartOffset());
} else {
// We can never see a syntax error when reparsing a function, since we should have
// reported the error when parsing the containing program or eval code. So if we're
}
template <class ParsedNode>
-PassRefPtr<ParsedNode> parse(VM* vm, const SourceCode& source, FunctionParameters* parameters, const Identifier& name, JSParserStrictness strictness, JSParserMode parserMode, ParserError& error)
+PassRefPtr<ParsedNode> parse(VM* vm, const SourceCode& source, FunctionParameters* parameters, const Identifier& name, JSParserStrictness strictness, JSParserMode parserMode, ParserError& error, JSTextPosition* positionBeforeLastNewline = 0, bool needReparsingAdjustment = false)
{
SamplingRegion samplingRegion("Parsing");
ASSERT(!source.provider()->source().isNull());
if (source.provider()->source().is8Bit()) {
- Parser< Lexer<LChar> > parser(vm, source, parameters, name, strictness, parserMode);
- return parser.parse<ParsedNode>(error);
+ Parser<Lexer<LChar>> parser(vm, source, parameters, name, strictness, parserMode);
+ RefPtr<ParsedNode> result = parser.parse<ParsedNode>(error, needReparsingAdjustment);
+ if (positionBeforeLastNewline)
+ *positionBeforeLastNewline = parser.positionBeforeLastNewline();
+ if (strictness == JSParseBuiltin) {
+ if (!result)
+ WTF::dataLog("Error compiling builtin: ", error.m_message, "\n");
+ RELEASE_ASSERT(result);
+ result->setClosedVariables(parser.closedVariables());
+ }
+ return result.release();
}
- Parser< Lexer<UChar> > parser(vm, source, parameters, name, strictness, parserMode);
- return parser.parse<ParsedNode>(error);
+ Parser<Lexer<UChar>> parser(vm, source, parameters, name, strictness, parserMode);
+ RefPtr<ParsedNode> result = parser.parse<ParsedNode>(error, needReparsingAdjustment);
+ if (positionBeforeLastNewline)
+ *positionBeforeLastNewline = parser.positionBeforeLastNewline();
+ return result.release();
}
} // namespace