7#include <unordered_map>
8#include <unordered_set>
31 if (IsSourceTextModule(module)) {
43 if (!
v8_flags.trace_module_status)
return;
45 os <<
"Changing module status from " << Module::StatusString(old_status)
47 << Module::StatusString(
static_cast<Module::Status>(module->status()))
49 PrintModuleName(module, os);
52void PrintStatusMessage(
Tagged<Module> module,
const char* message) {
53 if (!
v8_flags.trace_module_status)
return;
55 os <<
"Instantiating module ";
56 PrintModuleName(module, os);
64 module->set_status(new_status);
65 PrintStatusTransition(module, old_status);
67 module->set_status(new_status);
88 return "EvaluatingAsync";
101 SetStatusInternal(*
this, new_status);
108 IsTheHole(exception(), isolate));
109 DCHECK(!IsTheHole(error, isolate));
110 if (IsSourceTextModule(*
this)) {
114 self->set_code(self->GetSharedFunctionInfo());
117 if (isolate->is_catchable_by_javascript(error)) {
118 set_exception(error);
132 IsSourceTextModule(*module)
136 Reset(isolate, module);
138 if (!IsSourceTextModule(*module)) {
139 DCHECK(IsSyntheticModule(*module));
142 for (
int i = 0;
i < requested_modules->length(); ++
i) {
148#if V8_ENABLE_WEBASSEMBLY
149 DCHECK(IsUndefined(*descendant, isolate) ||
150 IsWasmModuleObject(*descendant));
152 DCHECK(IsUndefined(*descendant, isolate));
160 DCHECK(IsTheHole(module->exception(), isolate));
164 DCHECK(!IsJSModuleNamespace(module->module_namespace()));
165 const int export_count =
166 IsSourceTextModule(*module)
170 ObjectHashTable::New(isolate, export_count);
172 if (IsSourceTextModule(*module)) {
176 module->set_exports(*exports);
183 DCHECK(!IsTheHole(exception()));
195 if (IsSourceTextModule(*module)) {
198 loc, must_resolve, resolve_set);
211 PrintStatusMessage(*module,
"Instantiating module ");
222 unsigned dfs_index = 0;
242 module->SetStatus(kPreLinking);
245 if (IsSourceTextModule(*module)) {
257 unsigned* dfs_index,
Zone* zone) {
259 if (module->status() >=
kLinking)
return true;
263 if (IsSourceTextModule(*module)) {
275 PrintStatusMessage(*module,
"Evaluating module ");
277 int module_status =
module->status();
284 if (IsJSPromise(module->top_level_capability())) {
288 top_level_capability->result() == module->exception());
289 return top_level_capability;
306 module = Cast<SourceTextModule>(module)->GetCycleRoot(isolate);
311 if (IsJSPromise(module->top_level_capability())) {
315 DCHECK(IsUndefined(module->top_level_capability()));
317 if (IsSourceTextModule(*module)) {
328 if (!IsUndefined(*
object, roots)) {
337 if (IsSourceTextModule(*module)) {
344 names.reserve(exports->NumberOfElements());
347 if (!exports->ToKey(roots,
i, &
key))
continue;
350 DCHECK_EQ(
static_cast<int>(names.size()), exports->NumberOfElements());
353 std::sort(names.begin(), names.end(),
355 return String::Compare(isolate, a, b) ==
356 ComparisonResult::kLessThan;
361 isolate->factory()->NewJSModuleNamespace();
362 ns->set_module(*module);
363 module->set_module_namespace(*ns);
369 static_cast<int>(names.size()),
370 "JSModuleNamespace");
372 for (
const auto& name : names) {
374 if (name->AsArrayIndex(&index)) {
396 proto_info->set_module_namespace(*ns);
402 return !IsTheHole(*
object, isolate);
408 if (IsTheHole(*
object, isolate)) {
409 return isolate->factory()->undefined_value();
413 if (IsTheHole(*value, isolate)) {
422 MessageTemplate::kAccessedUninitializedVariable, name));
438 if (IsTheHole(*lookup, isolate))
return Just(
ABSENT);
441 if (IsTheHole(*value, isolate)) {
442 isolate->Throw(*isolate->factory()->NewReferenceError(
443 MessageTemplate::kNotDefined, name));
447 return Just(it->property_attributes());
458 if (IsSymbol(*
key)) {
459 return OrdinaryDefineOwnProperty(isolate,
object,
key, desc, should_throw);
466 Maybe<bool> has_own = GetOwnPropertyDescriptor(&it, ¤t);
477 (desc->has_configurable() && desc->configurable()) ||
478 (desc->has_enumerable() && !desc->enumerable()) ||
480 (desc->has_writable() && !desc->writable()) ||
481 (desc->has_value() &&
484 NewTypeError(MessageTemplate::kRedefineDisallowed,
key));
494 if (!IsSourceTextModule(*
this))
return false;
498 const size_t bucket_count = 2;
501 visited.insert(root);
509 if (current->has_toplevel_await())
return true;
511 for (
int i = 0, length = requested_modules->length();
i < length; ++
i) {
513 if (IsSourceTextModule(descendant)) {
514 const bool cycle = !visited.insert(descendant).second;
518 }
while (!worklist.
empty());
V8_INLINE T FromJust() const &
Local< Value > GetModuleNamespace()
bool IsGraphAsync() const
static DirectHandle< AccessorInfo > MakeModuleNamespaceEntryInfo(Isolate *isolate, DirectHandle< String > name)
Isolate * isolate() const
static V8_WARN_UNUSED_RESULT Maybe< bool > DefineOwnProperty(Isolate *isolate, DirectHandle< JSModuleNamespace > o, DirectHandle< Object > key, PropertyDescriptor *desc, Maybe< ShouldThrow > should_throw)
V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > GetExport(Isolate *isolate, DirectHandle< String > name)
static V8_WARN_UNUSED_RESULT Maybe< PropertyAttributes > GetPropertyAttributes(LookupIterator *it)
bool HasExport(Isolate *isolate, DirectHandle< String > name)
static V8_EXPORT_PRIVATE DirectHandle< NumberDictionary > NormalizeElements(DirectHandle< JSObject > object)
static void SetNormalizedElement(DirectHandle< JSObject > object, uint32_t index, DirectHandle< Object > value, PropertyDetails details)
static void OptimizeAsPrototype(DirectHandle< JSObject > object, bool enable_setup_mode=true)
static void SetNormalizedProperty(DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyDetails details)
static V8_EXPORT_PRIVATE void NormalizeProperties(Isolate *isolate, DirectHandle< JSObject > object, PropertyNormalizationMode mode, int expected_additional_properties, bool use_cache, const char *reason)
static V8_WARN_UNUSED_RESULT Maybe< bool > PreventExtensions(Isolate *isolate, DirectHandle< JSObject > object, ShouldThrow should_throw)
static Handle< Object > Reject(DirectHandle< JSPromise > promise, DirectHandle< Object > reason, bool debug_event=true)
static DirectHandle< PrototypeInfo > GetOrCreatePrototypeInfo(DirectHandle< Map > prototype_map, Isolate *isolate)
static void ResetGraph(Isolate *isolate, DirectHandle< Module > module)
void RecordError(Isolate *isolate, Tagged< Object > error)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Evaluate(Isolate *isolate, Handle< Module > module)
Tagged< Object > GetException()
void SetStatus(Status status)
static V8_WARN_UNUSED_RESULT bool FinishInstantiate(Isolate *isolate, Handle< Module > module, ZoneForwardList< Handle< SourceTextModule > > *stack, unsigned *dfs_index, Zone *zone)
static V8_WARN_UNUSED_RESULT MaybeHandle< Cell > ResolveExport(Isolate *isolate, Handle< Module > module, DirectHandle< String > module_specifier, Handle< String > export_name, MessageLocation loc, bool must_resolve, ResolveSet *resolve_set)
static void Reset(Isolate *isolate, DirectHandle< Module > module)
static V8_WARN_UNUSED_RESULT bool Instantiate(Isolate *isolate, Handle< Module > module, v8::Local< v8::Context > context, v8::Module::ResolveModuleCallback module_callback, v8::Module::ResolveSourceCallback source_callback)
static V8_WARN_UNUSED_RESULT bool PrepareInstantiate(Isolate *isolate, DirectHandle< Module > module, v8::Local< v8::Context > context, v8::Module::ResolveModuleCallback module_callback, v8::Module::ResolveSourceCallback source_callback)
static V8_EXPORT_PRIVATE bool SameValue(Tagged< Object > obj, Tagged< Object > other)
static bool IsAccessorDescriptor(PropertyDescriptor *desc)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Evaluate(Isolate *isolate, Handle< SourceTextModule > module)
static void FetchStarExports(Isolate *isolate, Handle< SourceTextModule > module, Zone *zone, UnorderedModuleSet *visited)
static V8_WARN_UNUSED_RESULT bool PrepareInstantiate(Isolate *isolate, DirectHandle< SourceTextModule > module, v8::Local< v8::Context > context, v8::Module::ResolveModuleCallback module_callback, v8::Module::ResolveSourceCallback source_callback)
static V8_WARN_UNUSED_RESULT MaybeHandle< Cell > ResolveExport(Isolate *isolate, Handle< SourceTextModule > module, DirectHandle< String > module_specifier, Handle< String > export_name, MessageLocation loc, bool must_resolve, ResolveSet *resolve_set)
static V8_WARN_UNUSED_RESULT bool FinishInstantiate(Isolate *isolate, Handle< SourceTextModule > module, ZoneForwardList< Handle< SourceTextModule > > *stack, unsigned *dfs_index, Zone *zone)
static void Reset(Isolate *isolate, DirectHandle< SourceTextModule > module)
static V8_WARN_UNUSED_RESULT bool PrepareInstantiate(Isolate *isolate, DirectHandle< SyntheticModule > module, v8::Local< v8::Context > context)
static V8_WARN_UNUSED_RESULT MaybeHandle< Cell > ResolveExport(Isolate *isolate, DirectHandle< SyntheticModule > module, DirectHandle< String > module_specifier, DirectHandle< String > export_name, MessageLocation loc, bool must_resolve)
static V8_WARN_UNUSED_RESULT bool FinishInstantiate(Isolate *isolate, DirectHandle< SyntheticModule > module)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Evaluate(Isolate *isolate, DirectHandle< SyntheticModule > module)
void push_back(const T &value)
#define RETURN_FAILURE(isolate, should_throw, call)
#define THROW_NEW_ERROR(isolate, call)
#define STACK_CHECK(isolate, result_value)
#define MAYBE_RETURN(call, value)
ZoneStack< RpoNumber > & stack
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
Tagged(T object) -> Tagged< T >
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
void Print(Tagged< Object > obj)
bool IsModule(FunctionKind kind)
ShouldThrow GetShouldThrow(Isolate *isolate, Maybe< ShouldThrow > should_throw)
V8_EXPORT_PRIVATE FlagValues v8_flags
@ CLEAR_INOBJECT_PROPERTIES
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Maybe< T > Just(const T &t)
#define DCHECK_LE(v1, v2)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK_NE(v1, v2)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)