Lines Matching full:module
16 #include "ecmascript/module/js_module_source_text.h"
23 #include "ecmascript/module/module_logger.h"
24 #include "ecmascript/module/js_shared_module_manager.h"
25 #include "ecmascript/module/module_path_helper.h"
35 …ing> SourceTextModule::GetExportedNames(JSThread *thread, const JSHandle<SourceTextModule> &module, in GetExportedNames() argument
39 // 1. Let module be this Source Text Module Record. in GetExportedNames()
40 // 2. If exportStarSet contains module, then in GetExportedNames()
41 if (exportStarSet->GetIdx(module.GetTaggedValue()) != TaggedArray::MAX_ARRAY_INDEX) { in GetExportedNames()
46 // 3. Append module to exportStarSet. in GetExportedNames()
49 newExportStarSet->Set(thread, len, module.GetTaggedValue()); in GetExportedNames()
51 JSTaggedValue entryValue = module->GetLocalExportEntries(); in GetExportedNames()
52 // 5. For each ExportEntry Record e in module.[[LocalExportEntries]], do in GetExportedNames()
55 // 6. For each ExportEntry Record e in module.[[IndirectExportEntries]], do in GetExportedNames()
56 entryValue = module->GetIndirectExportEntries(); in GetExportedNames()
59 entryValue = module->GetStarExportEntries(); in GetExportedNames()
65 // 7. For each ExportEntry Record e in module.[[StarExportEntries]], do in GetExportedNames()
70 // a. Let requestedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). in GetExportedNames()
72 SetExportName(thread, moduleRequest, module, exportedNames, newExportStarSet); in GetExportedNames()
79 // new way with module
81 …const JSHandle<SourceTextModule> &module, const JSHandle<JSTaggedValue> &moduleRequest, bool execu… in HostResolveImportedModuleWithMerge() argument
90 baseFilename = thread->GetEcmaVM()->GetQuickFixManager()->GetBaseFileName(module); in HostResolveImportedModuleWithMerge()
92 baseFilename = module->GetEcmaModuleFilenameString(); in HostResolveImportedModuleWithMerge()
103 CString recordName = module->GetEcmaModuleRecordNameString(); in HostResolveImportedModuleWithMerge()
126 … const JSHandle<SourceTextModule> &module, in HostResolveImportedModule() argument
136 CString dirname = base::PathHelper::ResolveDirPath(module->GetEcmaModuleFilenameString()); in HostResolveImportedModule()
143 bool SourceTextModule::CheckCircularImport(const JSHandle<SourceTextModule> &module, in CheckCircularImport() argument
148 // a. If module and r.[[Module]] are the same Module Record and in CheckCircularImport()
150 if (JSTaggedValue::SameValue(rr.first.GetTaggedValue(), module.GetTaggedValue()) && in CheckCircularImport()
161 … const JSHandle<SourceTextModule> &module, in ResolveExportObject() argument
165 // Let module be this Source Text Module Record. in ResolveExportObject()
168 // For CJS, if exports is not JSObject, means the CJS module use default output in ResolveExportObject()
172 return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, -1)); in ResolveExportObject()
175 return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, -1)); in ResolveExportObject()
186 resolution = ResolveElementOfObject(thread, jsHclass, exportName, module); in ResolveExportObject()
192 … resolution = JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, entry)); in ResolveExportObject()
234 …dValue> SourceTextModule::ResolveExport(JSThread *thread, const JSHandle<SourceTextModule> &module, in ResolveExport() argument
238 // 1. Let module be this Source Text Module Record. in ResolveExport()
241 // 2.For each Record { [[Module]], [[ExportName]] } r in resolveVector, do in ResolveExport()
242 if (CheckCircularImport(module, exportName, resolveVector)) { in ResolveExport()
245 // 3. Append the Record { [[Module]]: module, [[ExportName]]: exportName } to resolveVector. in ResolveExport()
246 resolveVector.emplace_back(std::make_pair(module, exportName)); in ResolveExport()
247 // 4. For each ExportEntry Record e in module.[[LocalExportEntries]], do in ResolveExport()
248 JSHandle<JSTaggedValue> localExportEntriesTv(thread, module->GetLocalExportEntries()); in ResolveExport()
250 …e<JSTaggedValue> resolution = ResolveLocalExport(thread, localExportEntriesTv, exportName, module); in ResolveExport()
255 // 5. For each ExportEntry Record e in module.[[IndirectExportEntries]], do in ResolveExport()
256 JSHandle<JSTaggedValue> indirectExportEntriesTv(thread, module->GetIndirectExportEntries()); in ResolveExport()
259 … exportName, module, resolveVector); in ResolveExport()
267 // a. Assert: A default export was not explicitly defined by this module. in ResolveExport()
274 // 8. For each ExportEntry Record e in module.[[StarExportEntries]], do in ResolveExport()
275 JSTaggedValue starExportEntriesTv = module->GetStarExportEntries(); in ResolveExport()
287 module, starResolution, resolveVector); in ResolveExport()
338 // use module name as so name in MakeNormalizedAppArgs()
352 LOG_FULL(FATAL) << "Invalid native module " << soPath; in MakeAppArgs()
357 // use module name as so name in MakeAppArgs()
390 LOG_FULL(DEBUG) << "Request module is " << moduleRequestName; in LoadNativeModuleImpl()
431 CString errorMsg = "load native module failed."; in LoadNativeModuleMayThrowError()
491 …t SourceTextModule::HandleInstantiateException([[maybe_unused]] JSHandle<SourceTextModule> &module, in HandleInstantiateException() argument
494 // a. For each module m in stack, do in HandleInstantiateException()
506 // b. Assert: module.[[Status]] is "uninstantiated". in HandleInstantiateException()
507 ASSERT(module->GetStatus() == ModuleStatus::UNINSTANTIATED); in HandleInstantiateException()
518 JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleHdl); in Instantiate() local
519 // 1. Let module be this Source Text Module Record. in Instantiate()
520 // 2. Assert: module.[[Status]] is one of UNLINKED, LINKED, EVALUATING-ASYNC, or EVALUATED. in Instantiate()
521 ModuleStatus status = module->GetStatus(); in Instantiate()
526 // 4. Let result be InnerModuleInstantiation(module, stack, 0). in Instantiate()
527 JSHandle<ModuleRecord> moduleRecord = JSHandle<ModuleRecord>::Cast(module); in Instantiate()
531 return HandleInstantiateException(module, stack, result); in Instantiate()
533 // 6. Assert: module.[[Status]] is one of LINKED, EVALUATING-ASYNC, or EVALUATED. in Instantiate()
534 status = module->GetStatus(); in Instantiate()
552 void SourceTextModule::DFSModuleInstantiation(JSHandle<SourceTextModule> &module, in DFSModuleInstantiation() argument
555 // 1. Assert: module occurs exactly once in stack. in DFSModuleInstantiation()
556 // 2. Assert: module.[[DFSAncestorIndex]] is less than or equal to module.[[DFSIndex]]. in DFSModuleInstantiation()
557 int dfsAncIdx = module->GetDFSAncestorIndex(); in DFSModuleInstantiation()
558 int dfsIdx = module->GetDFSIndex(); in DFSModuleInstantiation()
560 // 3. If module.[[DFSAncestorIndex]] equals module.[[DFSIndex]], then in DFSModuleInstantiation()
572 // iv. If requiredModule and module are the same Module Record, set done to true. in DFSModuleInstantiation()
573 … if (JSTaggedValue::SameValue(module.GetTaggedValue(), requiredModule.GetTaggedValue())) { in DFSModuleInstantiation()
581 … JSHandle<SourceTextModule> &module, in HandleInnerModuleInstantiation() argument
586 // a. Let requiredModule be ? HostResolveImportedModule(module, required). in HandleInnerModuleInstantiation()
588 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in HandleInnerModuleInstantiation()
591 SourceTextModule::HostResolveImportedModule(thread, module, required, executeFromJob); in HandleInnerModuleInstantiation()
596 … SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required, executeFromJob); in HandleInnerModuleInstantiation()
617 // i. Assert: requiredModule is a Source Text Module Record. in HandleInnerModuleInstantiation()
618 // ii. Set module.[[DFSAncestorIndex]] to min( in HandleInnerModuleInstantiation()
619 // module.[[DFSAncestorIndex]], requiredModule.[[DFSAncestorIndex]]). in HandleInnerModuleInstantiation()
620 … int dfsAncIdx = std::min(module->GetDFSAncestorIndex(), requiredModule->GetDFSAncestorIndex()); in HandleInnerModuleInstantiation()
621 module->SetDFSAncestorIndex(dfsAncIdx); in HandleInnerModuleInstantiation()
631 // 1. If module is not a Source Text Module Record, then in InnerModuleInstantiation()
635 // a. Perform ? module.Instantiate(). in InnerModuleInstantiation()
640 JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord); in InnerModuleInstantiation() local
641 …// 2. If module.[[Status]] is one of LINKING, LINKED, EVALUATING-ASYNC, or EVALUATED, then Return … in InnerModuleInstantiation()
642 ModuleStatus status = module->GetStatus(); in InnerModuleInstantiation()
649 // 3. Assert: module.[[Status]] is "uninstantiated". in InnerModuleInstantiation()
651 // 4. Set module.[[Status]] to "instantiating". in InnerModuleInstantiation()
652 module->SetStatus(ModuleStatus::INSTANTIATING); in InnerModuleInstantiation()
653 // 5. Set module.[[DFSIndex]] to index. in InnerModuleInstantiation()
654 module->SetDFSIndex(index); in InnerModuleInstantiation()
655 // 6. Set module.[[DFSAncestorIndex]] to index. in InnerModuleInstantiation()
656 module->SetDFSAncestorIndex(index); in InnerModuleInstantiation()
659 // 8. Append module to stack. in InnerModuleInstantiation()
660 stack.emplace_back(module); in InnerModuleInstantiation()
661 // 9. For each String required that is an element of module.[[RequestedModules]], do in InnerModuleInstantiation()
662 if (!module->GetRequestedModules().IsUndefined()) { in InnerModuleInstantiation()
663 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in InnerModuleInstantiation()
668 …auto result = HandleInnerModuleInstantiation(thread, module, required, stack, index, executeFromJo… in InnerModuleInstantiation()
675 // 10. Perform ? ModuleDeclarationEnvironmentSetup(module). in InnerModuleInstantiation()
676 if (module->GetIsNewBcVersion()) { in InnerModuleInstantiation()
677 SourceTextModule::ModuleDeclarationArrayEnvironmentSetup(thread, module); in InnerModuleInstantiation()
679 SourceTextModule::ModuleDeclarationEnvironmentSetup(thread, module); in InnerModuleInstantiation()
682 DFSModuleInstantiation(module, stack); in InnerModuleInstantiation()
687 const JSHandle<SourceTextModule> &module) in ModuleDeclarationEnvironmentSetup() argument
689 CheckResolvedBinding(thread, module); in ModuleDeclarationEnvironmentSetup()
690 if (module->GetImportEntries().IsUndefined()) { in ModuleDeclarationEnvironmentSetup()
693 ASSERT(!SourceTextModule::IsSharedModule(module)); in ModuleDeclarationEnvironmentSetup()
694 // 2. Assert: All named exports from module are resolvable. in ModuleDeclarationEnvironmentSetup()
695 // 3. Let realm be module.[[Realm]]. in ModuleDeclarationEnvironmentSetup()
698 JSHandle<TaggedArray> importEntries(thread, module->GetImportEntries()); in ModuleDeclarationEnvironmentSetup()
702 // 6. Set module.[[Environment]] to env. in ModuleDeclarationEnvironmentSetup()
703 module->SetEnvironment(thread, map); in ModuleDeclarationEnvironmentSetup()
705 JSMutableHandle<JSTaggedValue> envRec(thread, module->GetEnvironment()); in ModuleDeclarationEnvironmentSetup()
707 // 8. For each ImportEntry Record in in module.[[ImportEntries]], do in ModuleDeclarationEnvironmentSetup()
718 // a. Let importedModule be ! HostResolveImportedModule(module, in.[[ModuleRequest]]). in ModuleDeclarationEnvironmentSetup()
720 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in ModuleDeclarationEnvironmentSetup()
723 SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest); in ModuleDeclarationEnvironmentSetup()
728 SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest); in ModuleDeclarationEnvironmentSetup()
751 … CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + in ModuleDeclarationEnvironmentSetup()
753 if (!module->GetEcmaModuleRecordNameString().empty()) { in ModuleDeclarationEnvironmentSetup()
754 … CString recordStr = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); in ModuleDeclarationEnvironmentSetup()
757 msg += "' which imported by '" + module->GetEcmaModuleFilenameString() + "'"; in ModuleDeclarationEnvironmentSetup()
762 // in.[[LocalName]], resolution.[[Module]], resolution.[[BindingName]]). in ModuleDeclarationEnvironmentSetup()
770 module->SetEnvironment(thread, envRec); in ModuleDeclarationEnvironmentSetup()
774 … const JSHandle<SourceTextModule> &module) in ModuleDeclarationArrayEnvironmentSetup() argument
776 …if (IsSharedModule(module) && SharedModuleManager::GetInstance()->IsInstaniatedSModule(thread, mod… in ModuleDeclarationArrayEnvironmentSetup()
779 CheckResolvedIndexBinding(thread, module); in ModuleDeclarationArrayEnvironmentSetup()
780 if (module->GetImportEntries().IsUndefined()) { in ModuleDeclarationArrayEnvironmentSetup()
785 // 2. Assert: All named exports from module are resolvable. in ModuleDeclarationArrayEnvironmentSetup()
786 // 3. Let realm be module.[[Realm]]. in ModuleDeclarationArrayEnvironmentSetup()
789 JSHandle<TaggedArray> importEntries(thread, module->GetImportEntries()); in ModuleDeclarationArrayEnvironmentSetup()
794 // 8. For each ImportEntry Record in in module.[[ImportEntries]], do in ModuleDeclarationArrayEnvironmentSetup()
803 // a. Let importedModule be ! HostResolveImportedModule(module, in.[[ModuleRequest]]). in ModuleDeclarationArrayEnvironmentSetup()
805 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in ModuleDeclarationArrayEnvironmentSetup()
808 SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest); in ModuleDeclarationArrayEnvironmentSetup()
813 SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest); in ModuleDeclarationArrayEnvironmentSetup()
821 envRec = JSSharedModule::CloneEnvForSModule(thread, module, envRec); in ModuleDeclarationArrayEnvironmentSetup()
822 module->SetEnvironment(thread, envRec); in ModuleDeclarationArrayEnvironmentSetup()
832 … CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + in ModuleDeclarationArrayEnvironmentSetup()
834 if (!module->GetEcmaModuleRecordNameString().empty()) { in ModuleDeclarationArrayEnvironmentSetup()
836 module->GetEcmaModuleRecordNameString()); in ModuleDeclarationArrayEnvironmentSetup()
839 msg += "' which imported by '" + module->GetEcmaModuleFilenameString() + "'"; in ModuleDeclarationArrayEnvironmentSetup()
844 // in.[[LocalName]], resolution.[[Module]], resolution.[[BindingName]]). in ModuleDeclarationArrayEnvironmentSetup()
847 envRec = JSSharedModule::CloneEnvForSModule(thread, module, envRec); in ModuleDeclarationArrayEnvironmentSetup()
848 module->SetEnvironment(thread, envRec); in ModuleDeclarationArrayEnvironmentSetup()
852 … const JSHandle<SourceTextModule> &module) in GetModuleNamespace() argument
855 // 1. Assert: module is an instance of a concrete subclass of Module Record. in GetModuleNamespace()
856 // 2. Assert: module.[[Status]] is not "uninstantiated". in GetModuleNamespace()
857 ASSERT(module->GetStatus() != ModuleStatus::UNINSTANTIATED); in GetModuleNamespace()
858 // 3. Let namespace be module.[[Namespace]]. in GetModuleNamespace()
859 … JSMutableHandle<JSTaggedValue> moduleNamespace(thread, module->GetNamespace().GetWeakRawValue()); in GetModuleNamespace()
862 // a. Let exportedNames be ? module.GetExportedNames(« »). in GetModuleNamespace()
864 …CVector<std::string> exportedNames = SourceTextModule::GetExportedNames(thread, module, exportStar… in GetModuleNamespace()
870 // i. Let resolution be ? module.ResolveExport(name, « »). in GetModuleNamespace()
874 SourceTextModule::ResolveExport(thread, module, nameHandle, resolveVector); in GetModuleNamespace()
882 JSHandle<JSTaggedValue> moduleTagged = JSHandle<JSTaggedValue>::Cast(module); in GetModuleNamespace()
890 void SourceTextModule::HandleEvaluateResult(JSThread *thread, JSHandle<SourceTextModule> &module, in HandleEvaluateResult() argument
897 // a. For each module m in stack, do in HandleEvaluateResult()
906 // b. Assert: module.[[Status]] is "evaluated" and module.[[EvaluationError]] is result. in HandleEvaluateResult()
907 status = module->GetStatus(); in HandleEvaluateResult()
908 ASSERT(status == ModuleStatus::EVALUATED && module->GetEvaluationError() == result); in HandleEvaluateResult()
920 // a. Assert: module.[[Status]] is either EVALUATING-ASYNC or EVALUATED. in HandleEvaluateResult()
921 status = module->GetStatus(); in HandleEvaluateResult()
923 // b. Assert: module.[[EvaluationError]] is EMPTY. in HandleEvaluateResult()
924 ASSERT(module->GetEvaluationError() == SourceTextModule::UNDEFINED_INDEX); in HandleEvaluateResult()
925 // c. If module.[[AsyncEvaluation]] is false, then in HandleEvaluateResult()
926 // i. Assert: module.[[Status]] is EVALUATED. in HandleEvaluateResult()
928 if (!module->IsAsyncEvaluating()) { in HandleEvaluateResult()
940 // 1. Let module be this Source Text Module Record. in Evaluate()
941 // 2. Assert: module.[[Status]] is one of LINKED, EVALUATING-ASYNC, or EVALUATED. in Evaluate()
942 JSMutableHandle<SourceTextModule> module(thread, moduleHdl); in Evaluate() local
943 ModuleStatus status = module->GetStatus(); in Evaluate()
946 …// 3. If module.[[Status]] is either EVALUATING-ASYNC or EVALUATED, set module to module.[[CycleRo… in Evaluate()
948 module.Update(module->GetCycleRoot()); in Evaluate()
950 // 4. If module.[[TopLevelCapability]] is not EMPTY, then in Evaluate()
951 // a. Return module.[[TopLevelCapability]].[[Promise]]. in Evaluate()
960 // 7. Set module.[[TopLevelCapability]] to capability. in Evaluate()
961 if (!SourceTextModule::IsSharedModule(module)) { in Evaluate()
962 module->SetTopLevelCapability(thread, capability); in Evaluate()
965 // 8. Let result be Completion(InnerModuleEvaluation(module, stack, 0)). in Evaluate()
966 …int result = SourceTextModule::InnerModuleEvaluation(thread, module, stack, 0, buffer, size, execu… in Evaluate()
967 HandleEvaluateResult(thread, module, capability, stack, result); in Evaluate()
973 moduleLogger->InsertEntryPointModule(module); in Evaluate()
979 …SourceTextModule::EvaluateForConcurrent(JSThread *thread, const JSHandle<SourceTextModule> &module, in EvaluateForConcurrent() argument
982 // 1. Let module be this Source Text Module Record. in EvaluateForConcurrent()
983 // 2. Assert: module.[[Status]] is "instantiated" or "evaluated". in EvaluateForConcurrent()
984 [[maybe_unused]] ModuleStatus status = module->GetStatus(); in EvaluateForConcurrent()
986 // 4. Let result be InnerModuleEvaluation(module, stack, 0) in EvaluateForConcurrent()
987 JSHandle<ModuleRecord> moduleRecord = JSHandle<ModuleRecord>::Cast(module); in EvaluateForConcurrent()
1016 JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord); in InnerModuleEvaluationUnsafe() local
1017 ModuleStatus status = module->GetStatus(); in InnerModuleEvaluationUnsafe()
1019 if (module->GetEvaluationError() == SourceTextModule::UNDEFINED_INDEX) { in InnerModuleEvaluationUnsafe()
1022 // Otherwise return module.[[EvaluationError]]. in InnerModuleEvaluationUnsafe()
1023 return module->GetEvaluationError(); in InnerModuleEvaluationUnsafe()
1029 module->SetStatus(ModuleStatus::EVALUATING); in InnerModuleEvaluationUnsafe()
1030 module->SetDFSIndex(index); in InnerModuleEvaluationUnsafe()
1031 module->SetDFSAncestorIndex(index); in InnerModuleEvaluationUnsafe()
1032 module->SetPendingAsyncDependencies(0); in InnerModuleEvaluationUnsafe()
1034 stack.emplace_back(module); in InnerModuleEvaluationUnsafe()
1036 if (!module->GetRequestedModules().IsUndefined()) { in InnerModuleEvaluationUnsafe()
1037 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in InnerModuleEvaluationUnsafe()
1043 if (module->IsLazyImportModule(idx)) { in InnerModuleEvaluationUnsafe()
1047 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in InnerModuleEvaluationUnsafe()
1050 SourceTextModule::HostResolveImportedModule(thread, module, required)); in InnerModuleEvaluationUnsafe()
1053 SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required)); in InnerModuleEvaluationUnsafe()
1057 moduleLogger->InsertParentModule(module, requiredModule); in InnerModuleEvaluationUnsafe()
1085 … int dfsAncIdx = std::min(module->GetDFSAncestorIndex(), requiredModule->GetDFSAncestorIndex()); in InnerModuleEvaluationUnsafe()
1086 module->SetDFSAncestorIndex(dfsAncIdx); in InnerModuleEvaluationUnsafe()
1097 module->SetPendingAsyncDependencies(module->GetPendingAsyncDependencies() + 1); in InnerModuleEvaluationUnsafe()
1098 AddAsyncParentModule(thread, requiredModule, module); in InnerModuleEvaluationUnsafe()
1102 int pendingAsyncDependencies = module->GetPendingAsyncDependencies(); in InnerModuleEvaluationUnsafe()
1103 bool hasTLA = module->GetHasTLA(); in InnerModuleEvaluationUnsafe()
1105 // 12. If module.[[PendingAsyncDependencies]] > 0 or module.[[HasTLA]] is true, then in InnerModuleEvaluationUnsafe()
1107 // a. Assert: module.[[AsyncEvaluation]] is false and was never previously set to true. in InnerModuleEvaluationUnsafe()
1108 ASSERT(module->GetAsyncEvaluatingOrdinal() == NOT_ASYNC_EVALUATED); in InnerModuleEvaluationUnsafe()
1109 // b. Set module.[[AsyncEvaluation]] to true. in InnerModuleEvaluationUnsafe()
1110 module->SetAsyncEvaluatingOrdinal(moduleManager->NextModuleAsyncEvaluatingOrdinal()); in InnerModuleEvaluationUnsafe()
1111 // d. If module.[[PendingAsyncDependencies]] = 0, perform ExecuteAsyncModule(module). in InnerModuleEvaluationUnsafe()
1113 SourceTextModule::ExecuteAsyncModule(thread, module, buffer, size, executeFromJob); in InnerModuleEvaluationUnsafe()
1117 // 13. Else, Perform ? module.ExecuteModule(). in InnerModuleEvaluationUnsafe()
1118 SourceTextModule::ModuleExecution(thread, module, buffer, size, executeFromJob); in InnerModuleEvaluationUnsafe()
1121 // 14. Assert: module occurs exactly once in stack. in InnerModuleEvaluationUnsafe()
1122 // 15. Assert: module.[[DFSAncestorIndex]] ≤ module.[[DFSIndex]]. in InnerModuleEvaluationUnsafe()
1123 int dfsAncIdx = module->GetDFSAncestorIndex(); in InnerModuleEvaluationUnsafe()
1124 int dfsIdx = module->GetDFSIndex(); in InnerModuleEvaluationUnsafe()
1126 // 16. If module.[[DFSAncestorIndex]] = module.[[DFSIndex]], then in InnerModuleEvaluationUnsafe()
1136 // iii. Assert: requiredModule is a Cyclic Module Record. in InnerModuleEvaluationUnsafe()
1144 // vi. If requiredModule and module are the same Module Record, set done to true. in InnerModuleEvaluationUnsafe()
1145 … if (JSTaggedValue::SameValue(module.GetTaggedValue(), requiredModule.GetTaggedValue())) { in InnerModuleEvaluationUnsafe()
1148 // vii. Set requiredModule.[[CycleRoot]] to module. in InnerModuleEvaluationUnsafe()
1150 requiredModule->SetCycleRoot(thread, module); in InnerModuleEvaluationUnsafe()
1157 const JSHandle<SourceTextModule> &module) in IsEvaluatedModule() argument
1159 return GetModuleEvaluatingType(thread, stateVisit, module) == ModuleStatus::EVALUATED; in IsEvaluatedModule()
1163 const JSHandle<SourceTextModule> &module) in GetModuleEvaluatingType() argument
1166 return module->GetStatus(); in GetModuleEvaluatingType()
1169 …SourceTextModule::InnerModuleEvaluation(JSThread *thread, const JSHandle<SourceTextModule> &module, in InnerModuleEvaluation() argument
1173 bool isShared = IsSharedModule(module); in InnerModuleEvaluation()
1174 JSHandle<ModuleRecord> moduleRecord = JSHandle<ModuleRecord>::Cast(module); in InnerModuleEvaluation()
1179 …ateVisit &stateVisit = SharedModuleManager::GetInstance()->findModuleMutexWithLock(thread, module); in InnerModuleEvaluation()
1180 if (module->GetStatus() == ModuleStatus::EVALUATING && in InnerModuleEvaluation()
1185 if (module->GetStatus() == ModuleStatus::INSTANTIATED) { in InnerModuleEvaluation()
1197 …rceTextModule::HandleConcurrentEvaluateResult(JSThread *thread, JSHandle<SourceTextModule> &module, in HandleConcurrentEvaluateResult() argument
1203 // a. For each module m in stack, do in HandleConcurrentEvaluateResult()
1212 // b. Assert: module.[[Status]] is "evaluated" and module.[[EvaluationError]] is result. in HandleConcurrentEvaluateResult()
1213 status = module->GetStatus(); in HandleConcurrentEvaluateResult()
1214 ASSERT(status == ModuleStatus::EVALUATED && module->GetEvaluationError() == result); in HandleConcurrentEvaluateResult()
1217 // a. Assert: module.[[Status]] is either EVALUATING-ASYNC or EVALUATED. in HandleConcurrentEvaluateResult()
1218 status = module->GetStatus(); in HandleConcurrentEvaluateResult()
1220 // b. Assert: module.[[EvaluationError]] is EMPTY. in HandleConcurrentEvaluateResult()
1221 ASSERT(module->GetEvaluationError() == SourceTextModule::UNDEFINED_INDEX); in HandleConcurrentEvaluateResult()
1222 // c. If module.[[AsyncEvaluation]] is false, then in HandleConcurrentEvaluateResult()
1223 // i. Assert: module.[[Status]] is EVALUATED. in HandleConcurrentEvaluateResult()
1224 if (!module->IsAsyncEvaluating()) { in HandleConcurrentEvaluateResult()
1235 JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord); in ModuleEvaluation() local
1236 if (!module->GetRequestedModules().IsUndefined()) { in ModuleEvaluation()
1237 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in ModuleEvaluation()
1243 // skip the unused module in ModuleEvaluation()
1248 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in ModuleEvaluation()
1250 … requiredModule.Update(SourceTextModule::HostResolveImportedModule(thread, module, required)); in ModuleEvaluation()
1253 …uiredModule.Update(SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required)); in ModuleEvaluation()
1276 const JSHandle<SourceTextModule> &module, const void *buffer, size_t size, bool executeFromJob) in ModuleExecution() argument
1280 moduleFilenameStr = thread->GetEcmaVM()->GetQuickFixManager()->GetBaseFileName(module); in ModuleExecution()
1282 moduleFilenameStr = module->GetEcmaModuleFilenameString(); in ModuleExecution()
1285 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in ModuleExecution()
1307 void SourceTextModule::AddImportEntry(JSThread *thread, const JSHandle<SourceTextModule> &module, in AddImportEntry() argument
1311 JSTaggedValue importEntries = module->GetImportEntries(); in AddImportEntry()
1315 module->SetImportEntries(thread, array); in AddImportEntry()
1321 module->SetImportEntries(thread, entries); in AddImportEntry()
1328 …d SourceTextModule::AddLocalExportEntry(JSThread *thread, const JSHandle<SourceTextModule> &module, in AddLocalExportEntry() argument
1332 JSTaggedValue localExportEntries = module->GetLocalExportEntries(); in AddLocalExportEntry()
1336 module->SetLocalExportEntries(thread, array); in AddLocalExportEntry()
1343 …ourceTextModule::AddIndirectExportEntry(JSThread *thread, const JSHandle<SourceTextModule> &module, in AddIndirectExportEntry() argument
1348 JSTaggedValue indirectExportEntries = module->GetIndirectExportEntries(); in AddIndirectExportEntry()
1352 module->SetIndirectExportEntries(thread, array); in AddIndirectExportEntry()
1359 …id SourceTextModule::AddStarExportEntry(JSThread *thread, const JSHandle<SourceTextModule> &module, in AddStarExportEntry() argument
1363 JSTaggedValue starExportEntries = module->GetStarExportEntries(); in AddStarExportEntry()
1367 module->SetStarExportEntries(thread, array); in AddStarExportEntry()
1380 …THROW_REFERENCE_ERROR_AND_RETURN(thread, "module environment is undefined", JSTaggedValue::Excepti… in GetModuleValue()
1395 …THROW_REFERENCE_ERROR_AND_RETURN(thread, "module environment is undefined", JSTaggedValue::Excepti… in GetModuleValue()
1451 JSHandle<SourceTextModule> module(thread, this); in StoreModuleValue() local
1452 JSTaggedValue localExportEntries = module->GetLocalExportEntries(); in StoreModuleValue()
1455 JSHandle<JSTaggedValue> data(thread, module->GetNameDictionary()); in StoreModuleValue()
1460 if (SourceTextModule::IsSharedModule(module)) { in StoreModuleValue()
1466 module->SetNameDictionary(thread, data); in StoreModuleValue()
1472 // discard instructions won't consider shared-module.
1476 JSHandle<SourceTextModule> module(thread, this); in StoreModuleValue() local
1477 JSMutableHandle<JSTaggedValue> data(thread, module->GetNameDictionary()); in StoreModuleValue()
1484 module->SetNameDictionary(thread, data); in StoreModuleValue()
1488 const JSHandle<SourceTextModule> &module, in SetExportName() argument
1493 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in SetExportName()
1496 SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest); in SetExportName()
1501 SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest); in SetExportName()
1522 … const JSHandle<SourceTextModule> &module, in GetStarResolution() argument
1528 // a. Let importedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). in GetStarResolution()
1530 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in GetStarResolution()
1533 SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest); in GetStarResolution()
1538 SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest); in GetStarResolution()
1570 … // 2. If resolution.[[Module]] and starResolution.[[Module]] are not the same Module Record or in GetStarResolution()
1604 // a. Assert: module provides the direct binding for this export. in AddExportName()
1615 … const JSHandle<SourceTextModule> &module) in ResolveElementOfObject() argument
1620 return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, idx)); in ResolveElementOfObject()
1628 … const JSHandle<SourceTextModule> &module) in ResolveLocalExport() argument
1639 // if module is type of CommonJS or native, export first, check after execution. in ResolveLocalExport()
1640 auto moduleType = module->GetTypes(); in ResolveLocalExport()
1642 … return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedBindingRecord(module, exportName)); in ResolveLocalExport()
1646 // Adapter new module in ResolveLocalExport()
1647 if (module->GetIsNewBcVersion()) { in ResolveLocalExport()
1648 return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, in ResolveLocalExport()
1651 // i. Assert: module provides the direct binding for this export. in ResolveLocalExport()
1652 … // ii. Return ResolvedBinding Record { [[Module]]: module, [[BindingName]]: e.[[LocalName]] }. in ResolveLocalExport()
1654 … return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedBindingRecord(module, localName)); in ResolveLocalExport()
1663 … const JSHandle<SourceTextModule> &module, in ResolveIndirectExport() argument
1678 // i. Assert: module imports a specific binding for this export. in ResolveIndirectExport()
1679 // ii. Let importedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). in ResolveIndirectExport()
1682 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in ResolveIndirectExport()
1684 …requestedModule.Update(SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest)); in ResolveIndirectExport()
1687 … SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest)); in ResolveIndirectExport()
1698 … SourceTextModule::CheckResolvedBinding(JSThread *thread, const JSHandle<SourceTextModule> &module) in CheckResolvedBinding() argument
1701 // 1. For each ExportEntry Record e in module.[[IndirectExportEntries]], do in CheckResolvedBinding()
1702 JSTaggedValue indirectExportEntriesTv = module->GetIndirectExportEntries(); in CheckResolvedBinding()
1713 // a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « »). in CheckResolvedBinding()
1717 SourceTextModule::ResolveExport(thread, module, exportName, resolveVector); in CheckResolvedBinding()
1721 … CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + in CheckResolvedBinding()
1723 if (!module->GetEcmaModuleRecordNameString().empty()) { in CheckResolvedBinding()
1724 … CString recordStr = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); in CheckResolvedBinding()
1727 msg += "' which exported by '" + module->GetEcmaModuleFilenameString() + "'"; in CheckResolvedBinding()
1736 …ceTextModule::CheckResolvedIndexBinding(JSThread *thread, const JSHandle<SourceTextModule> &module) in CheckResolvedIndexBinding() argument
1739 // 1. For each ExportEntry Record e in module.[[IndirectExportEntries]], do in CheckResolvedIndexBinding()
1740 JSTaggedValue indirectExportEntriesTv = module->GetIndirectExportEntries(); in CheckResolvedIndexBinding()
1751 // a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « »). in CheckResolvedIndexBinding()
1755 SourceTextModule::ResolveExport(thread, module, exportName, resolveVector); in CheckResolvedIndexBinding()
1759 … CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + in CheckResolvedIndexBinding()
1761 if (!module->GetEcmaModuleRecordNameString().empty()) { in CheckResolvedIndexBinding()
1762 … CString record = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); in CheckResolvedIndexBinding()
1765 msg += "' which exported by '" + module->GetEcmaModuleFilenameString() + "'"; in CheckResolvedIndexBinding()
1774 SourceTextModule *module = SourceTextModule::Cast(currentModule.GetTaggedObject()); in GetModuleName() local
1775 CString recordName = module->GetEcmaModuleRecordNameString(); in GetModuleName()
1777 recordName = module->GetEcmaModuleFilenameString(); in GetModuleName()
1792 void SourceTextModule::AddAsyncParentModule(JSThread *thread, JSHandle<SourceTextModule> &module, in AddAsyncParentModule() argument
1796 JSTaggedValue asyncParentModules = module->GetAsyncParentModules(); in AddAsyncParentModule()
1800 module->SetAsyncParentModules(thread, array); in AddAsyncParentModule()
1806 module->SetAsyncParentModules(thread, array); in AddAsyncParentModule()
1810 …id SourceTextModule::ExecuteAsyncModule(JSThread *thread, const JSHandle<SourceTextModule> &module, in ExecuteAsyncModule() argument
1813 // 1. Assert: module.[[Status]] is either EVALUATING or EVALUATING-ASYNC. in ExecuteAsyncModule()
1814 …ASSERT(module->GetStatus() == ModuleStatus::EVALUATING || module->GetStatus() == ModuleStatus::EVA… in ExecuteAsyncModule()
1815 // 2. Assert: module.[[HasTLA]] is true. in ExecuteAsyncModule()
1816 ASSERT(module->GetHasTLA()); in ExecuteAsyncModule()
1817 CString moduleFilenameStr = module->GetEcmaModuleFilenameString(); in ExecuteAsyncModule()
1820 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in ExecuteAsyncModule()
1843 …// 4. Let fulfilledClosure be a new Abstract Closure with no parameters that captures module and p… in ExecuteAsyncModule()
1845 // a. Perform AsyncModuleExecutionFulfilled(module). in ExecuteAsyncModule()
1848 …rejectedClosure be a new Abstract Closure with parameters (error) that captures module and performs in ExecuteAsyncModule()
1850 // a. Perform AsyncModuleExecutionRejected(module, error). in ExecuteAsyncModule()
1859 onFulfilled->SetModule(thread, module); in ExecuteAsyncModule()
1863 onRejected->SetModule(thread, module); in ExecuteAsyncModule()
1872 …rceTextModule::GatherAvailableAncestors(JSThread *thread, const JSHandle<SourceTextModule> &module, in GatherAvailableAncestors() argument
1876 JSTaggedValue asyncParentModulesValue = module->GetAsyncParentModules(); in GatherAvailableAncestors()
1883 // 1. For each Cyclic Module Record m of module.[[AsyncParentModules]], do in GatherAvailableAncestors()
1913 …xtModule::AsyncModuleExecutionFulfilled(JSThread *thread, const JSHandle<SourceTextModule> &module) in AsyncModuleExecutionFulfilled() argument
1915 // 1. If module.[[Status]] is EVALUATED, then in AsyncModuleExecutionFulfilled()
1916 // a. Assert: module.[[EvaluationError]] is not EMPTY. in AsyncModuleExecutionFulfilled()
1918 if (module->GetStatus() == ModuleStatus::EVALUATED) { in AsyncModuleExecutionFulfilled()
1919 ASSERT(module->GetEvaluationError() != SourceTextModule::UNDEFINED_INDEX); in AsyncModuleExecutionFulfilled()
1922 // 2. Assert: module.[[Status]] is EVALUATING-ASYNC. in AsyncModuleExecutionFulfilled()
1923 ASSERT(module->GetStatus() == ModuleStatus::EVALUATING_ASYNC); in AsyncModuleExecutionFulfilled()
1924 // 3. Assert: module.[[AsyncEvaluation]] is true. in AsyncModuleExecutionFulfilled()
1925 ASSERT(module->IsAsyncEvaluating()); in AsyncModuleExecutionFulfilled()
1926 // 4. Assert: module.[[EvaluationError]] is EMPTY. in AsyncModuleExecutionFulfilled()
1927 ASSERT(module->GetEvaluationError() == SourceTextModule::UNDEFINED_INDEX); in AsyncModuleExecutionFulfilled()
1928 // 5. Set module.[[AsyncEvaluation]] to false. in AsyncModuleExecutionFulfilled()
1929 module->SetAsyncEvaluatingOrdinal(ASYNC_EVALUATE_DID_FINISH); in AsyncModuleExecutionFulfilled()
1930 // 6. Set module.[[Status]] to EVALUATED. in AsyncModuleExecutionFulfilled()
1931 module->SetStatus(ModuleStatus::EVALUATED); in AsyncModuleExecutionFulfilled()
1932 // 7. If module.[[TopLevelCapability]] is not EMPTY, then in AsyncModuleExecutionFulfilled()
1933 // a. Assert: module.[[CycleRoot]] is module. in AsyncModuleExecutionFulfilled()
1934 // b. Perform ! Call(module.[[TopLevelCapability]].[[Resolve]], undefined, « undefined »). in AsyncModuleExecutionFulfilled()
1936 JSTaggedValue topLevelCapabilityValue = module->GetTopLevelCapability(); in AsyncModuleExecutionFulfilled()
1938 ASSERT(JSTaggedValue::SameValue(module->GetCycleRoot(), module.GetTaggedValue())); in AsyncModuleExecutionFulfilled()
1951 // 9. Perform GatherAvailableAncestors(module, execList). in AsyncModuleExecutionFulfilled()
1954 GatherAvailableAncestors(thread, module, execList); in AsyncModuleExecutionFulfilled()
1957 // 12. For each Cyclic Module Record m of sortedExecList, do in AsyncModuleExecutionFulfilled()
2000 …extModule::AsyncModuleExecutionRejected(JSThread *thread, const JSHandle<SourceTextModule> &module, in AsyncModuleExecutionRejected() argument
2003 // 1. If module.[[Status]] is EVALUATED, then in AsyncModuleExecutionRejected()
2004 // a. Assert: module.[[EvaluationError]] is not EMPTY. in AsyncModuleExecutionRejected()
2006 if (module->GetStatus() == ModuleStatus::EVALUATED) { in AsyncModuleExecutionRejected()
2007 ASSERT(module->GetEvaluationError() != SourceTextModule::UNDEFINED_INDEX); in AsyncModuleExecutionRejected()
2010 // 2. Assert: module.[[Status]] is EVALUATING-ASYNC. in AsyncModuleExecutionRejected()
2011 ASSERT(module->GetStatus() == ModuleStatus::EVALUATING_ASYNC); in AsyncModuleExecutionRejected()
2012 // 3. Assert: module.[[AsyncEvaluation]] is true. in AsyncModuleExecutionRejected()
2013 ASSERT(module->IsAsyncEvaluating()); in AsyncModuleExecutionRejected()
2014 // 4. Assert: module.[[EvaluationError]] is EMPTY. in AsyncModuleExecutionRejected()
2015 ASSERT(module->GetEvaluationError() == SourceTextModule::UNDEFINED_INDEX); in AsyncModuleExecutionRejected()
2016 // 5. Set module.[[EvaluationError]] to ThrowCompletion(error). in AsyncModuleExecutionRejected()
2017 module->SetEvaluationError(MODULE_ERROR); in AsyncModuleExecutionRejected()
2018 // 6. Set module.[[Status]] to EVALUATED. in AsyncModuleExecutionRejected()
2019 module->SetStatus(ModuleStatus::EVALUATED); in AsyncModuleExecutionRejected()
2020 // 7. For each Cyclic Module Record m of module.[[AsyncParentModules]], do in AsyncModuleExecutionRejected()
2023 JSTaggedValue asyncParentModulesValue = module->GetAsyncParentModules(); in AsyncModuleExecutionRejected()
2034 // 8. If module.[[TopLevelCapability]] is not EMPTY, then in AsyncModuleExecutionRejected()
2035 // a. Assert: module.[[CycleRoot]] is module. in AsyncModuleExecutionRejected()
2036 // b. Perform ! Call(module.[[TopLevelCapability]].[[Reject]], undefined, « error »). in AsyncModuleExecutionRejected()
2037 JSTaggedValue topLevelCapabilityValue = module->GetTopLevelCapability(); in AsyncModuleExecutionRejected()
2044 ASSERT(JSTaggedValue::SameValue(module->GetCycleRoot(), module.GetTaggedValue())); in AsyncModuleExecutionRejected()
2064 JSHandle<SourceTextModule> module(thread, fulfilledFunc->GetModule()); in AsyncModuleFulfilledFunc() local
2065 AsyncModuleExecutionFulfilled(thread, module); in AsyncModuleFulfilledFunc()
2077 JSHandle<SourceTextModule> module(thread, rejectedFunc->GetModule()); in AsyncModuleRejectedFunc() local
2079 AsyncModuleExecutionRejected(thread, module, value.GetTaggedValue()); in AsyncModuleRejectedFunc()
2101 const JSHandle<SourceTextModule> &module, in SearchCircularImport() argument
2105 if (module->GetRequestedModules().IsUndefined()) { in SearchCircularImport()
2109 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in SearchCircularImport()
2116 SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required))); in SearchCircularImport()
2161 // check if module need to be mock in ReplaceModuleThroughFeature()
2166 // Load the replaced module, hms -> system hsp in ReplaceModuleThroughFeature()
2175 const JSHandle<SourceTextModule> &module, const JSHandle<JSTaggedValue> &moduleRequest) in GetResolvedModule() argument
2177 CString dirname = base::PathHelper::ResolveDirPath(module->GetEcmaModuleFilenameString()); in GetResolvedModule()
2195 // new way with module
2197 const JSHandle<SourceTextModule> &module, const JSHandle<JSTaggedValue> &moduleRequest) in GetResolvedModuleWithMerge() argument
2206 // native module cached by current context's module manager. in GetResolvedModuleWithMerge()
2211 CString baseFilename = module->GetEcmaModuleFilenameString(); in GetResolvedModuleWithMerge()
2212 CString recordName = module->GetEcmaModuleRecordNameString(); in GetResolvedModuleWithMerge()