/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
deps/v8/src/objects/module-inl.h
182 строки
6 KB
Michaël Zasso
deps: update V8 to 14.6.202.33
24 апр 2026, 19:01
Не верифицирован
24 апр 2026, 19:01
f1e0b83
Код
Авторство
О чём код?
// Copyright 2017 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. #ifndef V8_OBJECTS_MODULE_INL_H_ #define V8_OBJECTS_MODULE_INL_H_ #include "src/objects/module.h" // Include the non-inl header before the rest of the headers. #include "src/objects/objects-inl.h" // Needed for write barriers #include "src/objects/scope-info.h" #include "src/objects/source-text-module.h" #include "src/objects/string-inl.h" #include "src/objects/synthetic-module.h" // Has to be the last include (doesn't have include guards): #include "src/objects/object-macros.h" namespace v8 { namespace internal { #include "torque-generated/src/objects/module-tq-inl.inc" TQ_OBJECT_CONSTRUCTORS_IMPL(Module) TQ_OBJECT_CONSTRUCTORS_IMPL(JSModuleNamespace) TQ_OBJECT_CONSTRUCTORS_IMPL(JSDeferredModuleNamespace) Tagged<Object> ScriptOrModule::resource_name() const { return resource_name_.load(); } void ScriptOrModule::set_resource_name(Tagged<Object> value, WriteBarrierMode mode) { resource_name_.store(this, value, mode); } Tagged<FixedArray> ScriptOrModule::host_defined_options() const { return host_defined_options_.load(); } void ScriptOrModule::set_host_defined_options(Tagged<FixedArray> value, WriteBarrierMode mode) { host_defined_options_.store(this, value, mode); } BOOL_ACCESSORS(SourceTextModule, flags, has_toplevel_await, HasToplevelAwaitBit::kShift) BIT_FIELD_ACCESSORS(SourceTextModule, flags, async_evaluation_ordinal, SourceTextModule::AsyncEvaluationOrdinalBits) ACCESSORS(SourceTextModule, async_parent_modules, Tagged<ArrayList>, kAsyncParentModulesOffset) BIT_FIELD_ACCESSORS(ModuleRequest, flags, position, ModuleRequest::PositionBits) inline void ModuleRequest::set_phase(ModuleImportPhase phase) { DCHECK(PhaseBits::is_valid(phase)); int hints = flags(); hints = PhaseBits::update(hints, phase); set_flags(hints); } inline ModuleImportPhase ModuleRequest::phase() const { int value = flags() & PhaseBits::kMask; DCHECK(value == 0 || value == 1 || value == 2); return static_cast<ModuleImportPhase>(value); } struct Module::Hash { V8_INLINE size_t operator()(Tagged<Module> module) const { return module->hash(); } }; Tagged<SourceTextModuleInfo> SourceTextModule::info() const { return GetSharedFunctionInfo()->scope_info()->ModuleDescriptorInfo(); } Tagged<FixedArray> SourceTextModuleInfo::module_requests() const { return Cast<FixedArray>(get(kModuleRequestsIndex)); } Tagged<FixedArray> SourceTextModuleInfo::special_exports() const { return Cast<FixedArray>(get(kSpecialExportsIndex)); } Tagged<FixedArray> SourceTextModuleInfo::regular_exports() const { return Cast<FixedArray>(get(kRegularExportsIndex)); } Tagged<FixedArray> SourceTextModuleInfo::regular_imports() const { return Cast<FixedArray>(get(kRegularImportsIndex)); } Tagged<FixedArray> SourceTextModuleInfo::namespace_imports() const { return Cast<FixedArray>(get(kNamespaceImportsIndex)); } // TODO(crbug.com/401059828): make it DEBUG only, once investigation is over. bool SourceTextModuleInfo::Equals(Tagged<SourceTextModuleInfo> other) const { return regular_exports() == other->regular_exports() && regular_imports() == other->regular_imports() && special_exports() == other->special_exports() && namespace_imports() == other->namespace_imports() && module_requests() == other->module_requests(); } struct ModuleHandleHash { V8_INLINE size_t operator()(DirectHandle<Module> module) const { return module->hash(); } }; struct ModuleHandleEqual { V8_INLINE bool operator()(DirectHandle<Module> lhs, DirectHandle<Module> rhs) const { return *lhs == *rhs; } }; class UnorderedModuleSet : public std::unordered_set<Handle<Module>, ModuleHandleHash, ModuleHandleEqual, ZoneAllocator<Handle<Module>>> { public: explicit UnorderedModuleSet(Zone* zone) : std::unordered_set<Handle<Module>, ModuleHandleHash, ModuleHandleEqual, ZoneAllocator<Handle<Module>>>( 2 /* bucket count */, ModuleHandleHash(), ModuleHandleEqual(), ZoneAllocator<Handle<Module>>(zone)) {} }; Handle<SourceTextModule> SourceTextModule::GetCycleRoot( Isolate* isolate) const { CHECK_GE(status(), kEvaluatingAsync); DCHECK(!IsTheHole(cycle_root(), isolate)); Handle<SourceTextModule> root(Cast<SourceTextModule>(cycle_root()), isolate); return root; } void SourceTextModule::AddAsyncParentModule( Isolate* isolate, DirectHandle<SourceTextModule> module, DirectHandle<SourceTextModule> parent) { DirectHandle<ArrayList> async_parent_modules(module->async_parent_modules(), isolate); DirectHandle<ArrayList> new_array_list = ArrayList::Add(isolate, async_parent_modules, parent); module->set_async_parent_modules(*new_array_list); } Handle<SourceTextModule> SourceTextModule::GetAsyncParentModule( Isolate* isolate, int index) { Handle<SourceTextModule> module( Cast<SourceTextModule>(async_parent_modules()->get(index)), isolate); return module; } int SourceTextModule::AsyncParentModuleCount() { return async_parent_modules()->length(); } bool SourceTextModule::HasAsyncEvaluationOrdinal() const { return async_evaluation_ordinal() >= kFirstAsyncEvaluationOrdinal; } bool SourceTextModule::HasPendingAsyncDependencies() { DCHECK_GE(pending_async_dependencies(), 0); return pending_async_dependencies() > 0; } void SourceTextModule::IncrementPendingAsyncDependencies() { set_pending_async_dependencies(pending_async_dependencies() + 1); } void SourceTextModule::DecrementPendingAsyncDependencies() { set_pending_async_dependencies(pending_async_dependencies() - 1); } } // namespace internal } // namespace v8 #include "src/objects/object-macros-undef.h" #endif // V8_OBJECTS_MODULE_INL_H_