OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/parse-info.h" | 5 #include "src/parsing/parse-info.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast-value-factory.h" | 8 #include "src/ast/ast-value-factory.h" |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/heap/heap-inl.h" | 10 #include "src/heap/heap-inl.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 93 } |
94 | 94 |
95 ParseInfo::~ParseInfo() { | 95 ParseInfo::~ParseInfo() { |
96 if (ast_value_factory_owned()) { | 96 if (ast_value_factory_owned()) { |
97 delete ast_value_factory_; | 97 delete ast_value_factory_; |
98 set_ast_value_factory_owned(false); | 98 set_ast_value_factory_owned(false); |
99 } | 99 } |
100 ast_value_factory_ = nullptr; | 100 ast_value_factory_ = nullptr; |
101 } | 101 } |
102 | 102 |
103 // static | |
104 ParseInfo* ParseInfo::AllocateWithoutScript(Handle<SharedFunctionInfo> shared) { | |
105 Isolate* isolate = shared->GetIsolate(); | |
106 ParseInfo* p = new ParseInfo(isolate->allocator()); | |
107 p->isolate_ = isolate; | |
108 | |
109 p->set_toplevel(shared->is_toplevel()); | |
110 p->set_allow_lazy_parsing(FLAG_lazy_inner_functions); | |
111 p->set_hash_seed(isolate->heap()->HashSeed()); | |
112 p->set_is_named_expression(shared->is_named_expression()); | |
113 p->set_calls_eval(shared->scope_info()->CallsEval()); | |
114 p->set_compiler_hints(shared->compiler_hints()); | |
115 p->set_start_position(shared->start_position()); | |
116 p->set_end_position(shared->end_position()); | |
117 p->function_literal_id_ = shared->function_literal_id(); | |
118 p->set_stack_limit(isolate->stack_guard()->real_climit()); | |
119 p->set_unicode_cache(isolate->unicode_cache()); | |
120 p->set_language_mode(shared->language_mode()); | |
121 p->set_shared_info(shared); | |
122 p->set_module(shared->kind() == FunctionKind::kModule); | |
123 | |
124 // BUG(5946): This function exists as a workaround until we can | |
125 // get rid of %SetCode in our native functions. The ParseInfo | |
126 // is explicitly set up for the case that: | |
127 // a) you have a native built-in, | |
128 // b) it's being run for the 2nd-Nth time in an isolate, | |
129 // c) we've already compiled bytecode and therefore don't need | |
130 // to parse. | |
131 // We tolerate a ParseInfo without a Script in this case. | |
132 p->set_native(true); | |
133 p->set_eval(false); | |
134 | |
135 Handle<HeapObject> scope_info(shared->outer_scope_info()); | |
136 if (!scope_info->IsTheHole(isolate) && | |
137 Handle<ScopeInfo>::cast(scope_info)->length() > 0) { | |
138 p->set_outer_scope_info(Handle<ScopeInfo>::cast(scope_info)); | |
139 } | |
140 return p; | |
141 } | |
142 | |
143 DeclarationScope* ParseInfo::scope() const { return literal()->scope(); } | 103 DeclarationScope* ParseInfo::scope() const { return literal()->scope(); } |
144 | 104 |
145 bool ParseInfo::is_declaration() const { | 105 bool ParseInfo::is_declaration() const { |
146 return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDeclaration)) != 0; | 106 return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDeclaration)) != 0; |
147 } | 107 } |
148 | 108 |
149 FunctionKind ParseInfo::function_kind() const { | 109 FunctionKind ParseInfo::function_kind() const { |
150 return SharedFunctionInfo::FunctionKindBits::decode(compiler_hints_); | 110 return SharedFunctionInfo::FunctionKindBits::decode(compiler_hints_); |
151 } | 111 } |
152 | 112 |
153 void ParseInfo::set_deferred_handles( | 113 void ParseInfo::set_deferred_handles( |
154 std::shared_ptr<DeferredHandles> deferred_handles) { | 114 std::shared_ptr<DeferredHandles> deferred_handles) { |
155 DCHECK(deferred_handles_.get() == nullptr); | 115 DCHECK(deferred_handles_.get() == nullptr); |
156 deferred_handles_.swap(deferred_handles); | 116 deferred_handles_.swap(deferred_handles); |
157 } | 117 } |
158 | 118 |
159 void ParseInfo::set_deferred_handles(DeferredHandles* deferred_handles) { | 119 void ParseInfo::set_deferred_handles(DeferredHandles* deferred_handles) { |
160 DCHECK(deferred_handles_.get() == nullptr); | 120 DCHECK(deferred_handles_.get() == nullptr); |
161 deferred_handles_.reset(deferred_handles); | 121 deferred_handles_.reset(deferred_handles); |
162 } | 122 } |
163 | 123 |
164 #ifdef DEBUG | 124 #ifdef DEBUG |
165 bool ParseInfo::script_is_native() const { | 125 bool ParseInfo::script_is_native() const { |
166 return script_->type() == Script::TYPE_NATIVE; | 126 return script_->type() == Script::TYPE_NATIVE; |
167 } | 127 } |
168 #endif // DEBUG | 128 #endif // DEBUG |
169 | 129 |
170 } // namespace internal | 130 } // namespace internal |
171 } // namespace v8 | 131 } // namespace v8 |
OLD | NEW |