Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 set_compiler_hints(shared->compiler_hints()); | 52 set_compiler_hints(shared->compiler_hints()); |
| 53 set_start_position(shared->start_position()); | 53 set_start_position(shared->start_position()); |
| 54 set_end_position(shared->end_position()); | 54 set_end_position(shared->end_position()); |
| 55 function_literal_id_ = shared->function_literal_id(); | 55 function_literal_id_ = shared->function_literal_id(); |
| 56 set_stack_limit(isolate_->stack_guard()->real_climit()); | 56 set_stack_limit(isolate_->stack_guard()->real_climit()); |
| 57 set_unicode_cache(isolate_->unicode_cache()); | 57 set_unicode_cache(isolate_->unicode_cache()); |
| 58 set_language_mode(shared->language_mode()); | 58 set_language_mode(shared->language_mode()); |
| 59 set_shared_info(shared); | 59 set_shared_info(shared); |
| 60 set_module(shared->kind() == FunctionKind::kModule); | 60 set_module(shared->kind() == FunctionKind::kModule); |
| 61 | 61 |
| 62 Handle<Script> script(Script::cast(shared->script())); | 62 if (shared->script()->IsScript()) { |
|
Michael Starzinger
2017/02/15 14:51:48
This should no longer be needed since we have the
mvstanton
2017/02/15 15:18:47
doh! Done.
| |
| 63 set_script(script); | 63 Handle<Script> script(Script::cast(shared->script())); |
| 64 set_native(script->type() == Script::TYPE_NATIVE); | 64 set_script(script); |
| 65 set_eval(script->compilation_type() == Script::COMPILATION_TYPE_EVAL); | 65 set_native(script->type() == Script::TYPE_NATIVE); |
| 66 set_eval(script->compilation_type() == Script::COMPILATION_TYPE_EVAL); | |
| 67 } else { | |
| 68 set_native(true); | |
| 69 set_eval(false); | |
| 70 } | |
| 66 | 71 |
| 67 Handle<HeapObject> scope_info(shared->outer_scope_info()); | 72 Handle<HeapObject> scope_info(shared->outer_scope_info()); |
| 68 if (!scope_info->IsTheHole(isolate()) && | 73 if (!scope_info->IsTheHole(isolate()) && |
| 69 Handle<ScopeInfo>::cast(scope_info)->length() > 0) { | 74 Handle<ScopeInfo>::cast(scope_info)->length() > 0) { |
| 70 set_outer_scope_info(Handle<ScopeInfo>::cast(scope_info)); | 75 set_outer_scope_info(Handle<ScopeInfo>::cast(scope_info)); |
| 71 } | 76 } |
| 72 } | 77 } |
| 73 | 78 |
| 74 ParseInfo::ParseInfo(Handle<SharedFunctionInfo> shared, | 79 ParseInfo::ParseInfo(Handle<SharedFunctionInfo> shared, |
| 75 std::shared_ptr<Zone> zone) | 80 std::shared_ptr<Zone> zone) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 93 } | 98 } |
| 94 | 99 |
| 95 ParseInfo::~ParseInfo() { | 100 ParseInfo::~ParseInfo() { |
| 96 if (ast_value_factory_owned()) { | 101 if (ast_value_factory_owned()) { |
| 97 delete ast_value_factory_; | 102 delete ast_value_factory_; |
| 98 set_ast_value_factory_owned(false); | 103 set_ast_value_factory_owned(false); |
| 99 } | 104 } |
| 100 ast_value_factory_ = nullptr; | 105 ast_value_factory_ = nullptr; |
| 101 } | 106 } |
| 102 | 107 |
| 108 // static | |
| 109 ParseInfo* ParseInfo::AllocateWithoutScript(Handle<SharedFunctionInfo> shared) { | |
| 110 Isolate* isolate = shared->GetIsolate(); | |
| 111 ParseInfo* p = new ParseInfo(isolate->allocator()); | |
| 112 p->isolate_ = isolate; | |
| 113 | |
| 114 p->set_toplevel(shared->is_toplevel()); | |
| 115 p->set_allow_lazy_parsing(FLAG_lazy_inner_functions); | |
| 116 p->set_hash_seed(isolate->heap()->HashSeed()); | |
| 117 p->set_is_named_expression(shared->is_named_expression()); | |
| 118 p->set_calls_eval(shared->scope_info()->CallsEval()); | |
| 119 p->set_compiler_hints(shared->compiler_hints()); | |
| 120 p->set_start_position(shared->start_position()); | |
| 121 p->set_end_position(shared->end_position()); | |
| 122 p->function_literal_id_ = shared->function_literal_id(); | |
| 123 p->set_stack_limit(isolate->stack_guard()->real_climit()); | |
| 124 p->set_unicode_cache(isolate->unicode_cache()); | |
| 125 p->set_language_mode(shared->language_mode()); | |
| 126 p->set_shared_info(shared); | |
| 127 p->set_module(shared->kind() == FunctionKind::kModule); | |
| 128 | |
| 129 // BUG(5946): This function exists as a workaround until we can | |
| 130 // get rid of %SetCode in our native functions. The ParseInfo | |
| 131 // is explicitly set up for the case that: | |
| 132 // a) you have a native built-in, | |
| 133 // b) it's being run for the 2nd-Nth time in an isolate, | |
| 134 // c) we've already compiled bytecode and therefore don't need | |
| 135 // to parse. | |
| 136 // We tolerate a ParseInfo without a Script in this case. | |
| 137 p->set_native(true); | |
| 138 p->set_eval(false); | |
| 139 | |
| 140 Handle<HeapObject> scope_info(shared->outer_scope_info()); | |
| 141 if (!scope_info->IsTheHole(isolate) && | |
| 142 Handle<ScopeInfo>::cast(scope_info)->length() > 0) { | |
| 143 p->set_outer_scope_info(Handle<ScopeInfo>::cast(scope_info)); | |
| 144 } | |
| 145 return p; | |
| 146 } | |
| 147 | |
| 103 DeclarationScope* ParseInfo::scope() const { return literal()->scope(); } | 148 DeclarationScope* ParseInfo::scope() const { return literal()->scope(); } |
| 104 | 149 |
| 105 bool ParseInfo::is_declaration() const { | 150 bool ParseInfo::is_declaration() const { |
| 106 return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDeclaration)) != 0; | 151 return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDeclaration)) != 0; |
| 107 } | 152 } |
| 108 | 153 |
| 109 FunctionKind ParseInfo::function_kind() const { | 154 FunctionKind ParseInfo::function_kind() const { |
| 110 return SharedFunctionInfo::FunctionKindBits::decode(compiler_hints_); | 155 return SharedFunctionInfo::FunctionKindBits::decode(compiler_hints_); |
| 111 } | 156 } |
| 112 | 157 |
| 113 void ParseInfo::set_deferred_handles( | 158 void ParseInfo::set_deferred_handles( |
| 114 std::shared_ptr<DeferredHandles> deferred_handles) { | 159 std::shared_ptr<DeferredHandles> deferred_handles) { |
| 115 DCHECK(deferred_handles_.get() == nullptr); | 160 DCHECK(deferred_handles_.get() == nullptr); |
| 116 deferred_handles_.swap(deferred_handles); | 161 deferred_handles_.swap(deferred_handles); |
| 117 } | 162 } |
| 118 | 163 |
| 119 void ParseInfo::set_deferred_handles(DeferredHandles* deferred_handles) { | 164 void ParseInfo::set_deferred_handles(DeferredHandles* deferred_handles) { |
| 120 DCHECK(deferred_handles_.get() == nullptr); | 165 DCHECK(deferred_handles_.get() == nullptr); |
| 121 deferred_handles_.reset(deferred_handles); | 166 deferred_handles_.reset(deferred_handles); |
| 122 } | 167 } |
| 123 | 168 |
| 124 #ifdef DEBUG | 169 #ifdef DEBUG |
| 125 bool ParseInfo::script_is_native() const { | 170 bool ParseInfo::script_is_native() const { |
| 126 return script_->type() == Script::TYPE_NATIVE; | 171 return script_->type() == Script::TYPE_NATIVE; |
| 127 } | 172 } |
| 128 #endif // DEBUG | 173 #endif // DEBUG |
| 129 | 174 |
| 130 } // namespace internal | 175 } // namespace internal |
| 131 } // namespace v8 | 176 } // namespace v8 |
| OLD | NEW |