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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 // background thread. We should not access anything Isolate / heap dependent | 935 // background thread. We should not access anything Isolate / heap dependent |
936 // via ParseInfo, and also not pass it forward. | 936 // via ParseInfo, and also not pass it forward. |
937 DCHECK_NULL(scope_state_); | 937 DCHECK_NULL(scope_state_); |
938 DCHECK_NULL(target_stack_); | 938 DCHECK_NULL(target_stack_); |
939 | 939 |
940 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; | 940 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; |
941 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; | 941 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; |
942 | 942 |
943 FunctionLiteral* result = NULL; | 943 FunctionLiteral* result = NULL; |
944 { | 944 { |
945 // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native | 945 Scope* scope; |
946 // context, which will have the "this" binding for script scopes. | 946 if (info->script_scope()) { |
marja
2016/08/03 08:07:48
"script_scope" as a name is very generic, could so
jochen (gone - plz use gerrit)
2016/08/03 09:14:49
well, it's corresponding to the existing set_scrip
| |
947 Scope* scope = NewScriptScope(); | 947 scope = info->script_scope(); |
948 info->set_script_scope(scope); | 948 } else { |
949 if (!info->context().is_null() && !info->context()->IsNativeContext()) { | 949 // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native |
950 scope = Scope::DeserializeScopeChain(info->isolate(), zone(), | 950 // context, which will have the "this" binding for script scopes. |
951 *info->context(), scope, | 951 scope = NewScriptScope(); |
952 ast_value_factory()); | 952 info->set_script_scope(scope); |
953 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this | 953 if (!info->context().is_null() && !info->context()->IsNativeContext()) { |
954 // means the Parser cannot operate independent of the V8 heap. Tell the | 954 scope = Scope::DeserializeScopeChain( |
955 // string table to internalize strings and values right after they're | 955 info->isolate(), zone(), *info->context(), scope, |
956 // created. This kind of parsing can only be done in the main thread. | 956 ast_value_factory(), Scope::DeserializationMode::kKeepScopeInfo); |
957 DCHECK(parsing_on_main_thread_); | 957 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this |
958 ast_value_factory()->Internalize(info->isolate()); | 958 // means the Parser cannot operate independent of the V8 heap. Tell the |
959 // string table to internalize strings and values right after they're | |
960 // created. This kind of parsing can only be done in the main thread. | |
961 DCHECK(parsing_on_main_thread_); | |
962 ast_value_factory()->Internalize(info->isolate()); | |
963 } | |
964 original_scope_ = scope; | |
959 } | 965 } |
960 original_scope_ = scope; | |
961 if (info->is_eval()) { | 966 if (info->is_eval()) { |
962 if (!scope->is_script_scope() || is_strict(info->language_mode())) { | 967 if (!scope->is_script_scope() || is_strict(info->language_mode())) { |
963 parsing_mode = PARSE_EAGERLY; | 968 parsing_mode = PARSE_EAGERLY; |
964 } | 969 } |
965 scope = NewScopeWithParent(scope, EVAL_SCOPE); | 970 scope = NewScopeWithParent(scope, EVAL_SCOPE); |
966 } else if (info->is_module()) { | 971 } else if (info->is_module()) { |
967 scope = NewScopeWithParent(scope, MODULE_SCOPE); | 972 scope = NewScopeWithParent(scope, MODULE_SCOPE); |
968 } | 973 } |
969 | 974 |
970 scope->set_start_position(0); | 975 scope->set_start_position(0); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1109 FunctionLiteral* result = nullptr; | 1114 FunctionLiteral* result = nullptr; |
1110 | 1115 |
1111 { | 1116 { |
1112 // Parse the function literal. | 1117 // Parse the function literal. |
1113 Scope* scope = NewScriptScope(); | 1118 Scope* scope = NewScriptScope(); |
1114 info->set_script_scope(scope); | 1119 info->set_script_scope(scope); |
1115 if (!info->context().is_null()) { | 1120 if (!info->context().is_null()) { |
1116 // Ok to use Isolate here, since lazy function parsing is only done in the | 1121 // Ok to use Isolate here, since lazy function parsing is only done in the |
1117 // main thread. | 1122 // main thread. |
1118 DCHECK(parsing_on_main_thread_); | 1123 DCHECK(parsing_on_main_thread_); |
1119 scope = Scope::DeserializeScopeChain(isolate, zone(), *info->context(), | 1124 scope = Scope::DeserializeScopeChain( |
1120 scope, ast_value_factory()); | 1125 isolate, zone(), *info->context(), scope, ast_value_factory(), |
1126 Scope::DeserializationMode::kKeepScopeInfo); | |
1121 } | 1127 } |
1122 original_scope_ = scope; | 1128 original_scope_ = scope; |
1123 FunctionState function_state(&function_state_, &scope_state_, scope, | 1129 FunctionState function_state(&function_state_, &scope_state_, scope, |
1124 shared_info->kind()); | 1130 shared_info->kind()); |
1125 DCHECK(is_sloppy(scope->language_mode()) || | 1131 DCHECK(is_sloppy(scope->language_mode()) || |
1126 is_strict(info->language_mode())); | 1132 is_strict(info->language_mode())); |
1127 DCHECK(info->language_mode() == shared_info->language_mode()); | 1133 DCHECK(info->language_mode() == shared_info->language_mode()); |
1128 FunctionLiteral::FunctionType function_type = | 1134 FunctionLiteral::FunctionType function_type = |
1129 ComputeFunctionType(shared_info); | 1135 ComputeFunctionType(shared_info); |
1130 bool ok = true; | 1136 bool ok = true; |
(...skipping 5956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7087 node->Print(Isolate::Current()); | 7093 node->Print(Isolate::Current()); |
7088 } | 7094 } |
7089 #endif // DEBUG | 7095 #endif // DEBUG |
7090 | 7096 |
7091 #undef CHECK_OK | 7097 #undef CHECK_OK |
7092 #undef CHECK_OK_VOID | 7098 #undef CHECK_OK_VOID |
7093 #undef CHECK_FAILED | 7099 #undef CHECK_FAILED |
7094 | 7100 |
7095 } // namespace internal | 7101 } // namespace internal |
7096 } // namespace v8 | 7102 } // namespace v8 |
OLD | NEW |