• Home
  • Raw
  • Download

Lines Matching full:module

16 #include "ecmascript/module/js_module_source_text.h"
23 #include "ecmascript/module/module_logger.h"
24 #include "ecmascript/module/module_message_helper.h"
25 #include "ecmascript/module/module_path_helper.h"
26 #include "ecmascript/module/module_tools.h"
28 #include "ecmascript/module/module_resolver.h"
38 …ing> SourceTextModule::GetExportedNames(JSThread *thread, const JSHandle<SourceTextModule> &module, in GetExportedNames() argument
42 // 1. Let module be this Source Text Module Record. in GetExportedNames()
43 // 2. If exportStarSet contains module, then in GetExportedNames()
44 if (exportStarSet->GetIdx(module.GetTaggedValue()) != TaggedArray::MAX_ARRAY_INDEX) { in GetExportedNames()
49 // 3. Append module to exportStarSet. in GetExportedNames()
52 newExportStarSet->Set(thread, len, module.GetTaggedValue()); in GetExportedNames()
54 JSTaggedValue entryValue = module->GetLocalExportEntries(); in GetExportedNames()
55 // 5. For each ExportEntry Record e in module.[[LocalExportEntries]], do in GetExportedNames()
58 // 6. For each ExportEntry Record e in module.[[IndirectExportEntries]], do in GetExportedNames()
59 entryValue = module->GetIndirectExportEntries(); in GetExportedNames()
62 entryValue = module->GetStarExportEntries(); in GetExportedNames()
66 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in GetExportedNames()
67 // 7. For each ExportEntry Record e in module.[[StarExportEntries]], do in GetExportedNames()
72 // a. Let requestedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). in GetExportedNames()
74 GetRequestedModule(thread, module, requestedModules, ee->GetModuleRequestIndex())); in GetExportedNames()
83 bool SourceTextModule::CheckCircularImport(const JSHandle<SourceTextModule> &module, in CheckCircularImport() argument
88 // a. If module and r.[[Module]] are the same Module Record and in CheckCircularImport()
90 if (JSTaggedValue::SameValue(rr.first.GetTaggedValue(), module.GetTaggedValue()) && in CheckCircularImport()
101 … const JSHandle<SourceTextModule> &module, in ResolveExportObject() argument
105 // Let module be this Source Text Module Record. in ResolveExportObject()
108 // For CJS, if exports is not JSObject, means the CJS module use default output in ResolveExportObject()
112 return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, -1)); in ResolveExportObject()
115 return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, -1)); in ResolveExportObject()
126 resolution = ResolveElementOfObject(thread, jsHclass, exportName, module); in ResolveExportObject()
132 … resolution = JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, entry)); in ResolveExportObject()
170 …dValue> SourceTextModule::ResolveExport(JSThread *thread, const JSHandle<SourceTextModule> &module, in ResolveExport() argument
174 // 1. Let module be this Source Text Module Record. in ResolveExport()
177 // 2.For each Record { [[Module]], [[ExportName]] } r in resolveVector, do in ResolveExport()
178 if (CheckCircularImport(module, exportName, resolveVector)) { in ResolveExport()
181 // 3. Append the Record { [[Module]]: module, [[ExportName]]: exportName } to resolveVector. in ResolveExport()
182 resolveVector.emplace_back(std::make_pair(module, exportName)); in ResolveExport()
183 // 4. For each ExportEntry Record e in module.[[LocalExportEntries]], do in ResolveExport()
184 JSHandle<JSTaggedValue> localExportEntriesTv(thread, module->GetLocalExportEntries()); in ResolveExport()
186 …e<JSTaggedValue> resolution = ResolveLocalExport(thread, localExportEntriesTv, exportName, module); in ResolveExport()
191 // 5. For each ExportEntry Record e in module.[[IndirectExportEntries]], do in ResolveExport()
192 JSHandle<JSTaggedValue> indirectExportEntriesTv(thread, module->GetIndirectExportEntries()); in ResolveExport()
195 … exportName, module, resolveVector); in ResolveExport()
204 // a. Assert: A default export was not explicitly defined by this module. in ResolveExport()
211 // 8. For each ExportEntry Record e in module.[[StarExportEntries]], do in ResolveExport()
212 JSTaggedValue starExportEntriesTv = module->GetStarExportEntries(); in ResolveExport()
217 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in ResolveExport()
222 // a. Let importedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). in ResolveExport()
224 GetRequestedModule(thread, module, requestedModules, ee->GetModuleRequestIndex())); in ResolveExport()
284 // use module name as so name in MakeNormalizedAppArgs()
298 LOG_FULL(FATAL) << "Invalid native module " << soPath; in MakeAppArgs()
303 // use module name as so name in MakeAppArgs()
332 LOG_FULL(DEBUG) << "Request module is " << moduleRequestName; in LoadNativeModuleImpl()
366 CString errorMsg = "load native module failed."; in LoadNativeModuleMayThrowError()
413 …t SourceTextModule::HandleInstantiateException([[maybe_unused]] JSHandle<SourceTextModule> &module, in HandleInstantiateException() argument
416 // a. For each module m in stack, do in HandleInstantiateException()
428 // b. Assert: module.[[Status]] is "uninstantiated". in HandleInstantiateException()
429 ASSERT(module->GetStatus() == ModuleStatus::UNINSTANTIATED); in HandleInstantiateException()
440 JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleHdl); in Instantiate() local
441 // 1. Let module be this Source Text Module Record. in Instantiate()
442 // 2. Assert: module.[[Status]] is one of UNLINKED, LINKED, EVALUATING-ASYNC, or EVALUATED. in Instantiate()
443 ModuleStatus status = module->GetStatus(); in Instantiate()
449 // 4. Let result be InnerModuleInstantiation(module, stack, 0). in Instantiate()
450 JSHandle<ModuleRecord> moduleRecord = JSHandle<ModuleRecord>::Cast(module); in Instantiate()
454 return HandleInstantiateException(module, stack, result); in Instantiate()
456 // 6. Assert: module.[[Status]] is one of LINKED, EVALUATING-ASYNC, or EVALUATED. in Instantiate()
457 status = module->GetStatus(); in Instantiate()
475 void SourceTextModule::DFSModuleInstantiation(JSHandle<SourceTextModule> &module, in DFSModuleInstantiation() argument
478 // 1. Assert: module occurs exactly once in stack. in DFSModuleInstantiation()
479 // 2. Assert: module.[[DFSAncestorIndex]] is less than or equal to module.[[DFSIndex]]. in DFSModuleInstantiation()
480 int dfsAncIdx = module->GetDFSAncestorIndex(); in DFSModuleInstantiation()
481 int dfsIdx = module->GetDFSIndex(); in DFSModuleInstantiation()
483 // 3. If module.[[DFSAncestorIndex]] equals module.[[DFSIndex]], then in DFSModuleInstantiation()
495 // iv. If requiredModule and module are the same Module Record, set done to true. in DFSModuleInstantiation()
496 … if (JSTaggedValue::SameValue(module.GetTaggedValue(), requiredModule.GetTaggedValue())) { in DFSModuleInstantiation()
504 … JSHandle<SourceTextModule> &module, in HandleInnerModuleInstantiation() argument
511 // a. Let requiredModule be ? HostResolveImportedModule(module, required). in HandleInnerModuleInstantiation()
514 ModuleResolver::HostResolveImportedModule(thread, module, required, executeType); in HandleInnerModuleInstantiation()
516 if (!SourceTextModule::IsSharedModule(JSHandle<SourceTextModule>::Cast(module))) { in HandleInnerModuleInstantiation()
538 // i. Assert: requiredModule is a Source Text Module Record. in HandleInnerModuleInstantiation()
539 // ii. Set module.[[DFSAncestorIndex]] to min( in HandleInnerModuleInstantiation()
540 // module.[[DFSAncestorIndex]], requiredModule.[[DFSAncestorIndex]]). in HandleInnerModuleInstantiation()
541 … int dfsAncIdx = std::min(module->GetDFSAncestorIndex(), requiredModule->GetDFSAncestorIndex()); in HandleInnerModuleInstantiation()
542 module->SetDFSAncestorIndex(dfsAncIdx); in HandleInnerModuleInstantiation()
552 // 1. If module is not a Source Text Module Record, then in InnerModuleInstantiation()
556 // a. Perform ? module.Instantiate(). in InnerModuleInstantiation()
561 JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord); in InnerModuleInstantiation() local
562 …// 2. If module.[[Status]] is one of LINKING, LINKED, EVALUATING-ASYNC, or EVALUATED, then Return … in InnerModuleInstantiation()
563 ModuleStatus status = module->GetStatus(); in InnerModuleInstantiation()
567 if (SourceTextModule::IsSharedModule(module) && status == ModuleStatus::EVALUATING) { in InnerModuleInstantiation()
568 LOG_FULL(INFO) << "circular dependency occurred of shared-module"; in InnerModuleInstantiation()
571 // 3. Assert: module.[[Status]] is "uninstantiated". in InnerModuleInstantiation()
573 // 4. Set module.[[Status]] to "instantiating". in InnerModuleInstantiation()
574 module->SetStatus(ModuleStatus::INSTANTIATING); in InnerModuleInstantiation()
575 // 5. Set module.[[DFSIndex]] to index. in InnerModuleInstantiation()
576 module->SetDFSIndex(index); in InnerModuleInstantiation()
577 // 6. Set module.[[DFSAncestorIndex]] to index. in InnerModuleInstantiation()
578 module->SetDFSAncestorIndex(index); in InnerModuleInstantiation()
581 // 8. Append module to stack. in InnerModuleInstantiation()
582 stack.emplace_back(module); in InnerModuleInstantiation()
583 // 9. For each String required that is an element of module.[[RequestedModules]], do in InnerModuleInstantiation()
584 if (!module->GetModuleRequests().IsUndefined()) { in InnerModuleInstantiation()
585 JSHandle<TaggedArray> moduleRequests(thread, module->GetModuleRequests()); in InnerModuleInstantiation()
586 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in InnerModuleInstantiation()
592 thread, module, required, stack, requestedModules, idx, index, executeType); in InnerModuleInstantiation()
599 // 10. Perform ? ModuleDeclarationEnvironmentSetup(module). in InnerModuleInstantiation()
600 if (module->GetIsNewBcVersion()) { in InnerModuleInstantiation()
601 SourceTextModule::ModuleDeclarationArrayEnvironmentSetup(thread, module); in InnerModuleInstantiation()
603 SourceTextModule::ModuleDeclarationEnvironmentSetup(thread, module); in InnerModuleInstantiation()
606 DFSModuleInstantiation(module, stack); in InnerModuleInstantiation()
611 const JSHandle<SourceTextModule> &module) in ModuleDeclarationEnvironmentSetup() argument
613 CheckResolvedBinding(thread, module); in ModuleDeclarationEnvironmentSetup()
614 if (module->GetImportEntries().IsUndefined()) { in ModuleDeclarationEnvironmentSetup()
617 ASSERT(!SourceTextModule::IsSharedModule(module)); in ModuleDeclarationEnvironmentSetup()
618 // 2. Assert: All named exports from module are resolvable. in ModuleDeclarationEnvironmentSetup()
619 // 3. Let realm be module.[[Realm]]. in ModuleDeclarationEnvironmentSetup()
622 JSHandle<TaggedArray> importEntries(thread, module->GetImportEntries()); in ModuleDeclarationEnvironmentSetup()
626 // 6. Set module.[[Environment]] to env. in ModuleDeclarationEnvironmentSetup()
627 module->SetEnvironment(thread, map); in ModuleDeclarationEnvironmentSetup()
629 JSMutableHandle<JSTaggedValue> envRec(thread, module->GetEnvironment()); in ModuleDeclarationEnvironmentSetup()
631 // 8. For each ImportEntry Record in in module.[[ImportEntries]], do in ModuleDeclarationEnvironmentSetup()
632 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in ModuleDeclarationEnvironmentSetup()
641 // a. Let importedModule be ! HostResolveImportedModule(module, in.[[ModuleRequest]]). in ModuleDeclarationEnvironmentSetup()
643 GetRequestedModule(thread, module, requestedModules, in->GetModuleRequestIndex())); in ModuleDeclarationEnvironmentSetup()
665 … CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + in ModuleDeclarationEnvironmentSetup()
667 if (!module->GetEcmaModuleRecordNameString().empty()) { in ModuleDeclarationEnvironmentSetup()
668 … CString recordStr = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); in ModuleDeclarationEnvironmentSetup()
671 msg += "' which imported by '" + module->GetEcmaModuleFilenameString() + "'"; in ModuleDeclarationEnvironmentSetup()
676 // in.[[LocalName]], resolution.[[Module]], resolution.[[BindingName]]). in ModuleDeclarationEnvironmentSetup()
684 module->SetEnvironment(thread, envRec); in ModuleDeclarationEnvironmentSetup()
688 … const JSHandle<SourceTextModule> &module) in ModuleDeclarationArrayEnvironmentSetup() argument
691 "SourceTextModule::Instantiating:" + module->GetEcmaModuleRecordNameString()); in ModuleDeclarationArrayEnvironmentSetup()
692 …if (IsSharedModule(module) && SharedModuleManager::GetInstance()->IsInstantiatedSModule(thread, mo… in ModuleDeclarationArrayEnvironmentSetup()
695 CheckResolvedIndexBinding(thread, module); in ModuleDeclarationArrayEnvironmentSetup()
696 if (module->GetImportEntries().IsUndefined()) { in ModuleDeclarationArrayEnvironmentSetup()
701 // 2. Assert: All named exports from module are resolvable. in ModuleDeclarationArrayEnvironmentSetup()
702 // 3. Let realm be module.[[Realm]]. in ModuleDeclarationArrayEnvironmentSetup()
705 JSHandle<TaggedArray> importEntries(thread, module->GetImportEntries()); in ModuleDeclarationArrayEnvironmentSetup()
710 // 8. For each ImportEntry Record in in module.[[ImportEntries]], do in ModuleDeclarationArrayEnvironmentSetup()
711 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in ModuleDeclarationArrayEnvironmentSetup()
718 // a. Let importedModule be ! HostResolveImportedModule(module, in.[[ModuleRequest]]). in ModuleDeclarationArrayEnvironmentSetup()
720 GetRequestedModule(thread, module, requestedModules, in->GetModuleRequestIndex())); in ModuleDeclarationArrayEnvironmentSetup()
726 envRec = JSSharedModule::CloneEnvForSModule(thread, module, envRec); in ModuleDeclarationArrayEnvironmentSetup()
727 module->SetEnvironment(thread, envRec); in ModuleDeclarationArrayEnvironmentSetup()
738 … CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + in ModuleDeclarationArrayEnvironmentSetup()
740 if (!module->GetEcmaModuleRecordNameString().empty()) { in ModuleDeclarationArrayEnvironmentSetup()
742 module->GetEcmaModuleRecordNameString()); in ModuleDeclarationArrayEnvironmentSetup()
745 msg += "' which imported by '" + module->GetEcmaModuleFilenameString() + "'"; in ModuleDeclarationArrayEnvironmentSetup()
750 // in.[[LocalName]], resolution.[[Module]], resolution.[[BindingName]]). in ModuleDeclarationArrayEnvironmentSetup()
753 envRec = JSSharedModule::CloneEnvForSModule(thread, module, envRec); in ModuleDeclarationArrayEnvironmentSetup()
754 module->SetEnvironment(thread, envRec); in ModuleDeclarationArrayEnvironmentSetup()
758 … const JSHandle<SourceTextModule> &module) in GetModuleNamespace() argument
761 // 1. Assert: module is an instance of a concrete subclass of Module Record. in GetModuleNamespace()
762 // 2. Assert: module.[[Status]] is not "uninstantiated". in GetModuleNamespace()
763 ASSERT(module->GetStatus() != ModuleStatus::UNINSTANTIATED); in GetModuleNamespace()
764 // 3. Let namespace be module.[[Namespace]]. in GetModuleNamespace()
765 … JSMutableHandle<JSTaggedValue> moduleNamespace(thread, module->GetNamespace().GetWeakRawValue()); in GetModuleNamespace()
768 // a. Let exportedNames be ? module.GetExportedNames(« »). in GetModuleNamespace()
770 …CVector<std::string> exportedNames = SourceTextModule::GetExportedNames(thread, module, exportStar… in GetModuleNamespace()
776 // i. Let resolution be ? module.ResolveExport(name, « »). in GetModuleNamespace()
780 SourceTextModule::ResolveExport(thread, module, nameHandle, resolveVector); in GetModuleNamespace()
789 JSHandle<JSTaggedValue> moduleTagged = JSHandle<JSTaggedValue>::Cast(module); in GetModuleNamespace()
797 void SourceTextModule::HandleEvaluateResult(JSThread *thread, JSHandle<SourceTextModule> &module, in HandleEvaluateResult() argument
807 // b. Assert: module.[[Status]] is "evaluated" and module.[[EvaluationError]] is result. in HandleEvaluateResult()
822 // a. Assert: module.[[Status]] is either EVALUATING-ASYNC or EVALUATED. in HandleEvaluateResult()
823 status = module->GetStatus(); in HandleEvaluateResult()
825 // b. Assert: module.[[EvaluationError]] is EMPTY. in HandleEvaluateResult()
827 // c. If module.[[AsyncEvaluation]] is false, then in HandleEvaluateResult()
828 // i. Assert: module.[[Status]] is EVALUATED || ERRORED. in HandleEvaluateResult()
830 if (!module->IsAsyncEvaluating()) { in HandleEvaluateResult()
841 // 1. Let module be this Source Text Module Record. in Evaluate()
842 // 2. Assert: module.[[Status]] is one of LINKED, EVALUATING-ASYNC, or EVALUATED. in Evaluate()
843 JSMutableHandle<SourceTextModule> module(thread, moduleHdl); in Evaluate() local
844 ModuleStatus status = module->GetStatus(); in Evaluate()
847 …// 3. If module.[[Status]] is either EVALUATING-ASYNC or EVALUATED, set module to module.[[CycleRo… in Evaluate()
849 module.Update(module->GetCycleRoot()); in Evaluate()
851 // 4. If module.[[TopLevelCapability]] is not EMPTY, then in Evaluate()
852 // a. Return module.[[TopLevelCapability]].[[Promise]]. in Evaluate()
862 // 7. Set module.[[TopLevelCapability]] to capability. in Evaluate()
863 if (!SourceTextModule::IsSharedModule(module)) { in Evaluate()
864 module->SetTopLevelCapability(thread, capability); in Evaluate()
867 // 8. Let result be Completion(InnerModuleEvaluation(module, stack, 0)). in Evaluate()
868 …SourceTextModule::InnerModuleEvaluation(thread, module, stack, errorStack, 0, buffer, size, execut… in Evaluate()
869 HandleEvaluateResult(thread, module, capability, stack, errorStack); in Evaluate()
875 moduleLogger->InsertEntryPointModule(module); in Evaluate()
881 …SourceTextModule::EvaluateForConcurrent(JSThread *thread, const JSHandle<SourceTextModule> &module, in EvaluateForConcurrent() argument
884 // 1. Let module be this Source Text Module Record. in EvaluateForConcurrent()
885 // 2. Assert: module.[[Status]] is "instantiated" or "evaluated". in EvaluateForConcurrent()
886 [[maybe_unused]] ModuleStatus status = module->GetStatus(); in EvaluateForConcurrent()
888 // 4. Let result be InnerModuleEvaluation(module, stack, 0) in EvaluateForConcurrent()
889 JSHandle<ModuleRecord> moduleRecord = JSHandle<ModuleRecord>::Cast(module); in EvaluateForConcurrent()
919 JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord); in InnerModuleEvaluationUnsafe() local
920 ModuleStatus status = module->GetStatus(); in InnerModuleEvaluationUnsafe()
923 ModuleMessageHelper::PrintAndThrowError(thread, module); in InnerModuleEvaluationUnsafe()
933 module->SetStatus(ModuleStatus::EVALUATING); in InnerModuleEvaluationUnsafe()
934 module->SetDFSIndex(index); in InnerModuleEvaluationUnsafe()
935 module->SetDFSAncestorIndex(index); in InnerModuleEvaluationUnsafe()
936 module->SetPendingAsyncDependencies(0); in InnerModuleEvaluationUnsafe()
938 stack.emplace_back(module); in InnerModuleEvaluationUnsafe()
941 if (!module->GetRequestedModules().IsUndefined()) { in InnerModuleEvaluationUnsafe()
942 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in InnerModuleEvaluationUnsafe()
947 if (module->IsLazyImportModule(idx)) { in InnerModuleEvaluationUnsafe()
951 GetRequestedModule(thread, module, requestedModules, idx)); in InnerModuleEvaluationUnsafe()
954 moduleLogger->InsertParentModule(module, requiredModule); in InnerModuleEvaluationUnsafe()
980 … int dfsAncIdx = std::min(module->GetDFSAncestorIndex(), requiredModule->GetDFSAncestorIndex()); in InnerModuleEvaluationUnsafe()
981 module->SetDFSAncestorIndex(dfsAncIdx); in InnerModuleEvaluationUnsafe()
987 errorStack.emplace_back(module); in InnerModuleEvaluationUnsafe()
988 SetExceptionToModule(thread, module, requiredModule->GetException()); in InnerModuleEvaluationUnsafe()
989 ModuleMessageHelper::PrintAndThrowError(thread, module); in InnerModuleEvaluationUnsafe()
995 module->SetPendingAsyncDependencies(module->GetPendingAsyncDependencies() + 1); in InnerModuleEvaluationUnsafe()
996 AddAsyncParentModule(thread, requiredModule, module); in InnerModuleEvaluationUnsafe()
1000 int pendingAsyncDependencies = module->GetPendingAsyncDependencies(); in InnerModuleEvaluationUnsafe()
1001 bool hasTLA = module->GetHasTLA(); in InnerModuleEvaluationUnsafe()
1002 // 12. If module.[[PendingAsyncDependencies]] > 0 or module.[[HasTLA]] is true, then in InnerModuleEvaluationUnsafe()
1004 // a. Assert: module.[[AsyncEvaluation]] is false and was never previously set to true. in InnerModuleEvaluationUnsafe()
1005 ASSERT(module->GetAsyncEvaluatingOrdinal() == NOT_ASYNC_EVALUATED); in InnerModuleEvaluationUnsafe()
1006 // b. Set module.[[AsyncEvaluation]] to true. in InnerModuleEvaluationUnsafe()
1008 module->SetAsyncEvaluatingOrdinal(moduleManager->NextModuleAsyncEvaluatingOrdinal()); in InnerModuleEvaluationUnsafe()
1009 // d. If module.[[PendingAsyncDependencies]] = 0, perform ExecuteAsyncModule(module). in InnerModuleEvaluationUnsafe()
1011 SourceTextModule::ExecuteAsyncModule(thread, module, buffer, size, executeType); in InnerModuleEvaluationUnsafe()
1015 // 13. Else, Perform ? module.ExecuteModule(). in InnerModuleEvaluationUnsafe()
1016 SourceTextModule::ModuleExecution(thread, module, buffer, size, executeType); in InnerModuleEvaluationUnsafe()
1019 // 14. Assert: module occurs exactly once in stack. in InnerModuleEvaluationUnsafe()
1020 // 15. Assert: module.[[DFSAncestorIndex]] ≤ module.[[DFSIndex]]. in InnerModuleEvaluationUnsafe()
1021 int dfsAncIdx = module->GetDFSAncestorIndex(); in InnerModuleEvaluationUnsafe()
1022 int dfsIdx = module->GetDFSIndex(); in InnerModuleEvaluationUnsafe()
1024 // 16. If module.[[DFSAncestorIndex]] = module.[[DFSIndex]], then in InnerModuleEvaluationUnsafe()
1034 // iii. Assert: requiredModule is a Cyclic Module Record. in InnerModuleEvaluationUnsafe()
1042 // vi. If requiredModule and module are the same Module Record, set done to true. in InnerModuleEvaluationUnsafe()
1043 … if (JSTaggedValue::SameValue(module.GetTaggedValue(), requiredModule.GetTaggedValue())) { in InnerModuleEvaluationUnsafe()
1046 // vii. Set requiredModule.[[CycleRoot]] to module. in InnerModuleEvaluationUnsafe()
1048 requiredModule->SetCycleRoot(thread, module); in InnerModuleEvaluationUnsafe()
1056 const JSHandle<SourceTextModule> &module) in IsEvaluatedModule() argument
1059 return GetModuleEvaluatingType(thread, stateVisit, module) >= ModuleStatus::EVALUATED; in IsEvaluatedModule()
1063 const JSHandle<SourceTextModule> &module) in GetModuleEvaluatingType() argument
1066 return module->GetStatus(); in GetModuleEvaluatingType()
1069 …SourceTextModule::InnerModuleEvaluation(JSThread *thread, const JSHandle<SourceTextModule> &module, in InnerModuleEvaluation() argument
1074 bool isShared = IsSharedModule(module); in InnerModuleEvaluation()
1075 JSHandle<ModuleRecord> moduleRecord = JSHandle<ModuleRecord>::Cast(module); in InnerModuleEvaluation()
1080 …ateVisit &stateVisit = SharedModuleManager::GetInstance()->findModuleMutexWithLock(thread, module); in InnerModuleEvaluation()
1081 ModuleStatus status = module->GetStatus(); in InnerModuleEvaluation()
1087 ModuleMessageHelper::PrintAndThrowError(thread, module); in InnerModuleEvaluation()
1104 …rceTextModule::HandleConcurrentEvaluateResult(JSThread *thread, JSHandle<SourceTextModule> &module, in HandleConcurrentEvaluateResult() argument
1112 // b. Assert: module.[[Status]] is "evaluated" and module.[[EvaluationError]] is result. in HandleConcurrentEvaluateResult()
1118 // a. Assert: module.[[Status]] is either EVALUATING-ASYNC or EVALUATED. in HandleConcurrentEvaluateResult()
1119 status = module->GetStatus(); in HandleConcurrentEvaluateResult()
1123 // c. If module.[[AsyncEvaluation]] is false, then in HandleConcurrentEvaluateResult()
1124 // i. Assert: module.[[Status]] is EVALUATED || ERRORED. in HandleConcurrentEvaluateResult()
1125 if (!module->IsAsyncEvaluating()) { in HandleConcurrentEvaluateResult()
1135 JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord); in ModuleEvaluation() local
1136 if (!module->GetRequestedModules().IsUndefined()) { in ModuleEvaluation()
1137 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in ModuleEvaluation()
1143 // skip the unused module in ModuleEvaluation()
1147 GetRequestedModule(thread, module, requestedModules, idx)); in ModuleEvaluation()
1171 …const JSHandle<SourceTextModule> &module, const void *buffer, size_t size, const ExecuteTypes &exe… in ModuleExecution() argument
1175 moduleFilenameStr = thread->GetEcmaVM()->GetQuickFixManager()->GetBaseFileName(module); in ModuleExecution()
1177 moduleFilenameStr = module->GetEcmaModuleFilenameString(); in ModuleExecution()
1180 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in ModuleExecution()
1202 void SourceTextModule::AddImportEntry(JSThread *thread, const JSHandle<SourceTextModule> &module, in AddImportEntry() argument
1206 JSTaggedValue importEntries = module->GetImportEntries(); in AddImportEntry()
1210 module->SetImportEntries(thread, array); in AddImportEntry()
1216 module->SetImportEntries(thread, entries); in AddImportEntry()
1223 …d SourceTextModule::AddLocalExportEntry(JSThread *thread, const JSHandle<SourceTextModule> &module, in AddLocalExportEntry() argument
1227 JSTaggedValue localExportEntries = module->GetLocalExportEntries(); in AddLocalExportEntry()
1231 module->SetLocalExportEntries(thread, array); in AddLocalExportEntry()
1238 …ourceTextModule::AddIndirectExportEntry(JSThread *thread, const JSHandle<SourceTextModule> &module, in AddIndirectExportEntry() argument
1243 JSTaggedValue indirectExportEntries = module->GetIndirectExportEntries(); in AddIndirectExportEntry()
1247 module->SetIndirectExportEntries(thread, array); in AddIndirectExportEntry()
1254 …id SourceTextModule::AddStarExportEntry(JSThread *thread, const JSHandle<SourceTextModule> &module, in AddStarExportEntry() argument
1258 JSTaggedValue starExportEntries = module->GetStarExportEntries(); in AddStarExportEntry()
1262 module->SetStarExportEntries(thread, array); in AddStarExportEntry()
1273 // if module is Errored, throw origin jsError in GetModuleValue()
1294 // if module is Errored, throw origin jsError in GetModuleValue()
1373 void SourceTextModule::StoreModuleValue(JSThread *thread, const JSHandle<SourceTextModule> &module,… in StoreModuleValue() argument
1376 if (UNLIKELY(IsSharedModule(module)) && !value->IsSharedType()) { in StoreModuleValue()
1377 CString msg = "Export non-shared object from shared-module, module name is :" + in StoreModuleValue()
1378 module->GetEcmaModuleRecordNameString(); in StoreModuleValue()
1381 JSTaggedValue localExportEntries = module->GetLocalExportEntries(); in StoreModuleValue()
1384 JSHandle<JSTaggedValue> data(thread, module->GetNameDictionary()); in StoreModuleValue()
1389 if (SourceTextModule::IsSharedModule(module)) { in StoreModuleValue()
1395 module->SetNameDictionary(thread, data); in StoreModuleValue()
1402 // discard instructions won't consider shared-module.
1403 void SourceTextModule::StoreModuleValue(JSThread *thread, const JSHandle<SourceTextModule> &module, in StoreModuleValue() argument
1406 if (UNLIKELY(IsSharedModule(module)) && !value->IsSharedType()) { in StoreModuleValue()
1407 CString msg = "Export non-shared object from shared-module, module name is :" + in StoreModuleValue()
1408 module->GetEcmaModuleRecordNameString(); in StoreModuleValue()
1411 JSMutableHandle<JSTaggedValue> data(thread, module->GetNameDictionary()); in StoreModuleValue()
1418 module->SetNameDictionary(thread, data); in StoreModuleValue()
1475 … // 2. If resolution.[[Module]] and starResolution.[[Module]] are not the same Module Record or in GetStarResolution()
1509 // a. Assert: module provides the direct binding for this export. in AddExportName()
1520 … const JSHandle<SourceTextModule> &module) in ResolveElementOfObject() argument
1525 return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, idx)); in ResolveElementOfObject()
1533 … const JSHandle<SourceTextModule> &module) in ResolveLocalExport() argument
1544 // if module is type of CommonJS or native, export first, check after execution. in ResolveLocalExport()
1545 auto moduleType = module->GetTypes(); in ResolveLocalExport()
1547 … return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedBindingRecord(module, exportName)); in ResolveLocalExport()
1551 // Adapter new module in ResolveLocalExport()
1552 if (module->GetIsNewBcVersion()) { in ResolveLocalExport()
1553 return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, in ResolveLocalExport()
1556 // i. Assert: module provides the direct binding for this export. in ResolveLocalExport()
1557 … // ii. Return ResolvedBinding Record { [[Module]]: module, [[BindingName]]: e.[[LocalName]] }. in ResolveLocalExport()
1559 … return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedBindingRecord(module, localName)); in ResolveLocalExport()
1568 … const JSHandle<SourceTextModule> &module, in ResolveIndirectExport() argument
1576 JSHandle<TaggedArray> requestedModules(thread, module->GetRequestedModules()); in ResolveIndirectExport()
1583 // i. Assert: module imports a specific binding for this export. in ResolveIndirectExport()
1584 // ii. Let importedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). in ResolveIndirectExport()
1586 GetRequestedModule(thread, module, requestedModules, ee->GetModuleRequestIndex())); in ResolveIndirectExport()
1596 … SourceTextModule::CheckResolvedBinding(JSThread *thread, const JSHandle<SourceTextModule> &module) in CheckResolvedBinding() argument
1599 // 1. For each ExportEntry Record e in module.[[IndirectExportEntries]], do in CheckResolvedBinding()
1600 JSTaggedValue indirectExportEntriesTv = module->GetIndirectExportEntries(); in CheckResolvedBinding()
1611 // a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « »). in CheckResolvedBinding()
1615 SourceTextModule::ResolveExport(thread, module, exportName, resolveVector); in CheckResolvedBinding()
1619 … TaggedArray *requestArray = TaggedArray::Cast(module->GetModuleRequests().GetTaggedObject()); in CheckResolvedBinding()
1622 … CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + in CheckResolvedBinding()
1624 if (!module->GetEcmaModuleRecordNameString().empty()) { in CheckResolvedBinding()
1625 … CString recordStr = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); in CheckResolvedBinding()
1628 msg += "' which exported by '" + module->GetEcmaModuleFilenameString() + "'"; in CheckResolvedBinding()
1637 …ceTextModule::CheckResolvedIndexBinding(JSThread *thread, const JSHandle<SourceTextModule> &module) in CheckResolvedIndexBinding() argument
1640 // 1. For each ExportEntry Record e in module.[[IndirectExportEntries]], do in CheckResolvedIndexBinding()
1641 JSTaggedValue indirectExportEntriesTv = module->GetIndirectExportEntries(); in CheckResolvedIndexBinding()
1652 // a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « »). in CheckResolvedIndexBinding()
1656 SourceTextModule::ResolveExport(thread, module, exportName, resolveVector); in CheckResolvedIndexBinding()
1660 … TaggedArray *requestArray = TaggedArray::Cast(module->GetModuleRequests().GetTaggedObject()); in CheckResolvedIndexBinding()
1663 … CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + in CheckResolvedIndexBinding()
1665 if (!module->GetEcmaModuleRecordNameString().empty()) { in CheckResolvedIndexBinding()
1666 … CString record = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); in CheckResolvedIndexBinding()
1669 msg += "' which exported by '" + module->GetEcmaModuleFilenameString() + "'"; in CheckResolvedIndexBinding()
1678 SourceTextModule *module = SourceTextModule::Cast(currentModule.GetTaggedObject()); in GetModuleName() local
1679 CString recordName = module->GetEcmaModuleRecordNameString(); in GetModuleName()
1681 recordName = module->GetEcmaModuleFilenameString(); in GetModuleName()
1696 void SourceTextModule::AddAsyncParentModule(JSThread *thread, JSHandle<SourceTextModule> &module, in AddAsyncParentModule() argument
1700 JSTaggedValue asyncParentModules = module->GetAsyncParentModules(); in AddAsyncParentModule()
1704 module->SetAsyncParentModules(thread, array); in AddAsyncParentModule()
1710 module->SetAsyncParentModules(thread, array); in AddAsyncParentModule()
1714 …id SourceTextModule::ExecuteAsyncModule(JSThread *thread, const JSHandle<SourceTextModule> &module, in ExecuteAsyncModule() argument
1717 // 1. Assert: module.[[Status]] is either EVALUATING or EVALUATING-ASYNC. in ExecuteAsyncModule()
1718 …ASSERT(module->GetStatus() == ModuleStatus::EVALUATING || module->GetStatus() == ModuleStatus::EVA… in ExecuteAsyncModule()
1719 // 2. Assert: module.[[HasTLA]] is true. in ExecuteAsyncModule()
1720 ASSERT(module->GetHasTLA()); in ExecuteAsyncModule()
1721 CString moduleFilenameStr = module->GetEcmaModuleFilenameString(); in ExecuteAsyncModule()
1724 CString moduleRecordName = module->GetEcmaModuleRecordNameString(); in ExecuteAsyncModule()
1747 …// 4. Let fulfilledClosure be a new Abstract Closure with no parameters that captures module and p… in ExecuteAsyncModule()
1749 // a. Perform AsyncModuleExecutionFulfilled(module). in ExecuteAsyncModule()
1752 …rejectedClosure be a new Abstract Closure with parameters (error) that captures module and performs in ExecuteAsyncModule()
1754 // a. Perform AsyncModuleExecutionRejected(module, error). in ExecuteAsyncModule()
1763 onFulfilled->SetModule(thread, module); in ExecuteAsyncModule()
1767 onRejected->SetModule(thread, module); in ExecuteAsyncModule()
1776 …rceTextModule::GatherAvailableAncestors(JSThread *thread, const JSHandle<SourceTextModule> &module, in GatherAvailableAncestors() argument
1780 JSTaggedValue asyncParentModulesValue = module->GetAsyncParentModules(); in GatherAvailableAncestors()
1787 // 1. For each Cyclic Module Record m of module.[[AsyncParentModules]], do in GatherAvailableAncestors()
1816 …xtModule::AsyncModuleExecutionFulfilled(JSThread *thread, const JSHandle<SourceTextModule> &module) in AsyncModuleExecutionFulfilled() argument
1818 // 1. If module.[[Status]] is EVALUATED, then in AsyncModuleExecutionFulfilled()
1819 // a. Assert: module.[[EvaluationError]] is not EMPTY. in AsyncModuleExecutionFulfilled()
1821 if (module->GetStatus() == ModuleStatus::ERRORED) { in AsyncModuleExecutionFulfilled()
1822 ASSERT(!module->GetException().IsHole()); in AsyncModuleExecutionFulfilled()
1825 // 2. Assert: module.[[Status]] is EVALUATING-ASYNC. in AsyncModuleExecutionFulfilled()
1826 ASSERT(module->GetStatus() == ModuleStatus::EVALUATING_ASYNC); in AsyncModuleExecutionFulfilled()
1827 // 3. Assert: module.[[AsyncEvaluation]] is true. in AsyncModuleExecutionFulfilled()
1828 ASSERT(module->IsAsyncEvaluating()); in AsyncModuleExecutionFulfilled()
1829 // 4. Assert: module.[[EvaluationError]] is EMPTY. in AsyncModuleExecutionFulfilled()
1830 // 5. Set module.[[AsyncEvaluation]] to false. in AsyncModuleExecutionFulfilled()
1831 module->SetAsyncEvaluatingOrdinal(ASYNC_EVALUATE_DID_FINISH); in AsyncModuleExecutionFulfilled()
1832 // 6. Set module.[[Status]] to EVALUATED. in AsyncModuleExecutionFulfilled()
1833 module->SetStatus(ModuleStatus::EVALUATED); in AsyncModuleExecutionFulfilled()
1834 // 7. If module.[[TopLevelCapability]] is not EMPTY, then in AsyncModuleExecutionFulfilled()
1835 // a. Assert: module.[[CycleRoot]] is module. in AsyncModuleExecutionFulfilled()
1836 // b. Perform ! Call(module.[[TopLevelCapability]].[[Resolve]], undefined, « undefined »). in AsyncModuleExecutionFulfilled()
1838 JSTaggedValue topLevelCapabilityValue = module->GetTopLevelCapability(); in AsyncModuleExecutionFulfilled()
1840 ASSERT(JSTaggedValue::SameValue(module->GetCycleRoot(), module.GetTaggedValue())); in AsyncModuleExecutionFulfilled()
1853 // 9. Perform GatherAvailableAncestors(module, execList). in AsyncModuleExecutionFulfilled()
1856 GatherAvailableAncestors(thread, module, execList); in AsyncModuleExecutionFulfilled()
1859 // 12. For each Cyclic Module Record m of sortedExecList, do in AsyncModuleExecutionFulfilled()
1864 ASSERT(module->GetStatus() == ModuleStatus::ERRORED); in AsyncModuleExecutionFulfilled()
1902 …extModule::AsyncModuleExecutionRejected(JSThread *thread, const JSHandle<SourceTextModule> &module, in AsyncModuleExecutionRejected() argument
1905 // 1. If module.[[Status]] is EVALUATED, then in AsyncModuleExecutionRejected()
1906 // a. Assert: module.[[EvaluationError]] is not EMPTY. in AsyncModuleExecutionRejected()
1908 if (module->GetStatus() == ModuleStatus::ERRORED) { in AsyncModuleExecutionRejected()
1909 ASSERT(!module->GetException().IsHole()); in AsyncModuleExecutionRejected()
1912 // 2. Assert: module.[[Status]] is EVALUATING-ASYNC. in AsyncModuleExecutionRejected()
1913 ASSERT(module->GetStatus() == ModuleStatus::EVALUATING_ASYNC); in AsyncModuleExecutionRejected()
1914 // 3. Assert: module.[[AsyncEvaluation]] is true. in AsyncModuleExecutionRejected()
1915 ASSERT(module->IsAsyncEvaluating()); in AsyncModuleExecutionRejected()
1916 // 4. Assert: module.[[EvaluationError]] is EMPTY. in AsyncModuleExecutionRejected()
1917 ASSERT(module->GetException().IsHole()); in AsyncModuleExecutionRejected()
1918 // 5. Set module.[[EvaluationError]] to ThrowCompletion(error). in AsyncModuleExecutionRejected()
1919 module->SetStatus(ModuleStatus::ERRORED); in AsyncModuleExecutionRejected()
1920 // 6. Set module.[[Status]] to EVALUATED. in AsyncModuleExecutionRejected()
1921 module->SetException(thread, error); in AsyncModuleExecutionRejected()
1922 // 7. For each Cyclic Module Record m of module.[[AsyncParentModules]], do in AsyncModuleExecutionRejected()
1925 JSTaggedValue asyncParentModulesValue = module->GetAsyncParentModules(); in AsyncModuleExecutionRejected()
1936 // 8. If module.[[TopLevelCapability]] is not EMPTY, then in AsyncModuleExecutionRejected()
1937 // a. Assert: module.[[CycleRoot]] is module. in AsyncModuleExecutionRejected()
1938 // b. Perform ! Call(module.[[TopLevelCapability]].[[Reject]], undefined, « error »). in AsyncModuleExecutionRejected()
1939 JSTaggedValue topLevelCapabilityValue = module->GetTopLevelCapability(); in AsyncModuleExecutionRejected()
1946 ASSERT(JSTaggedValue::SameValue(module->GetCycleRoot(), module.GetTaggedValue())); in AsyncModuleExecutionRejected()
1966 JSHandle<SourceTextModule> module(thread, fulfilledFunc->GetModule()); in AsyncModuleFulfilledFunc() local
1967 AsyncModuleExecutionFulfilled(thread, module); in AsyncModuleFulfilledFunc()
1979 JSHandle<SourceTextModule> module(thread, rejectedFunc->GetModule()); in AsyncModuleRejectedFunc() local
1981 AsyncModuleExecutionRejected(thread, module, value.GetTaggedValue()); in AsyncModuleRejectedFunc()
2003 const JSHandle<SourceTextModule> &module, in SearchCircularImport() argument
2007 if (module->GetModuleRequests().IsUndefined()) { in SearchCircularImport()
2011 JSHandle<TaggedArray> moduleRequests(thread, module->GetModuleRequests()); in SearchCircularImport()
2018 ModuleResolver::HostResolveImportedModule(thread, module, required))); in SearchCircularImport()
2060 // This function for module which execution doesn't through SourceTextModule::Evaluate
2061 void SourceTextModule::RecordEvaluatedOrError(JSThread *thread, JSHandle<SourceTextModule> module) in RecordEvaluatedOrError() argument
2064 module->SetStatus(ModuleStatus::ERRORED); in RecordEvaluatedOrError()
2067 LOG_FULL(INFO) << "Error module: " << module->GetEcmaModuleRecordNameString(); in RecordEvaluatedOrError()
2069 return SetExceptionToModule(thread, module, thread->GetException()); in RecordEvaluatedOrError()
2071 module->SetStatus(ModuleStatus::EVALUATED); in RecordEvaluatedOrError()
2074 void SourceTextModule::SetExceptionToModule(JSThread *thread, JSHandle<SourceTextModule> module, in SetExceptionToModule() argument
2077 if (!IsSharedModule(module)) { in SetExceptionToModule()
2078 module->SetException(thread, exception); in SetExceptionToModule()
2087 // process error message for share module in SetExceptionToModule()
2093 …CString errMsg = "Error store in module " + module->GetEcmaModuleRecordNameString() + ":\n" + msg + in SetExceptionToModule()
2103 module->SetException(thread, ecmaErrMsg.GetTaggedValue()); in SetExceptionToModule()
2111 LOG_FULL(ERROR) << "Error found in module:" << GetEcmaModuleRecordNameString(); in CheckAndThrowModuleError()
2129 // a. For each module m in stack, do in HandleEvaluateException()
2140 LOG_FULL(INFO) << "Error module: " << mm->GetEcmaModuleRecordNameString(); in HandleEvaluateException()
2155 LOG_FULL(INFO) << "Error module: " << mm->GetEcmaModuleRecordNameString(); in HandleErrorStack()
2161 … const JSHandle<SourceTextModule> module, in GetRequestedModule() argument
2165 // if module is not shared or circularImport, requestedModules may not be modules. in GetRequestedModule()
2173 // resolve or find module by request string. in GetRequestedModule()
2174 JSHandle<TaggedArray> moduleRequests(thread, module->GetModuleRequests()); in GetRequestedModule()
2176 return ModuleResolver::HostResolveImportedModule(thread, module, moduleRequest); in GetRequestedModule()