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)18 UnoptimizedCompilationInfo::UnoptimizedCompilationInfo(Zone* zone,
19 ParseInfo* parse_info,
20 FunctionLiteral* literal)
21 : flags_(parse_info->flags()),
22 dispatcher_(parse_info->dispatcher()),
23 character_stream_(parse_info->character_stream()),
24 feedback_vector_spec_(zone) {
25 // NOTE: The parse_info passed here represents the global information gathered
26 // during parsing, but does not represent specific details of the actual
27 // function literal being compiled for this OptimizedCompilationInfo. As such,
28 // parse_info->literal() might be different from literal, and only global
29 // details of the script being parsed are relevant to this
30 // OptimizedCompilationInfo.
31 DCHECK_NOT_NULL(literal);
32 literal_ = literal;
33 source_range_map_ = parse_info->source_range_map();
34 }
35
scope() const36 DeclarationScope* UnoptimizedCompilationInfo::scope() const {
37 DCHECK_NOT_NULL(literal_);
38 return literal_->scope();
39 }
40
num_parameters() const41 int UnoptimizedCompilationInfo::num_parameters() const {
42 return scope()->num_parameters();
43 }
44
num_parameters_including_this() const45 int UnoptimizedCompilationInfo::num_parameters_including_this() const {
46 return scope()->num_parameters() + 1;
47 }
48
49 SourcePositionTableBuilder::RecordingMode
SourcePositionRecordingMode() const50 UnoptimizedCompilationInfo::SourcePositionRecordingMode() const {
51 if (flags().collect_source_positions()) {
52 return SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS;
53 }
54
55 // Always collect source positions for functions that cannot be lazily
56 // compiled, e.g. class member initializer functions.
57 return !literal_->AllowsLazyCompilation()
58 ? SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS
59 : SourcePositionTableBuilder::LAZY_SOURCE_POSITIONS;
60 }
61
62 } // namespace internal
63 } // namespace v8
64