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/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/char-predicates-inl.h" | 10 #include "src/char-predicates-inl.h" |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 pending_error_char_arg_(NULL) { | 776 pending_error_char_arg_(NULL) { |
777 ASSERT(!script_.is_null()); | 777 ASSERT(!script_.is_null()); |
778 isolate_->set_ast_node_id(0); | 778 isolate_->set_ast_node_id(0); |
779 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 779 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
780 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 780 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
781 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 781 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
782 set_allow_lazy(false); // Must be explicitly enabled. | 782 set_allow_lazy(false); // Must be explicitly enabled. |
783 set_allow_generators(FLAG_harmony_generators); | 783 set_allow_generators(FLAG_harmony_generators); |
784 set_allow_for_of(FLAG_harmony_iteration); | 784 set_allow_for_of(FLAG_harmony_iteration); |
785 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 785 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
| 786 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 787 ++feature) { |
| 788 use_counts_[feature] = 0; |
| 789 } |
786 } | 790 } |
787 | 791 |
788 | 792 |
789 FunctionLiteral* Parser::ParseProgram() { | 793 FunctionLiteral* Parser::ParseProgram() { |
790 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 794 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
791 // see comment for HistogramTimerScope class. | 795 // see comment for HistogramTimerScope class. |
792 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); | 796 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); |
793 Handle<String> source(String::cast(script_->source())); | 797 Handle<String> source(String::cast(script_->source())); |
794 isolate()->counters()->total_parse_size()->Increment(source->length()); | 798 isolate()->counters()->total_parse_size()->Increment(source->length()); |
795 ElapsedTimer timer; | 799 ElapsedTimer timer; |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 } | 1084 } |
1081 | 1085 |
1082 if (directive_prologue) { | 1086 if (directive_prologue) { |
1083 // A shot at a directive. | 1087 // A shot at a directive. |
1084 ExpressionStatement* e_stat; | 1088 ExpressionStatement* e_stat; |
1085 Literal* literal; | 1089 Literal* literal; |
1086 // Still processing directive prologue? | 1090 // Still processing directive prologue? |
1087 if ((e_stat = stat->AsExpressionStatement()) != NULL && | 1091 if ((e_stat = stat->AsExpressionStatement()) != NULL && |
1088 (literal = e_stat->expression()->AsLiteral()) != NULL && | 1092 (literal = e_stat->expression()->AsLiteral()) != NULL && |
1089 literal->raw_value()->IsString()) { | 1093 literal->raw_value()->IsString()) { |
1090 // Check "use strict" directive (ES5 14.1). | 1094 // Check "use strict" directive (ES5 14.1) and "use asm" directive. Only |
| 1095 // one can be present. |
1091 if (strict_mode() == SLOPPY && | 1096 if (strict_mode() == SLOPPY && |
1092 literal->raw_value()->AsString() == | 1097 literal->raw_value()->AsString() == |
1093 ast_value_factory_->use_strict_string() && | 1098 ast_value_factory_->use_strict_string() && |
1094 token_loc.end_pos - token_loc.beg_pos == 12) { | 1099 token_loc.end_pos - token_loc.beg_pos == |
| 1100 ast_value_factory_->use_strict_string()->length() + 2) { |
1095 // TODO(mstarzinger): Global strict eval calls, need their own scope | 1101 // TODO(mstarzinger): Global strict eval calls, need their own scope |
1096 // as specified in ES5 10.4.2(3). The correct fix would be to always | 1102 // as specified in ES5 10.4.2(3). The correct fix would be to always |
1097 // add this scope in DoParseProgram(), but that requires adaptations | 1103 // add this scope in DoParseProgram(), but that requires adaptations |
1098 // all over the code base, so we go with a quick-fix for now. | 1104 // all over the code base, so we go with a quick-fix for now. |
1099 // In the same manner, we have to patch the parsing mode. | 1105 // In the same manner, we have to patch the parsing mode. |
1100 if (is_eval && !scope_->is_eval_scope()) { | 1106 if (is_eval && !scope_->is_eval_scope()) { |
1101 ASSERT(scope_->is_global_scope()); | 1107 ASSERT(scope_->is_global_scope()); |
1102 Scope* scope = NewScope(scope_, EVAL_SCOPE); | 1108 Scope* scope = NewScope(scope_, EVAL_SCOPE); |
1103 scope->set_start_position(scope_->start_position()); | 1109 scope->set_start_position(scope_->start_position()); |
1104 scope->set_end_position(scope_->end_position()); | 1110 scope->set_end_position(scope_->end_position()); |
1105 scope_ = scope; | 1111 scope_ = scope; |
1106 mode_ = PARSE_EAGERLY; | 1112 mode_ = PARSE_EAGERLY; |
1107 } | 1113 } |
1108 scope_->SetStrictMode(STRICT); | 1114 scope_->SetStrictMode(STRICT); |
1109 // "use strict" is the only directive for now. | 1115 // "use strict" is the only directive for now. |
1110 directive_prologue = false; | 1116 directive_prologue = false; |
| 1117 } else if (literal->raw_value()->AsString() == |
| 1118 ast_value_factory_->use_asm_string() && |
| 1119 token_loc.end_pos - token_loc.beg_pos == |
| 1120 ast_value_factory_->use_asm_string()->length() + 2) { |
| 1121 // Store the usage count; The actual use counter on the isolate is |
| 1122 // incremented after parsing is done. |
| 1123 ++use_counts_[v8::Isolate::kUseAsm]; |
1111 } | 1124 } |
1112 } else { | 1125 } else { |
1113 // End of the directive prologue. | 1126 // End of the directive prologue. |
1114 directive_prologue = false; | 1127 directive_prologue = false; |
1115 } | 1128 } |
1116 } | 1129 } |
1117 | 1130 |
1118 processor->Add(stat, zone()); | 1131 processor->Add(stat, zone()); |
1119 } | 1132 } |
1120 | 1133 |
(...skipping 2771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3892 | 3905 |
3893 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | 3906 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
3894 Handle<Object> result = pending_error_is_reference_error_ | 3907 Handle<Object> result = pending_error_is_reference_error_ |
3895 ? factory->NewReferenceError(pending_error_message_, array) | 3908 ? factory->NewReferenceError(pending_error_message_, array) |
3896 : factory->NewSyntaxError(pending_error_message_, array); | 3909 : factory->NewSyntaxError(pending_error_message_, array); |
3897 isolate()->Throw(*result, &location); | 3910 isolate()->Throw(*result, &location); |
3898 } | 3911 } |
3899 } | 3912 } |
3900 | 3913 |
3901 | 3914 |
| 3915 void Parser::InternalizeUseCounts() { |
| 3916 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 3917 ++feature) { |
| 3918 for (int i = 0; i < use_counts_[feature]; ++i) { |
| 3919 isolate()->CountUsage(v8::Isolate::UseCounterFeature(feature)); |
| 3920 } |
| 3921 } |
| 3922 } |
| 3923 |
| 3924 |
3902 // ---------------------------------------------------------------------------- | 3925 // ---------------------------------------------------------------------------- |
3903 // Regular expressions | 3926 // Regular expressions |
3904 | 3927 |
3905 | 3928 |
3906 RegExpParser::RegExpParser(FlatStringReader* in, | 3929 RegExpParser::RegExpParser(FlatStringReader* in, |
3907 Handle<String>* error, | 3930 Handle<String>* error, |
3908 bool multiline, | 3931 bool multiline, |
3909 Zone* zone) | 3932 Zone* zone) |
3910 : isolate_(zone->isolate()), | 3933 : isolate_(zone->isolate()), |
3911 zone_(zone), | 3934 zone_(zone), |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4833 result = ParseProgram(); | 4856 result = ParseProgram(); |
4834 } | 4857 } |
4835 } | 4858 } |
4836 info()->SetFunction(result); | 4859 info()->SetFunction(result); |
4837 ASSERT(ast_value_factory_->IsInternalized()); | 4860 ASSERT(ast_value_factory_->IsInternalized()); |
4838 // info takes ownership of ast_value_factory_. | 4861 // info takes ownership of ast_value_factory_. |
4839 if (info()->ast_value_factory() == NULL) { | 4862 if (info()->ast_value_factory() == NULL) { |
4840 info()->SetAstValueFactory(ast_value_factory_); | 4863 info()->SetAstValueFactory(ast_value_factory_); |
4841 } | 4864 } |
4842 ast_value_factory_ = NULL; | 4865 ast_value_factory_ = NULL; |
| 4866 |
| 4867 InternalizeUseCounts(); |
| 4868 |
4843 return (result != NULL); | 4869 return (result != NULL); |
4844 } | 4870 } |
4845 | 4871 |
4846 } } // namespace v8::internal | 4872 } } // namespace v8::internal |
OLD | NEW |