diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-12-07 13:56:11 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-12-07 13:56:11 -0800 |
commit | c30f1137121315b0d3641af6dc61e3b047f940e1 (patch) | |
tree | f118eaf670505e6a63f28bc8df845520f67adc55 /deps/v8/src/parser.cc | |
parent | 5b8c62f7d12c1c5a553e765ba05bbd8a7e17ee47 (diff) | |
download | node-new-c30f1137121315b0d3641af6dc61e3b047f940e1.tar.gz |
Upgrade V8 to 3.0.0
Diffstat (limited to 'deps/v8/src/parser.cc')
-rw-r--r-- | deps/v8/src/parser.cc | 100 |
1 files changed, 67 insertions, 33 deletions
diff --git a/deps/v8/src/parser.cc b/deps/v8/src/parser.cc index 186d1020d7..056332b5b4 100644 --- a/deps/v8/src/parser.cc +++ b/deps/v8/src/parser.cc @@ -593,7 +593,9 @@ Parser::Parser(Handle<Script> script, allow_natives_syntax_(allow_natives_syntax), extension_(extension), pre_data_(pre_data), - fni_(NULL) { + fni_(NULL), + stack_overflow_(false) { + AstNode::ResetIds(); } @@ -643,7 +645,7 @@ FunctionLiteral* Parser::ParseProgram(Handle<String> source, source->length(), false, temp_scope.ContainsLoops()); - } else if (scanner().stack_overflow()) { + } else if (stack_overflow_) { Top::StackOverflow(); } } @@ -693,7 +695,7 @@ FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info) { // Make sure the results agree. ASSERT(ok == (result != NULL)); // The only errors should be stack overflows. - ASSERT(ok || scanner_.stack_overflow()); + ASSERT(ok || stack_overflow_); } // Make sure the target stack is empty. @@ -704,6 +706,9 @@ FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info) { if (result == NULL) { Top::StackOverflow(); zone_scope.DeleteOnExit(); + } else { + Handle<String> inferred_name(info->inferred_name()); + result->set_inferred_name(inferred_name); } return result; } @@ -1793,7 +1798,7 @@ CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { *default_seen_ptr = true; } Expect(Token::COLON, CHECK_OK); - + int pos = scanner().location().beg_pos; ZoneList<Statement*>* statements = new ZoneList<Statement*>(5); while (peek() != Token::CASE && peek() != Token::DEFAULT && @@ -1802,7 +1807,7 @@ CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { statements->Add(stat); } - return new CaseClause(label, statements); + return new CaseClause(label, statements, pos); } @@ -1874,7 +1879,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { } Block* catch_block = NULL; - VariableProxy* catch_var = NULL; + Variable* catch_var = NULL; Block* finally_block = NULL; Token::Value tok = peek(); @@ -1904,7 +1909,8 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { // executing the finally block. catch_var = top_scope_->NewTemporary(Factory::catch_var_symbol()); Literal* name_literal = new Literal(name); - Expression* obj = new CatchExtensionObject(name_literal, catch_var); + VariableProxy* catch_var_use = new VariableProxy(catch_var); + Expression* obj = new CatchExtensionObject(name_literal, catch_var_use); { Target target(&this->target_stack_, &catch_collector); catch_block = WithHelper(obj, NULL, true, CHECK_OK); } @@ -1928,8 +1934,9 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { // 'try { try { } catch { } } finally { }' if (catch_block != NULL && finally_block != NULL) { + VariableProxy* catch_var_defn = new VariableProxy(catch_var); TryCatchStatement* statement = - new TryCatchStatement(try_block, catch_var, catch_block); + new TryCatchStatement(try_block, catch_var_defn, catch_block); statement->set_escaping_targets(collector.targets()); try_block = new Block(NULL, 1, false); try_block->AddStatement(statement); @@ -1939,7 +1946,8 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { TryStatement* result = NULL; if (catch_block != NULL) { ASSERT(finally_block == NULL); - result = new TryCatchStatement(try_block, catch_var, catch_block); + VariableProxy* catch_var_defn = new VariableProxy(catch_var); + result = new TryCatchStatement(try_block, catch_var_defn, catch_block); result->set_escaping_targets(collector.targets()); } else { ASSERT(finally_block != NULL); @@ -2590,25 +2598,24 @@ void Parser::ReportUnexpectedToken(Token::Value token) { // We don't report stack overflows here, to avoid increasing the // stack depth even further. Instead we report it after parsing is // over, in ParseProgram/ParseJson. - if (token == Token::ILLEGAL && scanner().stack_overflow()) - return; + if (token == Token::ILLEGAL && stack_overflow_) return; // Four of the tokens are treated specially switch (token) { - case Token::EOS: - return ReportMessage("unexpected_eos", Vector<const char*>::empty()); - case Token::NUMBER: - return ReportMessage("unexpected_token_number", - Vector<const char*>::empty()); - case Token::STRING: - return ReportMessage("unexpected_token_string", - Vector<const char*>::empty()); - case Token::IDENTIFIER: - return ReportMessage("unexpected_token_identifier", - Vector<const char*>::empty()); - default: - const char* name = Token::String(token); - ASSERT(name != NULL); - ReportMessage("unexpected_token", Vector<const char*>(&name, 1)); + case Token::EOS: + return ReportMessage("unexpected_eos", Vector<const char*>::empty()); + case Token::NUMBER: + return ReportMessage("unexpected_token_number", + Vector<const char*>::empty()); + case Token::STRING: + return ReportMessage("unexpected_token_string", + Vector<const char*>::empty()); + case Token::IDENTIFIER: + return ReportMessage("unexpected_token_identifier", + Vector<const char*>::empty()); + default: + const char* name = Token::String(token); + ASSERT(name != NULL); + ReportMessage("unexpected_token", Vector<const char*>(&name, 1)); } } @@ -2814,6 +2821,7 @@ bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { + if (expression->AsLiteral() != NULL) return true; MaterializedLiteral* lit = expression->AsMaterializedLiteral(); return lit != NULL && lit->is_simple(); } @@ -3498,9 +3506,10 @@ Expression* Parser::NewThrowError(Handle<String> constructor, Handle<Object> JsonParser::ParseJson(Handle<String> source) { source->TryFlatten(); scanner_.Initialize(source); + stack_overflow_ = false; Handle<Object> result = ParseJsonValue(); if (result.is_null() || scanner_.Next() != Token::EOS) { - if (scanner_.stack_overflow()) { + if (stack_overflow_) { // Scanner failed. Top::StackOverflow(); } else { @@ -3598,6 +3607,10 @@ Handle<Object> JsonParser::ParseJsonObject() { if (scanner_.peek() == Token::RBRACE) { scanner_.Next(); } else { + if (StackLimitCheck().HasOverflowed()) { + stack_overflow_ = true; + return Handle<Object>::null(); + } do { if (scanner_.Next() != Token::STRING) { return ReportUnexpectedToken(); @@ -3632,6 +3645,10 @@ Handle<Object> JsonParser::ParseJsonArray() { if (token == Token::RBRACK) { scanner_.Next(); } else { + if (StackLimitCheck().HasOverflowed()) { + stack_overflow_ = true; + return Handle<Object>::null(); + } do { Handle<Object> element = ParseJsonValue(); if (element.is_null()) return Handle<Object>::null(); @@ -4395,6 +4412,7 @@ CharacterRange RegExpParser::ParseClassAtom(uc16* char_class) { RegExpTree* RegExpParser::ParseCharacterClass() { static const char* kUnterminated = "Unterminated character class"; static const char* kRangeOutOfOrder = "Range out of order in character class"; + static const char* kInvalidRange = "Invalid character range"; ASSERT_EQ(current(), '['); Advance(); @@ -4403,12 +4421,28 @@ RegExpTree* RegExpParser::ParseCharacterClass() { is_negated = true; Advance(); } + // A CharacterClass is a sequence of single characters, character class + // escapes or ranges. Ranges are on the form "x-y" where x and y are + // single characters (and not character class escapes like \s). + // A "-" may occur at the start or end of the character class (just after + // "[" or "[^", or just before "]") without being considered part of a + // range. A "-" may also appear as the beginning or end of a range. + // I.e., [--+] is valid, so is [!--]. + ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); while (has_more() && current() != ']') { uc16 char_class = 0; CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); if (char_class) { CharacterRange::AddClassEscape(char_class, ranges); + if (current() == '-') { + Advance(); + ranges->Add(CharacterRange::Singleton('-')); + if (current() != ']') { + ReportError(CStrVector(kInvalidRange) CHECK_FAILED); + } + break; + } continue; } if (current() == '-') { @@ -4424,10 +4458,7 @@ RegExpTree* RegExpParser::ParseCharacterClass() { } CharacterRange next = ParseClassAtom(&char_class CHECK_FAILED); if (char_class) { - ranges->Add(first); - ranges->Add(CharacterRange::Singleton('-')); - CharacterRange::AddClassEscape(char_class, ranges); - continue; + ReportError(CStrVector(kInvalidRange) CHECK_FAILED); } if (first.from() > next.to()) { return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); @@ -4531,8 +4562,11 @@ static ScriptDataImpl* DoPreParse(Handle<String> source, int literal_flags) { V8JavaScriptScanner scanner; scanner.Initialize(source, stream, literal_flags); - preparser::PreParser preparser; - if (!preparser.PreParseProgram(&scanner, recorder, allow_lazy)) { + intptr_t stack_limit = StackGuard::real_climit(); + if (!preparser::PreParser::PreParseProgram(&scanner, + recorder, + allow_lazy, + stack_limit)) { Top::StackOverflow(); return NULL; } |