v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
module-inl.h
Go to the documentation of this file.
1// Copyright 2017 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#ifndef V8_OBJECTS_MODULE_INL_H_
6#define V8_OBJECTS_MODULE_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include "src/objects/objects-inl.h" // Needed for write barriers
16
17// Has to be the last include (doesn't have include guards):
19
20namespace v8 {
21namespace internal {
22
23#include "torque-generated/src/objects/module-tq-inl.inc"
24
26TQ_OBJECT_CONSTRUCTORS_IMPL(JSModuleNamespace)
27TQ_OBJECT_CONSTRUCTORS_IMPL(ScriptOrModule)
28
30NEVER_READ_ONLY_SPACE_IMPL(ModuleRequest)
31NEVER_READ_ONLY_SPACE_IMPL(SourceTextModule)
32NEVER_READ_ONLY_SPACE_IMPL(SyntheticModule)
33
34BOOL_ACCESSORS(SourceTextModule, flags, has_toplevel_await,
35 HasToplevelAwaitBit::kShift)
37 SourceTextModule::AsyncEvaluationOrdinalBits)
39 kAsyncParentModulesOffset)
40
42
43inline void ModuleRequest::set_phase(ModuleImportPhase phase) {
44 DCHECK(PhaseBit::is_valid(phase));
45 int hints = flags();
46 hints = PhaseBit::update(hints, phase);
47 set_flags(hints);
48}
49
51 return PhaseBit::decode(flags());
52}
53
55 V8_INLINE size_t operator()(Tagged<Module> module) const {
56 return module->hash();
57 }
58};
59
61 return GetSharedFunctionInfo()->scope_info()->ModuleDescriptorInfo();
62}
63
67
71
75
79
83
84// TODO(crbug.com/401059828): make it DEBUG only, once investigation is over.
86 return regular_exports() == other->regular_exports() &&
87 regular_imports() == other->regular_imports() &&
88 special_exports() == other->special_exports() &&
89 namespace_imports() == other->namespace_imports() &&
90 module_requests() == other->module_requests();
91}
92
95 return module->hash();
96 }
97};
98
101 DirectHandle<Module> rhs) const {
102 return *lhs == *rhs;
103 }
104};
105
107 : public std::unordered_set<Handle<Module>, ModuleHandleHash,
108 ModuleHandleEqual,
109 ZoneAllocator<Handle<Module>>> {
110 public:
111 explicit UnorderedModuleSet(Zone* zone)
114 2 /* bucket count */, ModuleHandleHash(), ModuleHandleEqual(),
115 ZoneAllocator<Handle<Module>>(zone)) {}
116};
117
119 Isolate* isolate) const {
120 CHECK_GE(status(), kEvaluatingAsync);
121 DCHECK(!IsTheHole(cycle_root(), isolate));
122 Handle<SourceTextModule> root(Cast<SourceTextModule>(cycle_root()), isolate);
123 return root;
124}
125
129 DirectHandle<ArrayList> async_parent_modules(module->async_parent_modules(),
130 isolate);
131 DirectHandle<ArrayList> new_array_list =
132 ArrayList::Add(isolate, async_parent_modules, parent);
133 module->set_async_parent_modules(*new_array_list);
134}
135
137 Isolate* isolate, int index) {
139 Cast<SourceTextModule>(async_parent_modules()->get(index)), isolate);
140 return module;
141}
142
144 return async_parent_modules()->length();
145}
146
150
152 DCHECK_GE(pending_async_dependencies(), 0);
153 return pending_async_dependencies() > 0;
154}
155
157 set_pending_async_dependencies(pending_async_dependencies() + 1);
158}
159
161 set_pending_async_dependencies(pending_async_dependencies() - 1);
162}
163
164} // namespace internal
165} // namespace v8
166
168
169#endif // V8_OBJECTS_MODULE_INL_H_
static V8_EXPORT_PRIVATE DirectHandle< ArrayList > Add(Isolate *isolate, DirectHandle< ArrayList > array, Tagged< Smi > obj, AllocationType allocation=AllocationType::kYoung)
ModuleImportPhase phase() const
Definition module-inl.h:50
Tagged< FixedArray > regular_imports() const
Definition module-inl.h:76
Tagged< FixedArray > special_exports() const
Definition module-inl.h:68
bool Equals(Tagged< SourceTextModuleInfo > other) const
Definition module-inl.h:85
Tagged< FixedArray > namespace_imports() const
Definition module-inl.h:80
Tagged< FixedArray > module_requests() const
Definition module-inl.h:64
Tagged< FixedArray > regular_exports() const
Definition module-inl.h:72
static void AddAsyncParentModule(Isolate *isolate, DirectHandle< SourceTextModule > module, DirectHandle< SourceTextModule > parent)
Definition module-inl.h:126
Handle< SourceTextModule > GetAsyncParentModule(Isolate *isolate, int index)
Definition module-inl.h:136
static constexpr unsigned kFirstAsyncEvaluationOrdinal
Handle< SourceTextModule > GetCycleRoot(Isolate *isolate) const
Definition module-inl.h:118
bool HasAsyncEvaluationOrdinal() const
Definition module-inl.h:147
NEVER_READ_ONLY_SPACE Tagged< SharedFunctionInfo > GetSharedFunctionInfo() const
Tagged< SourceTextModuleInfo > info() const
Definition module-inl.h:60
int position
Definition liveedit.cc:290
STL namespace.
Flag flags[]
Definition flags.cc:3797
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
ModuleImportPhase
#define BOOL_ACCESSORS(holder, field, name, offset)
#define ACCESSORS(holder, name, type, offset)
#define TQ_OBJECT_CONSTRUCTORS_IMPL(Type)
#define BIT_FIELD_ACCESSORS(holder, field, name, BitField)
#define NEVER_READ_ONLY_SPACE_IMPL(Type)
#define CHECK_GE(lhs, rhs)
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define DCHECK(condition)
Definition logging.h:482
V8_INLINE bool operator()(DirectHandle< Module > lhs, DirectHandle< Module > rhs) const
Definition module-inl.h:100
V8_INLINE size_t operator()(DirectHandle< Module > module) const
Definition module-inl.h:94
V8_INLINE size_t operator()(Tagged< Module > module) const
Definition module-inl.h:55
#define V8_INLINE
Definition v8config.h:500