| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 target_stack_(NULL), | 788 target_stack_(NULL), |
| 789 cached_parse_data_(NULL), | 789 cached_parse_data_(NULL), |
| 790 info_(info), | 790 info_(info), |
| 791 has_pending_error_(false), | 791 has_pending_error_(false), |
| 792 pending_error_message_(NULL), | 792 pending_error_message_(NULL), |
| 793 pending_error_arg_(NULL), | 793 pending_error_arg_(NULL), |
| 794 pending_error_char_arg_(NULL), | 794 pending_error_char_arg_(NULL), |
| 795 total_preparse_skipped_(0), | 795 total_preparse_skipped_(0), |
| 796 pre_parse_timer_(NULL) { | 796 pre_parse_timer_(NULL) { |
| 797 DCHECK(!script().is_null() || info->source_stream() != NULL); | 797 DCHECK(!script().is_null() || info->source_stream() != NULL); |
| 798 set_allow_lazy(false); // Must be explicitly enabled. |
| 799 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
| 798 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 800 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
| 799 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 801 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); |
| 800 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 802 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); |
| 801 set_allow_lazy(false); // Must be explicitly enabled. | |
| 802 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | |
| 803 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 803 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
| 804 set_allow_classes(FLAG_harmony_classes); | 804 set_allow_harmony_classes(FLAG_harmony_classes); |
| 805 set_allow_harmony_object_literals(FLAG_harmony_object_literals); | 805 set_allow_harmony_object_literals(FLAG_harmony_object_literals); |
| 806 set_allow_harmony_templates(FLAG_harmony_templates); | 806 set_allow_harmony_templates(FLAG_harmony_templates); |
| 807 set_allow_harmony_sloppy(FLAG_harmony_sloppy); |
| 807 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 808 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 808 ++feature) { | 809 ++feature) { |
| 809 use_counts_[feature] = 0; | 810 use_counts_[feature] = 0; |
| 810 } | 811 } |
| 811 if (info->ast_value_factory() == NULL) { | 812 if (info->ast_value_factory() == NULL) { |
| 812 // info takes ownership of AstValueFactory. | 813 // info takes ownership of AstValueFactory. |
| 813 info->SetAstValueFactory( | 814 info->SetAstValueFactory( |
| 814 new AstValueFactory(zone(), parse_info->hash_seed)); | 815 new AstValueFactory(zone(), parse_info->hash_seed)); |
| 815 } | 816 } |
| 816 } | 817 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 *scope = NewScope(*scope, EVAL_SCOPE); | 910 *scope = NewScope(*scope, EVAL_SCOPE); |
| 910 } | 911 } |
| 911 } else if (info->is_global()) { | 912 } else if (info->is_global()) { |
| 912 *scope = NewScope(*scope, SCRIPT_SCOPE); | 913 *scope = NewScope(*scope, SCRIPT_SCOPE); |
| 913 } | 914 } |
| 914 (*scope)->set_start_position(0); | 915 (*scope)->set_start_position(0); |
| 915 // End position will be set by the caller. | 916 // End position will be set by the caller. |
| 916 | 917 |
| 917 // Compute the parsing mode. | 918 // Compute the parsing mode. |
| 918 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; | 919 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; |
| 919 if (allow_natives_syntax() || extension_ != NULL || | 920 if (allow_natives() || extension_ != NULL || |
| 920 (*scope)->is_eval_scope()) { | 921 (*scope)->is_eval_scope()) { |
| 921 mode = PARSE_EAGERLY; | 922 mode = PARSE_EAGERLY; |
| 922 } | 923 } |
| 923 ParsingModeScope parsing_mode(this, mode); | 924 ParsingModeScope parsing_mode(this, mode); |
| 924 | 925 |
| 925 // Enters 'scope'. | 926 // Enters 'scope'. |
| 926 AstNodeFactory function_factory(ast_value_factory()); | 927 AstNodeFactory function_factory(ast_value_factory()); |
| 927 FunctionState function_state(&function_state_, &scope_, *scope, | 928 FunctionState function_state(&function_state_, &scope_, *scope, |
| 928 &function_factory); | 929 &function_factory); |
| 929 | 930 |
| (...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 // | 1986 // |
| 1986 // class C { ... } | 1987 // class C { ... } |
| 1987 // | 1988 // |
| 1988 // has the same semantics as: | 1989 // has the same semantics as: |
| 1989 // | 1990 // |
| 1990 // let C = class C { ... }; | 1991 // let C = class C { ... }; |
| 1991 // | 1992 // |
| 1992 // so rewrite it as such. | 1993 // so rewrite it as such. |
| 1993 | 1994 |
| 1994 Expect(Token::CLASS, CHECK_OK); | 1995 Expect(Token::CLASS, CHECK_OK); |
| 1996 if (!allow_harmony_sloppy() && strict_mode() == SLOPPY) { |
| 1997 ReportMessage("sloppy_lexical"); |
| 1998 *ok = false; |
| 1999 return NULL; |
| 2000 } |
| 2001 |
| 1995 int pos = position(); | 2002 int pos = position(); |
| 1996 bool is_strict_reserved = false; | 2003 bool is_strict_reserved = false; |
| 1997 const AstRawString* name = | 2004 const AstRawString* name = |
| 1998 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 2005 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 1999 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), | 2006 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), |
| 2000 is_strict_reserved, pos, CHECK_OK); | 2007 is_strict_reserved, pos, CHECK_OK); |
| 2001 | 2008 |
| 2002 VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue()); | 2009 VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue()); |
| 2003 Declaration* declaration = | 2010 Declaration* declaration = |
| 2004 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); | 2011 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2482 // Also detect attempts at 'let' declarations in sloppy mode. | 2489 // Also detect attempts at 'let' declarations in sloppy mode. |
| 2483 if (!FLAG_harmony_modules || peek() != Token::IDENTIFIER || | 2490 if (!FLAG_harmony_modules || peek() != Token::IDENTIFIER || |
| 2484 scanner()->HasAnyLineTerminatorBeforeNext() || | 2491 scanner()->HasAnyLineTerminatorBeforeNext() || |
| 2485 expr->AsVariableProxy() == NULL || | 2492 expr->AsVariableProxy() == NULL || |
| 2486 expr->AsVariableProxy()->raw_name() != | 2493 expr->AsVariableProxy()->raw_name() != |
| 2487 ast_value_factory()->module_string() || | 2494 ast_value_factory()->module_string() || |
| 2488 scanner()->literal_contains_escapes()) { | 2495 scanner()->literal_contains_escapes()) { |
| 2489 if (peek() == Token::IDENTIFIER && expr->AsVariableProxy() != NULL && | 2496 if (peek() == Token::IDENTIFIER && expr->AsVariableProxy() != NULL && |
| 2490 expr->AsVariableProxy()->raw_name() == | 2497 expr->AsVariableProxy()->raw_name() == |
| 2491 ast_value_factory()->let_string()) { | 2498 ast_value_factory()->let_string()) { |
| 2492 ReportMessage("lexical_strict_mode", NULL); | 2499 ReportMessage("sloppy_lexical", NULL); |
| 2493 *ok = false; | 2500 *ok = false; |
| 2494 return NULL; | 2501 return NULL; |
| 2495 } | 2502 } |
| 2496 ExpectSemicolon(CHECK_OK); | 2503 ExpectSemicolon(CHECK_OK); |
| 2497 } | 2504 } |
| 2498 return factory()->NewExpressionStatement(expr, pos); | 2505 return factory()->NewExpressionStatement(expr, pos); |
| 2499 } | 2506 } |
| 2500 | 2507 |
| 2501 | 2508 |
| 2502 IfStatement* Parser::ParseIfStatement(ZoneList<const AstRawString*>* labels, | 2509 IfStatement* Parser::ParseIfStatement(ZoneList<const AstRawString*>* labels, |
| (...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3366 } | 3373 } |
| 3367 | 3374 |
| 3368 // Standard 'for' loop | 3375 // Standard 'for' loop |
| 3369 ForStatement* loop = factory()->NewForStatement(labels, stmt_pos); | 3376 ForStatement* loop = factory()->NewForStatement(labels, stmt_pos); |
| 3370 Target target(&this->target_stack_, loop); | 3377 Target target(&this->target_stack_, loop); |
| 3371 | 3378 |
| 3372 // Parsed initializer at this point. | 3379 // Parsed initializer at this point. |
| 3373 // Detect attempts at 'let' declarations in sloppy mode. | 3380 // Detect attempts at 'let' declarations in sloppy mode. |
| 3374 if (peek() == Token::IDENTIFIER && strict_mode() == SLOPPY && | 3381 if (peek() == Token::IDENTIFIER && strict_mode() == SLOPPY && |
| 3375 is_let_identifier_expression) { | 3382 is_let_identifier_expression) { |
| 3376 ReportMessage("lexical_strict_mode", NULL); | 3383 ReportMessage("sloppy_lexical", NULL); |
| 3377 *ok = false; | 3384 *ok = false; |
| 3378 return NULL; | 3385 return NULL; |
| 3379 } | 3386 } |
| 3380 Expect(Token::SEMICOLON, CHECK_OK); | 3387 Expect(Token::SEMICOLON, CHECK_OK); |
| 3381 | 3388 |
| 3382 // If there are let bindings, then condition and the next statement of the | 3389 // If there are let bindings, then condition and the next statement of the |
| 3383 // for loop must be parsed in a new scope. | 3390 // for loop must be parsed in a new scope. |
| 3384 Scope* inner_scope = NULL; | 3391 Scope* inner_scope = NULL; |
| 3385 if (let_bindings.length() > 0) { | 3392 if (let_bindings.length() > 0) { |
| 3386 inner_scope = NewScope(for_scope, BLOCK_SCOPE); | 3393 inner_scope = NewScope(for_scope, BLOCK_SCOPE); |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3957 SingletonLogger* logger) { | 3964 SingletonLogger* logger) { |
| 3958 // This function may be called on a background thread too; record only the | 3965 // This function may be called on a background thread too; record only the |
| 3959 // main thread preparse times. | 3966 // main thread preparse times. |
| 3960 if (pre_parse_timer_ != NULL) { | 3967 if (pre_parse_timer_ != NULL) { |
| 3961 pre_parse_timer_->Start(); | 3968 pre_parse_timer_->Start(); |
| 3962 } | 3969 } |
| 3963 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 3970 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
| 3964 | 3971 |
| 3965 if (reusable_preparser_ == NULL) { | 3972 if (reusable_preparser_ == NULL) { |
| 3966 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit_); | 3973 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit_); |
| 3974 reusable_preparser_->set_allow_lazy(true); |
| 3975 reusable_preparser_->set_allow_natives(allow_natives()); |
| 3967 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3976 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
| 3968 reusable_preparser_->set_allow_modules(allow_modules()); | 3977 reusable_preparser_->set_allow_harmony_modules(allow_harmony_modules()); |
| 3969 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3978 reusable_preparser_->set_allow_harmony_arrow_functions( |
| 3970 reusable_preparser_->set_allow_lazy(true); | 3979 allow_harmony_arrow_functions()); |
| 3971 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); | |
| 3972 reusable_preparser_->set_allow_harmony_numeric_literals( | 3980 reusable_preparser_->set_allow_harmony_numeric_literals( |
| 3973 allow_harmony_numeric_literals()); | 3981 allow_harmony_numeric_literals()); |
| 3974 reusable_preparser_->set_allow_classes(allow_classes()); | 3982 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); |
| 3975 reusable_preparser_->set_allow_harmony_object_literals( | 3983 reusable_preparser_->set_allow_harmony_object_literals( |
| 3976 allow_harmony_object_literals()); | 3984 allow_harmony_object_literals()); |
| 3977 reusable_preparser_->set_allow_harmony_templates(allow_harmony_templates()); | 3985 reusable_preparser_->set_allow_harmony_templates(allow_harmony_templates()); |
| 3986 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy()); |
| 3978 } | 3987 } |
| 3979 PreParser::PreParseResult result = | 3988 PreParser::PreParseResult result = |
| 3980 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3989 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
| 3981 is_generator(), | 3990 is_generator(), |
| 3982 logger); | 3991 logger); |
| 3983 if (pre_parse_timer_ != NULL) { | 3992 if (pre_parse_timer_ != NULL) { |
| 3984 pre_parse_timer_->Stop(); | 3993 pre_parse_timer_->Stop(); |
| 3985 } | 3994 } |
| 3986 return result; | 3995 return result; |
| 3987 } | 3996 } |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5102 result->capture_count = capture_count; | 5111 result->capture_count = capture_count; |
| 5103 } | 5112 } |
| 5104 return !parser.failed(); | 5113 return !parser.failed(); |
| 5105 } | 5114 } |
| 5106 | 5115 |
| 5107 | 5116 |
| 5108 bool Parser::Parse() { | 5117 bool Parser::Parse() { |
| 5109 DCHECK(info()->function() == NULL); | 5118 DCHECK(info()->function() == NULL); |
| 5110 FunctionLiteral* result = NULL; | 5119 FunctionLiteral* result = NULL; |
| 5111 pre_parse_timer_ = isolate()->counters()->pre_parse(); | 5120 pre_parse_timer_ = isolate()->counters()->pre_parse(); |
| 5112 if (FLAG_trace_parse || allow_natives_syntax() || extension_ != NULL) { | 5121 if (FLAG_trace_parse || allow_natives() || extension_ != NULL) { |
| 5113 // If intrinsics are allowed, the Parser cannot operate independent of the | 5122 // If intrinsics are allowed, the Parser cannot operate independent of the |
| 5114 // V8 heap because of Runtime. Tell the string table to internalize strings | 5123 // V8 heap because of Runtime. Tell the string table to internalize strings |
| 5115 // and values right after they're created. | 5124 // and values right after they're created. |
| 5116 ast_value_factory()->Internalize(isolate()); | 5125 ast_value_factory()->Internalize(isolate()); |
| 5117 } | 5126 } |
| 5118 | 5127 |
| 5119 if (info()->is_lazy()) { | 5128 if (info()->is_lazy()) { |
| 5120 DCHECK(!info()->is_eval()); | 5129 DCHECK(!info()->is_eval()); |
| 5121 if (info()->shared_info()->is_function()) { | 5130 if (info()->shared_info()->is_function()) { |
| 5122 result = ParseLazy(); | 5131 result = ParseLazy(); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5306 | 5315 |
| 5307 const AstRawString* raw_str = ast_value_factory()->GetOneByteString( | 5316 const AstRawString* raw_str = ast_value_factory()->GetOneByteString( |
| 5308 OneByteVector(raw_chars.get(), to_index)); | 5317 OneByteVector(raw_chars.get(), to_index)); |
| 5309 Literal* raw_lit = factory()->NewStringLiteral(raw_str, span_start - 1); | 5318 Literal* raw_lit = factory()->NewStringLiteral(raw_str, span_start - 1); |
| 5310 raw_strings->Add(raw_lit, zone()); | 5319 raw_strings->Add(raw_lit, zone()); |
| 5311 } | 5320 } |
| 5312 | 5321 |
| 5313 return raw_strings; | 5322 return raw_strings; |
| 5314 } | 5323 } |
| 5315 } } // namespace v8::internal | 5324 } } // namespace v8::internal |
| OLD | NEW |