// Copyright 2016 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/parsing/parse-info.h" #include "src/ast/ast-source-ranges.h" #include "src/ast/ast-value-factory.h" #include "src/ast/ast.h" #include "src/base/template-utils.h" #include "src/compiler-dispatcher/compiler-dispatcher.h" #include "src/heap/heap-inl.h" #include "src/logging/counters.h" #include "src/logging/log.h" #include "src/numbers/hash-seed-inl.h" #include "src/objects/objects-inl.h" #include "src/objects/scope-info.h" #include "src/zone/zone.h" namespace v8 { namespace internal { ParseInfo::ParseInfo(AccountingAllocator* zone_allocator) : zone_(base::make_unique(zone_allocator, ZONE_NAME)), flags_(0), extension_(nullptr), script_scope_(nullptr), stack_limit_(0), hash_seed_(0), function_kind_(FunctionKind::kNormalFunction), function_syntax_kind_(FunctionSyntaxKind::kDeclaration), script_id_(-1), start_position_(0), end_position_(0), parameters_end_pos_(kNoSourcePosition), function_literal_id_(kFunctionLiteralIdInvalid), max_function_literal_id_(kFunctionLiteralIdInvalid), character_stream_(nullptr), ast_value_factory_(nullptr), ast_string_constants_(nullptr), function_name_(nullptr), runtime_call_stats_(nullptr), source_range_map_(nullptr), literal_(nullptr) {} ParseInfo::ParseInfo(Isolate* isolate, AccountingAllocator* zone_allocator) : ParseInfo(zone_allocator) { set_hash_seed(HashSeed(isolate)); set_stack_limit(isolate->stack_guard()->real_climit()); set_runtime_call_stats(isolate->counters()->runtime_call_stats()); set_logger(isolate->logger()); set_ast_string_constants(isolate->ast_string_constants()); set_collect_source_positions(!FLAG_enable_lazy_source_positions || isolate->NeedsDetailedOptimizedCodeLineInfo()); if (!isolate->is_best_effort_code_coverage()) set_coverage_enabled(); if (isolate->is_block_code_coverage()) set_block_coverage_enabled(); if (isolate->is_collecting_type_profile()) set_collect_type_profile(); if (isolate->compiler_dispatcher()->IsEnabled()) { parallel_tasks_.reset(new ParallelTasks(isolate->compiler_dispatcher())); } set_might_always_opt(FLAG_always_opt || FLAG_prepare_always_opt); set_allow_lazy_compile(FLAG_lazy); set_allow_natives_syntax(FLAG_allow_natives_syntax); set_allow_harmony_dynamic_import(FLAG_harmony_dynamic_import); set_allow_harmony_import_meta(FLAG_harmony_import_meta); set_allow_harmony_optional_chaining(FLAG_harmony_optional_chaining); set_allow_harmony_nullish(FLAG_harmony_nullish); set_allow_harmony_private_methods(FLAG_harmony_private_methods); } ParseInfo::ParseInfo(Isolate* isolate) : ParseInfo(isolate, isolate->allocator()) { script_id_ = isolate->heap()->NextScriptId(); LOG(isolate, ScriptEvent(Logger::ScriptEventType::kReserveId, script_id_)); } template void ParseInfo::SetFunctionInfo(T function) { set_language_mode(function->language_mode()); set_function_kind(function->kind()); set_function_syntax_kind(function->syntax_kind()); set_requires_instance_members_initializer( function->requires_instance_members_initializer()); set_toplevel(function->is_toplevel()); set_is_oneshot_iife(function->is_oneshot_iife()); } ParseInfo::ParseInfo(Isolate* isolate, Handle shared) : ParseInfo(isolate, isolate->allocator()) { // Do not support re-parsing top-level function of a wrapped script. // TODO(yangguo): consider whether we need a top-level function in a // wrapped script at all. DCHECK_IMPLIES(is_toplevel(), !Script::cast(shared->script()).is_wrapped()); set_allow_lazy_parsing(true); set_asm_wasm_broken(shared->is_asm_wasm_broken()); set_start_position(shared->StartPosition()); set_end_position(shared->EndPosition()); function_literal_id_ = shared->function_literal_id(); SetFunctionInfo(shared); Handle