1 // Copyright 2018 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "src/codegen/unoptimized-compilation-info.h" 6 7 #include "src/ast/ast.h" 8 #include "src/ast/scopes.h" 9 #include "src/codegen/source-position.h" 10 #include "src/debug/debug.h" 11 #include "src/execution/isolate.h" 12 #include "src/objects/objects-inl.h" 13 #include "src/parsing/parse-info.h" 14 15 namespace v8 { 16 namespace internal { 17 UnoptimizedCompilationInfo(Zone * zone,ParseInfo * parse_info,FunctionLiteral * literal)18UnoptimizedCompilationInfo::UnoptimizedCompilationInfo(Zone* zone, 19 ParseInfo* parse_info, 20 FunctionLiteral* literal) 21 : flags_(parse_info->flags()), feedback_vector_spec_(zone) { 22 // NOTE: The parse_info passed here represents the global information gathered 23 // during parsing, but does not represent specific details of the actual 24 // function literal being compiled for this OptimizedCompilationInfo. As such, 25 // parse_info->literal() might be different from literal, and only global 26 // details of the script being parsed are relevant to this 27 // OptimizedCompilationInfo. 28 DCHECK_NOT_NULL(literal); 29 literal_ = literal; 30 source_range_map_ = parse_info->source_range_map(); 31 } 32 scope() const33DeclarationScope* UnoptimizedCompilationInfo::scope() const { 34 DCHECK_NOT_NULL(literal_); 35 return literal_->scope(); 36 } 37 num_parameters() const38int UnoptimizedCompilationInfo::num_parameters() const { 39 return scope()->num_parameters(); 40 } 41 num_parameters_including_this() const42int UnoptimizedCompilationInfo::num_parameters_including_this() const { 43 return scope()->num_parameters() + 1; 44 } 45 46 SourcePositionTableBuilder::RecordingMode SourcePositionRecordingMode() const47UnoptimizedCompilationInfo::SourcePositionRecordingMode() const { 48 if (flags().collect_source_positions()) { 49 return SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS; 50 } 51 52 // Always collect source positions for functions that cannot be lazily 53 // compiled, e.g. class member initializer functions. 54 return !literal_->AllowsLazyCompilation() 55 ? SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS 56 : SourcePositionTableBuilder::LAZY_SOURCE_POSITIONS; 57 } 58 59 } // namespace internal 60 } // namespace v8 61