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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 ParseInfo::ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared) | 65 ParseInfo::ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared) |
66 : ParseInfo(zone) { | 66 : ParseInfo(zone) { |
67 isolate_ = shared->GetIsolate(); | 67 isolate_ = shared->GetIsolate(); |
68 | 68 |
69 set_lazy(); | 69 set_lazy(); |
70 set_hash_seed(isolate_->heap()->HashSeed()); | 70 set_hash_seed(isolate_->heap()->HashSeed()); |
71 set_stack_limit(isolate_->stack_guard()->real_climit()); | 71 set_stack_limit(isolate_->stack_guard()->real_climit()); |
72 set_unicode_cache(isolate_->unicode_cache()); | 72 set_unicode_cache(isolate_->unicode_cache()); |
73 set_language_mode(shared->language_mode()); | 73 set_language_mode(shared->language_mode()); |
| 74 set_module(shared->within_module()); |
74 set_shared_info(shared); | 75 set_shared_info(shared); |
75 | 76 |
76 Handle<Script> script(Script::cast(shared->script())); | 77 Handle<Script> script(Script::cast(shared->script())); |
77 set_script(script); | 78 set_script(script); |
78 if (!script.is_null() && script->type() == Script::TYPE_NATIVE) { | 79 if (!script.is_null() && script->type() == Script::TYPE_NATIVE) { |
79 set_native(); | 80 set_native(); |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 | 84 |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 | 847 |
847 source = String::Flatten(source); | 848 source = String::Flatten(source); |
848 FunctionLiteral* result; | 849 FunctionLiteral* result; |
849 | 850 |
850 if (source->IsExternalTwoByteString()) { | 851 if (source->IsExternalTwoByteString()) { |
851 // Notice that the stream is destroyed at the end of the branch block. | 852 // Notice that the stream is destroyed at the end of the branch block. |
852 // The last line of the blocks can't be moved outside, even though they're | 853 // The last line of the blocks can't be moved outside, even though they're |
853 // identical calls. | 854 // identical calls. |
854 ExternalTwoByteStringUtf16CharacterStream stream( | 855 ExternalTwoByteStringUtf16CharacterStream stream( |
855 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | 856 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); |
856 scanner_.Initialize(&stream); | 857 scanner_.Initialize(&stream, !info->is_module()); |
857 result = DoParseProgram(info); | 858 result = DoParseProgram(info); |
858 } else { | 859 } else { |
859 GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 860 GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
860 scanner_.Initialize(&stream); | 861 scanner_.Initialize(&stream, !info->is_module()); |
861 result = DoParseProgram(info); | 862 result = DoParseProgram(info); |
862 } | 863 } |
863 if (result != NULL) { | 864 if (result != NULL) { |
864 DCHECK_EQ(scanner_.peek_location().beg_pos, source->length()); | 865 DCHECK_EQ(scanner_.peek_location().beg_pos, source->length()); |
865 } | 866 } |
866 HandleSourceURLComments(isolate, info->script()); | 867 HandleSourceURLComments(isolate, info->script()); |
867 | 868 |
868 if (FLAG_trace_parse && result != NULL) { | 869 if (FLAG_trace_parse && result != NULL) { |
869 double ms = timer.Elapsed().InMillisecondsF(); | 870 double ms = timer.Elapsed().InMillisecondsF(); |
870 if (info->is_eval()) { | 871 if (info->is_eval()) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 } else if (IsConciseMethod(shared_info->kind()) || | 1038 } else if (IsConciseMethod(shared_info->kind()) || |
1038 IsAccessorFunction(shared_info->kind())) { | 1039 IsAccessorFunction(shared_info->kind())) { |
1039 return FunctionLiteral::kAccessorOrMethod; | 1040 return FunctionLiteral::kAccessorOrMethod; |
1040 } | 1041 } |
1041 return FunctionLiteral::kAnonymousExpression; | 1042 return FunctionLiteral::kAnonymousExpression; |
1042 } | 1043 } |
1043 | 1044 |
1044 FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, | 1045 FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, |
1045 Utf16CharacterStream* source) { | 1046 Utf16CharacterStream* source) { |
1046 Handle<SharedFunctionInfo> shared_info = info->shared_info(); | 1047 Handle<SharedFunctionInfo> shared_info = info->shared_info(); |
1047 scanner_.Initialize(source); | 1048 scanner_.Initialize(source, !info->is_module()); |
1048 DCHECK(scope_ == NULL); | 1049 DCHECK(scope_ == NULL); |
1049 DCHECK(target_stack_ == NULL); | 1050 DCHECK(target_stack_ == NULL); |
1050 | 1051 |
1051 Handle<String> name(String::cast(shared_info->name())); | 1052 Handle<String> name(String::cast(shared_info->name())); |
1052 DCHECK(ast_value_factory()); | 1053 DCHECK(ast_value_factory()); |
1053 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); | 1054 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); |
1054 const AstRawString* raw_name = ast_value_factory()->GetString(name); | 1055 const AstRawString* raw_name = ast_value_factory()->GetString(name); |
1055 fni_->PushEnclosingName(raw_name); | 1056 fni_->PushEnclosingName(raw_name); |
1056 | 1057 |
1057 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1058 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
(...skipping 4190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5248 DCHECK(info->literal() == NULL); | 5249 DCHECK(info->literal() == NULL); |
5249 FunctionLiteral* result = NULL; | 5250 FunctionLiteral* result = NULL; |
5250 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); | 5251 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); |
5251 | 5252 |
5252 CompleteParserRecorder recorder; | 5253 CompleteParserRecorder recorder; |
5253 if (produce_cached_parse_data()) log_ = &recorder; | 5254 if (produce_cached_parse_data()) log_ = &recorder; |
5254 | 5255 |
5255 DCHECK(info->source_stream() != NULL); | 5256 DCHECK(info->source_stream() != NULL); |
5256 ExternalStreamingStream stream(info->source_stream(), | 5257 ExternalStreamingStream stream(info->source_stream(), |
5257 info->source_stream_encoding()); | 5258 info->source_stream_encoding()); |
5258 scanner_.Initialize(&stream); | 5259 scanner_.Initialize(&stream, !info->is_module()); |
5259 DCHECK(info->context().is_null() || info->context()->IsNativeContext()); | 5260 DCHECK(info->context().is_null() || info->context()->IsNativeContext()); |
5260 | 5261 |
5261 // When streaming, we don't know the length of the source until we have parsed | 5262 // When streaming, we don't know the length of the source until we have parsed |
5262 // it. The raw data can be UTF-8, so we wouldn't know the source length until | 5263 // it. The raw data can be UTF-8, so we wouldn't know the source length until |
5263 // we have decoded it anyway even if we knew the raw data length (which we | 5264 // we have decoded it anyway even if we knew the raw data length (which we |
5264 // don't). We work around this by storing all the scopes which need their end | 5265 // don't). We work around this by storing all the scopes which need their end |
5265 // position set at the end of the script (the top scope and possible eval | 5266 // position set at the end of the script (the top scope and possible eval |
5266 // scopes) and set their end position after we know the script length. | 5267 // scopes) and set their end position after we know the script length. |
5267 result = DoParseProgram(info); | 5268 result = DoParseProgram(info); |
5268 | 5269 |
(...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6912 try_block, target); | 6913 try_block, target); |
6913 final_loop = target; | 6914 final_loop = target; |
6914 } | 6915 } |
6915 | 6916 |
6916 return final_loop; | 6917 return final_loop; |
6917 } | 6918 } |
6918 | 6919 |
6919 | 6920 |
6920 } // namespace internal | 6921 } // namespace internal |
6921 } // namespace v8 | 6922 } // namespace v8 |
OLD | NEW |