mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2025-02-25 23:08:22 +00:00
!6571 Fix of import function failed across thread under certain circumstances
Merge pull request !6571 from DaiHN/sendable_module_fix
This commit is contained in:
commit
d0896b61f3
@ -244,6 +244,19 @@ bool JSPandaFile::CheckAndGetRecordInfo(const CString &recordName, JSRecordInfo
|
||||
return false;
|
||||
}
|
||||
|
||||
const JSRecordInfo &JSPandaFile::GetRecordInfo(const CString &recordName)
|
||||
{
|
||||
if (IsBundlePack()) {
|
||||
return jsRecordInfo_.begin()->second;
|
||||
}
|
||||
auto info = jsRecordInfo_.find(recordName);
|
||||
if (info != jsRecordInfo_.end()) {
|
||||
return info->second;
|
||||
}
|
||||
LOG_FULL(FATAL) << "Get record info failed";
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
CString JSPandaFile::GetEntryPoint(const CString &recordName) const
|
||||
{
|
||||
CString entryPoint;
|
||||
|
@ -290,6 +290,8 @@ public:
|
||||
|
||||
bool CheckAndGetRecordInfo(const CString &recordName, JSRecordInfo &recordInfo) const;
|
||||
|
||||
const JSRecordInfo &GetRecordInfo(const CString &recordName);
|
||||
|
||||
CString GetJsonStringId(const JSRecordInfo &jsRecordInfo) const;
|
||||
|
||||
bool PUBLIC_API IsModule(const JSRecordInfo &jsRecordInfo) const
|
||||
|
@ -369,10 +369,28 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteModuleBufferSecure(JST
|
||||
return CommonExecuteBuffer(thread, name, entry, jsPandaFile.get());
|
||||
}
|
||||
|
||||
Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteSpecialModule(JSThread *thread, const CString &recordName,
|
||||
const CString &filename, const JSPandaFile *jsPandaFile, const JSRecordInfo &recordInfo)
|
||||
{
|
||||
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
|
||||
|
||||
if (jsPandaFile->IsCjs(recordInfo)) {
|
||||
moduleManager->ExecuteCjsModule(thread, recordName.c_str(), jsPandaFile);
|
||||
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, Unexpected(false));
|
||||
return JSTaggedValue::Undefined();
|
||||
}
|
||||
if (jsPandaFile->IsJson(recordInfo)) {
|
||||
moduleManager->ExecuteJsonModule(thread, recordName.c_str(), filename, jsPandaFile);
|
||||
return JSTaggedValue::Undefined();
|
||||
}
|
||||
UNREACHABLE();
|
||||
LOG_FULL(FATAL) << "this branch is unreachable";
|
||||
}
|
||||
|
||||
// RecordName is the ohmurl-path of js files.
|
||||
// The first js file waiting be executed should use ES Module format.
|
||||
// The first js file executed could be json, cjs, native so or esm.
|
||||
Expected<JSTaggedValue, bool> JSPandaFileExecutor::LazyExecuteModule(
|
||||
JSThread *thread, const CString &recordName, const CString &filename, bool isMergedAbc)
|
||||
JSThread *thread, CString &recordName, const CString &filename, bool isMergedAbc)
|
||||
{
|
||||
LOG_FULL(INFO) << "recordName : " << recordName << ", in abc : " << filename;
|
||||
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "JSPandaFileExecutor::LazyExecuteModule");
|
||||
@ -382,17 +400,25 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::LazyExecuteModule(
|
||||
LOG_FULL(FATAL) << "Load file with filename '" << filename << "' failed, ";
|
||||
}
|
||||
|
||||
if (isMergedAbc) {
|
||||
if (!jsPandaFile->HasRecord(recordName)) {
|
||||
CString msg = "cannot find record '" + recordName + "', in lazy load abc: " + filename;
|
||||
THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), Unexpected(false));
|
||||
}
|
||||
// [[todo::DaiHN]]check is es module
|
||||
// resolve native module
|
||||
auto [isNative, moduleType] = SourceTextModule::CheckNativeModule(recordName);
|
||||
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
|
||||
if (isNative) {
|
||||
moduleManager->ExecuteNativeModule(thread, recordName.c_str());
|
||||
return JSTaggedValue::Undefined();
|
||||
}
|
||||
|
||||
if (isMergedAbc && !jsPandaFile->HasRecord(recordName)) {
|
||||
CString msg = "cannot find record '" + recordName + "', in lazy load abc: " + filename;
|
||||
THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), Unexpected(false));
|
||||
}
|
||||
|
||||
const JSRecordInfo &recordInfo = jsPandaFile->GetRecordInfo(recordName);
|
||||
if (!jsPandaFile->IsModule(recordInfo)) {
|
||||
return JSPandaFileExecutor::ExecuteSpecialModule(thread, recordName, filename, jsPandaFile.get(), recordInfo);
|
||||
}
|
||||
[[maybe_unused]] EcmaHandleScope scope(thread);
|
||||
// The first js file should execute at current vm.
|
||||
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
|
||||
JSHandle<JSTaggedValue> moduleRecord(thread->GlobalConstants()->GetHandledUndefined());
|
||||
if (isMergedAbc) {
|
||||
moduleRecord = moduleManager->HostResolveImportedModuleWithMerge(filename, recordName);
|
||||
|
@ -38,6 +38,11 @@ public:
|
||||
static Expected<JSTaggedValue, bool> Execute(JSThread *thread, const JSPandaFile *jsPandaFile,
|
||||
std::string_view entryPoint, bool executeFromJob = false);
|
||||
static void BindPandaFilesForAot(EcmaVM *vm, JSPandaFile *jsPandaFile);
|
||||
static Expected<JSTaggedValue, bool> ExecuteSpecialModule(JSThread *thread, const CString &recordName,
|
||||
const CString &filename, const JSPandaFile *jsPandaFile,
|
||||
const JSRecordInfo &recordInfo);
|
||||
static Expected<JSTaggedValue, bool> LazyExecuteModule(JSThread *thread, CString &recordName,
|
||||
const CString &filename, bool isMergedAbc);
|
||||
// Execute from secure mem
|
||||
static Expected<JSTaggedValue, bool> ExecuteFromBufferSecure(JSThread *thread, uint8_t *buffer, size_t size,
|
||||
std::string_view entryPoint,
|
||||
@ -47,8 +52,6 @@ public:
|
||||
bool needUpdate = false);
|
||||
static Expected<JSTaggedValue, bool> CommonExecuteBuffer(JSThread *thread, const CString &filename,
|
||||
const CString &entry, const JSPandaFile *jsPandaFile);
|
||||
static Expected<JSTaggedValue, bool> LazyExecuteModule(
|
||||
JSThread *thread, const CString &recordName, const CString &filename, bool isMergedAbc);
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
#endif // ECMASCRIPT_JSPANDAFILE_JS_PANDAFILE_EXECUTOR_H
|
||||
|
@ -219,7 +219,7 @@ JSTaggedValue ModuleManager::GetNativeModuleValue(JSThread *thread, JSTaggedValu
|
||||
ConvertToString(nativeModuleName.GetTaggedValue()) + " failed";
|
||||
return nativeExports.GetTaggedValue();
|
||||
}
|
||||
return GetValueFromExportObject(nativeExports, binding->GetIndex());
|
||||
return SourceTextModule::GetValueFromExportObject(thread, nativeExports, binding->GetIndex());
|
||||
}
|
||||
|
||||
JSTaggedValue ModuleManager::GetCJSModuleValue(JSThread *thread, JSTaggedValue currentModule,
|
||||
@ -241,31 +241,7 @@ JSTaggedValue ModuleManager::GetCJSModuleValue(JSThread *thread, JSTaggedValue c
|
||||
}
|
||||
return cjsExports.GetTaggedValue();
|
||||
}
|
||||
return GetValueFromExportObject(cjsExports, binding->GetIndex());
|
||||
}
|
||||
|
||||
JSTaggedValue ModuleManager::GetValueFromExportObject(JSHandle<JSTaggedValue> &exportObject, int32_t index)
|
||||
{
|
||||
if (index == SourceTextModule::UNDEFINED_INDEX) {
|
||||
return exportObject.GetTaggedValue();
|
||||
}
|
||||
JSTaggedValue value = JSTaggedValue::Hole();
|
||||
JSObject *obj = JSObject::Cast(exportObject.GetTaggedValue());
|
||||
TaggedArray *properties = TaggedArray::Cast(obj->GetProperties().GetTaggedObject());
|
||||
if (!properties->IsDictionaryMode()) {
|
||||
JSHClass *jsHclass = obj->GetJSHClass();
|
||||
LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject());
|
||||
PropertyAttributes attr = layoutInfo->GetAttr(index);
|
||||
value = obj->GetProperty(jsHclass, attr);
|
||||
} else {
|
||||
NameDictionary *dict = NameDictionary::Cast(properties);
|
||||
value = dict->GetValue(index);
|
||||
}
|
||||
if (UNLIKELY(value.IsAccessor())) {
|
||||
return FastRuntimeStub::CallGetter(vm_->GetJSThread(), JSTaggedValue(obj), JSTaggedValue(obj), value);
|
||||
}
|
||||
ASSERT(!value.IsAccessor());
|
||||
return value;
|
||||
return SourceTextModule::GetValueFromExportObject(thread, cjsExports, binding->GetIndex());
|
||||
}
|
||||
|
||||
void ModuleManager::StoreModuleValue(int32_t index, JSTaggedValue value)
|
||||
@ -425,6 +401,22 @@ bool ModuleManager::IsImportedModuleLoaded(JSTaggedValue referencing)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModuleManager::IsEvaluatedModule(JSTaggedValue referencing)
|
||||
{
|
||||
NameDictionary *dict = NameDictionary::Cast(resolvedModules_.GetTaggedObject());
|
||||
|
||||
int entry = dict->FindEntry(referencing);
|
||||
if (entry == -1) {
|
||||
return false;
|
||||
}
|
||||
JSTaggedValue result = dict->GetValue(entry);
|
||||
if (SourceTextModule::Cast(result.GetTaggedObject())->GetStatus() ==
|
||||
ModuleStatus::EVALUATED) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ModuleManager::SkipDefaultBundleFile(const CString &moduleFileName) const
|
||||
{
|
||||
// relative file path like "../../xxxx" can't be loaded rightly in aot compilation phase
|
||||
@ -801,15 +793,24 @@ JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModule(const JSPandaFi
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> ModuleManager::LoadNativeModule(JSThread *thread, const std::string &key)
|
||||
{
|
||||
JSHandle<SourceTextModule> ecmaModule = JSHandle<SourceTextModule>::Cast(ExecuteNativeModule(thread, key));
|
||||
ASSERT(ecmaModule->GetIsNewBcVersion());
|
||||
int index = GetExportObjectIndex(vm_, ecmaModule, key);
|
||||
JSTaggedValue result = ecmaModule->GetModuleValue(thread, index, false);
|
||||
return JSHandle<JSTaggedValue>(thread, result);
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> ModuleManager::ExecuteNativeModule(JSThread *thread, const std::string &recordName)
|
||||
{
|
||||
ObjectFactory *factory = vm_->GetFactory();
|
||||
JSHandle<EcmaString> keyHandle = factory->NewFromASCII(key.c_str());
|
||||
JSHandle<EcmaString> record = factory->NewFromASCII(recordName.c_str());
|
||||
JSMutableHandle<JSTaggedValue> requiredModule(thread, thread->GlobalConstants()->GetUndefined());
|
||||
if (IsImportedModuleLoaded(keyHandle.GetTaggedValue())) {
|
||||
JSHandle<SourceTextModule> moduleRecord = HostGetImportedModule(keyHandle.GetTaggedValue());
|
||||
if (IsImportedModuleLoaded(record.GetTaggedValue())) {
|
||||
JSHandle<SourceTextModule> moduleRecord = HostGetImportedModule(record.GetTaggedValue());
|
||||
requiredModule.Update(moduleRecord);
|
||||
} else {
|
||||
CString requestPath = ConvertToString(keyHandle.GetTaggedValue());
|
||||
CString requestPath = ConvertToString(record.GetTaggedValue());
|
||||
CString entryPoint = PathHelper::GetStrippedModuleName(requestPath);
|
||||
auto [isNative, moduleType] = SourceTextModule::CheckNativeModule(requestPath);
|
||||
JSHandle<JSTaggedValue> nativeModuleHandle = ResolveNativeModule(requestPath, moduleType);
|
||||
@ -822,16 +823,53 @@ JSHandle<JSTaggedValue> ModuleManager::LoadNativeModule(JSThread *thread, const
|
||||
nativeModule->SetLoadingTypes(LoadingTypes::STABLE_MODULE);
|
||||
requiredModule.Update(nativeModule);
|
||||
}
|
||||
return requiredModule;
|
||||
}
|
||||
|
||||
JSHandle<SourceTextModule> ecmaModule = JSHandle<SourceTextModule>::Cast(requiredModule);
|
||||
if (ecmaModule->GetIsNewBcVersion()) {
|
||||
int index = GetExportObjectIndex(vm_, ecmaModule, key);
|
||||
JSTaggedValue result = ecmaModule->GetModuleValue(thread, index, false);
|
||||
return JSHandle<JSTaggedValue>(thread, result);
|
||||
JSHandle<JSTaggedValue> ModuleManager::ExecuteJsonModule(JSThread *thread, const std::string &recordName,
|
||||
const CString &filename, const JSPandaFile *jsPandaFile)
|
||||
{
|
||||
ObjectFactory *factory = vm_->GetFactory();
|
||||
JSHandle<EcmaString> record = factory->NewFromASCII(recordName.c_str());
|
||||
JSMutableHandle<JSTaggedValue> requiredModule(thread, thread->GlobalConstants()->GetUndefined());
|
||||
if (IsImportedModuleLoaded(record.GetTaggedValue())) {
|
||||
JSHandle<SourceTextModule> moduleRecord = HostGetImportedModule(record.GetTaggedValue());
|
||||
requiredModule.Update(moduleRecord);
|
||||
} else {
|
||||
JSHandle<SourceTextModule> moduleRecord =
|
||||
JSHandle<SourceTextModule>::Cast(ModuleDataExtractor::ParseJsonModule(thread, jsPandaFile, filename,
|
||||
recordName.c_str()));
|
||||
moduleRecord->SetStatus(ModuleStatus::EVALUATED);
|
||||
requiredModule.Update(moduleRecord);
|
||||
}
|
||||
return requiredModule;
|
||||
}
|
||||
|
||||
JSTaggedValue result = ecmaModule->GetModuleValue(thread, keyHandle.GetTaggedValue(), false);
|
||||
return JSHandle<JSTaggedValue>(thread, result);
|
||||
JSHandle<JSTaggedValue> ModuleManager::ExecuteCjsModule(JSThread *thread, const std::string &recordName,
|
||||
const JSPandaFile *jsPandaFile)
|
||||
{
|
||||
ObjectFactory *factory = vm_->GetFactory();
|
||||
CString entryPoint = JSPandaFile::ENTRY_FUNCTION_NAME;
|
||||
CString moduleRecord = jsPandaFile->GetJSPandaFileDesc();
|
||||
if (!jsPandaFile->IsBundlePack()) {
|
||||
entryPoint = recordName;
|
||||
moduleRecord = recordName;
|
||||
}
|
||||
JSHandle<EcmaString> record = factory->NewFromASCII(moduleRecord);
|
||||
|
||||
JSMutableHandle<JSTaggedValue> requiredModule(thread, thread->GlobalConstants()->GetUndefined());
|
||||
if (IsImportedModuleLoaded(record.GetTaggedValue())) {
|
||||
requiredModule.Update(HostGetImportedModule(record.GetTaggedValue()));
|
||||
} else {
|
||||
JSHandle<SourceTextModule> module =
|
||||
JSHandle<SourceTextModule>::Cast(ModuleDataExtractor::ParseCjsModule(thread, jsPandaFile));
|
||||
module->SetEcmaModuleRecordName(thread, record);
|
||||
requiredModule.Update(module);
|
||||
JSPandaFileExecutor::Execute(thread, jsPandaFile, entryPoint);
|
||||
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, requiredModule);
|
||||
module->SetStatus(ModuleStatus::EVALUATED);
|
||||
}
|
||||
return requiredModule;
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> ModuleManager::GetModuleNameSpaceFromFile(
|
||||
|
@ -56,6 +56,7 @@ public:
|
||||
JSHandle<SourceTextModule> HostGetImportedModule(JSTaggedValue referencing);
|
||||
JSTaggedValue HostGetImportedModule(void *src);
|
||||
bool IsImportedModuleLoaded(JSTaggedValue referencing);
|
||||
bool IsEvaluatedModule(JSTaggedValue referencing);
|
||||
|
||||
JSHandle<JSTaggedValue> ResolveNativeModule(const CString &moduleRequestName, ModuleTypes moduleType);
|
||||
JSHandle<JSTaggedValue> HostResolveImportedModule(const void *buffer, size_t size, const CString &filename);
|
||||
@ -68,6 +69,13 @@ public:
|
||||
JSHandle<JSTaggedValue> HostResolveImportedModule(const JSPandaFile *jsPandaFile, const CString &filename);
|
||||
|
||||
JSHandle<JSTaggedValue> LoadNativeModule(JSThread *thread, const std::string &key);
|
||||
|
||||
JSHandle<JSTaggedValue> ExecuteNativeModule(JSThread *thread, const std::string &recordName);
|
||||
|
||||
JSHandle<JSTaggedValue> ExecuteJsonModule(JSThread *thread, const std::string &recordName,
|
||||
const CString &filename, const JSPandaFile *jsPandaFile);
|
||||
JSHandle<JSTaggedValue> ExecuteCjsModule(JSThread *thread, const std::string &recordName,
|
||||
const JSPandaFile *jsPandaFile);
|
||||
JSHandle<JSTaggedValue> GetModuleNameSpaceFromFile(
|
||||
JSThread *thread, std::string &recordNameStr, std::string &baseFileName);
|
||||
|
||||
@ -115,8 +123,6 @@ private:
|
||||
void StoreModuleValueInternal(JSHandle<SourceTextModule> ¤tModule,
|
||||
int32_t index, JSTaggedValue value);
|
||||
|
||||
JSTaggedValue GetValueFromExportObject(JSHandle<JSTaggedValue> &exportObject, int32_t index);
|
||||
|
||||
// deprecated begin
|
||||
JSTaggedValue GetModuleValueOutterInternal(JSTaggedValue key, JSTaggedValue currentModule);
|
||||
void StoreModuleValueInternal(JSHandle<SourceTextModule> ¤tModule,
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "ecmascript/module/js_module_namespace.h"
|
||||
#include "ecmascript/module/module_data_extractor.h"
|
||||
#include "ecmascript/module/module_path_helper.h"
|
||||
#include "ecmascript/object_fast_operator-inl.h"
|
||||
#include "ecmascript/platform/file.h"
|
||||
#include "ecmascript/tagged_dictionary.h"
|
||||
|
||||
@ -1417,6 +1418,15 @@ JSTaggedValue SourceTextModule::GetModuleValue(JSThread *thread, JSTaggedValue k
|
||||
return JSTaggedValue::Hole();
|
||||
}
|
||||
|
||||
JSTaggedValue SourceTextModule::GetValueFromExportObject(JSThread *thread, JSHandle<JSTaggedValue> &exportObject,
|
||||
int32_t index)
|
||||
{
|
||||
if (index == SourceTextModule::UNDEFINED_INDEX) {
|
||||
return exportObject.GetTaggedValue();
|
||||
}
|
||||
return ObjectFastOperator::FastGetPropertyByPorpsIndex(thread, exportObject.GetTaggedValue(), index);
|
||||
}
|
||||
|
||||
JSTaggedValue SourceTextModule::FindByExport(const JSTaggedValue &exportEntriesTv, const JSTaggedValue &key,
|
||||
const JSTaggedValue &dictionary)
|
||||
{
|
||||
|
@ -159,6 +159,16 @@ public:
|
||||
moduleType == ModuleTypes::INTERNAL_MODULE;
|
||||
}
|
||||
|
||||
inline static bool IsCjsModule(ModuleTypes moduleType)
|
||||
{
|
||||
return moduleType == ModuleTypes::CJS_MODULE;
|
||||
}
|
||||
|
||||
inline static bool IsJsonModule(ModuleTypes moduleType)
|
||||
{
|
||||
return moduleType == ModuleTypes::JSON_MODULE;
|
||||
}
|
||||
|
||||
inline static bool IsModuleInSharedHeap(JSHandle<SourceTextModule> currentModule)
|
||||
{
|
||||
return currentModule->GetSharedType() > SharedTypes::UNSENDABLE_MODULE;
|
||||
@ -237,6 +247,8 @@ public:
|
||||
|
||||
JSTaggedValue GetNativeModuleValue(JSThread *thread, JSHandle<ResolvedBinding> &binding);
|
||||
JSTaggedValue GetNativeModuleValue(JSThread *thread, JSHandle<ResolvedIndexBinding> &binding);
|
||||
static JSTaggedValue GetValueFromExportObject(JSThread *thread, JSHandle<JSTaggedValue> &exportObject,
|
||||
int32_t index);
|
||||
|
||||
static JSHandle<JSTaggedValue> ResolveIndirectExport(JSThread *thread, const JSHandle<JSTaggedValue> &exportEntry,
|
||||
const JSHandle<JSTaggedValue> &exportName,
|
||||
|
@ -61,6 +61,31 @@ JSTaggedValue SharedModuleManager::GetSendableModuleValue(JSThread *thread, int3
|
||||
return GetSendableModuleValueImpl(thread, index, currentModule);
|
||||
}
|
||||
|
||||
JSTaggedValue SharedModuleManager::GetModuleValue(JSThread *thread, JSHandle<SourceTextModule> module, int index) const
|
||||
{
|
||||
ModuleTypes moduleType = module->GetTypes();
|
||||
if (SourceTextModule::IsNativeModule(moduleType)) {
|
||||
JSHandle<JSTaggedValue> nativeExports = JSHandle<JSTaggedValue>(thread,
|
||||
module->GetModuleValue(thread, 0, false));
|
||||
if (!nativeExports->IsJSObject()) {
|
||||
JSHandle<JSTaggedValue> recordName(thread, module->GetEcmaModuleRecordName());
|
||||
LOG_FULL(WARN) << "Lazy load native module failed, so is " <<
|
||||
ConvertToString(recordName.GetTaggedValue());
|
||||
return nativeExports.GetTaggedValue();
|
||||
}
|
||||
return SourceTextModule::GetValueFromExportObject(thread, nativeExports, index);
|
||||
}
|
||||
if (SourceTextModule::IsCjsModule(moduleType)) {
|
||||
JSHandle<JSTaggedValue> cjsModuleName(thread, SourceTextModule::GetModuleName(module.GetTaggedValue()));
|
||||
JSHandle<JSTaggedValue> cjsExports = CjsModule::SearchFromModuleCache(thread, cjsModuleName);
|
||||
if (cjsExports->IsHole()) {
|
||||
LOG_FULL(FATAL) << "Lazy load cjs module failed, is " << ConvertToString(cjsModuleName.GetTaggedValue());
|
||||
}
|
||||
return SourceTextModule::GetValueFromExportObject(thread, cjsExports, index);
|
||||
}
|
||||
return module->GetModuleValue(thread, index, false);
|
||||
}
|
||||
|
||||
JSTaggedValue SharedModuleManager::GetSendableModuleValueImpl(
|
||||
JSThread *thread, int32_t index, JSTaggedValue currentModule) const
|
||||
{
|
||||
@ -83,26 +108,25 @@ JSTaggedValue SharedModuleManager::GetSendableModuleValueImpl(
|
||||
// moduleRecord is string, find at current vm
|
||||
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
|
||||
JSHandle<SourceTextModule> resolvedModule;
|
||||
if (moduleManager->IsImportedModuleLoaded(moduleRecord)) {
|
||||
if (moduleManager->IsImportedModuleLoaded(moduleRecord) && moduleManager->IsEvaluatedModule(moduleRecord)) {
|
||||
resolvedModule = moduleManager->HostGetImportedModule(moduleRecord);
|
||||
} else {
|
||||
auto isMergedAbc = !module->GetEcmaModuleRecordName().IsUndefined();
|
||||
CString record = ConvertToString(moduleRecord);
|
||||
CString fileName = ConvertToString(module->GetEcmaModuleFilename());
|
||||
if (JSPandaFileExecutor::LazyExecuteModule(thread, record, fileName, isMergedAbc)) {
|
||||
resolvedModule = moduleManager->HostGetImportedModule(moduleRecord);
|
||||
if (!JSPandaFileExecutor::LazyExecuteModule(thread, record, fileName, isMergedAbc)) {
|
||||
LOG_ECMA(FATAL) << "LazyExecuteModule failed";
|
||||
}
|
||||
LOG_ECMA(FATAL) << "LazyExecuteModule failed";
|
||||
resolvedModule = moduleManager->HostGetImportedModule(moduleRecord);
|
||||
}
|
||||
// [[todo::DaiHN will consider HotReload]]
|
||||
// [[todo::DaiHN should consider json, cjs and native module later]]
|
||||
ASSERT(resolvedModule->GetTypes() == ModuleTypes::ECMA_MODULE);
|
||||
return resolvedModule->GetModuleValue(thread, binding->GetIndex(), false);
|
||||
|
||||
return GetModuleValue(thread, resolvedModule, binding->GetIndex());
|
||||
} else if (resolvedBinding.IsResolvedIndexBinding()) {
|
||||
ResolvedIndexBinding *binding = ResolvedIndexBinding::Cast(resolvedBinding.GetTaggedObject());
|
||||
SourceTextModule *resolvedModule = SourceTextModule::Cast(binding->GetModule().GetTaggedObject());
|
||||
return resolvedModule->GetModuleValue(thread, binding->GetIndex(), false);
|
||||
JSHandle<SourceTextModule> resolvedModule(thread, binding->GetModule().GetTaggedObject());
|
||||
return GetModuleValue(thread, resolvedModule, binding->GetIndex());
|
||||
}
|
||||
LOG_ECMA(FATAL) << "Unexpect binding";
|
||||
UNREACHABLE();
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
|
@ -43,6 +43,7 @@ private:
|
||||
NO_COPY_SEMANTIC(SharedModuleManager);
|
||||
NO_MOVE_SEMANTIC(SharedModuleManager);
|
||||
JSHandle<SourceTextModule> GetImportedSModule(JSThread *thread, JSTaggedValue referencing);
|
||||
JSTaggedValue GetModuleValue(JSThread *thread, JSHandle<SourceTextModule> module, int index) const;
|
||||
|
||||
static constexpr uint32_t DEAULT_DICTIONART_CAPACITY = 4;
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "ecmascript/ecma_string_table.h"
|
||||
#include "ecmascript/element_accessor-inl.h"
|
||||
#include "ecmascript/interpreter/fast_runtime_stub-inl.h"
|
||||
#include "ecmascript/js_api/js_api_arraylist.h"
|
||||
#include "ecmascript/js_api/js_api_deque.h"
|
||||
#include "ecmascript/js_api/js_api_linked_list.h"
|
||||
@ -943,5 +944,27 @@ bool ObjectFastOperator::GetNumFromString(const char *str, int len, int *index,
|
||||
*index = indexStr;
|
||||
return true;
|
||||
}
|
||||
|
||||
JSTaggedValue ObjectFastOperator::FastGetPropertyByPorpsIndex(JSThread *thread,
|
||||
JSTaggedValue receiver, uint32_t index)
|
||||
{
|
||||
JSTaggedValue value = JSTaggedValue::Hole();
|
||||
JSObject *obj = JSObject::Cast(receiver);
|
||||
TaggedArray *properties = TaggedArray::Cast(obj->GetProperties().GetTaggedObject());
|
||||
if (!properties->IsDictionaryMode()) {
|
||||
JSHClass *jsHclass = obj->GetJSHClass();
|
||||
LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject());
|
||||
PropertyAttributes attr = layoutInfo->GetAttr(index);
|
||||
value = obj->GetProperty(jsHclass, attr);
|
||||
} else {
|
||||
NameDictionary *dict = NameDictionary::Cast(properties);
|
||||
value = dict->GetValue(index);
|
||||
}
|
||||
if (UNLIKELY(value.IsAccessor())) {
|
||||
return FastRuntimeStub::CallGetter(thread, JSTaggedValue(obj), JSTaggedValue(obj), value);
|
||||
}
|
||||
ASSERT(!value.IsAccessor());
|
||||
return value;
|
||||
}
|
||||
}
|
||||
#endif // ECMASCRIPT_OBJECT_FAST_OPERATOR_INL_H
|
||||
|
@ -92,6 +92,7 @@ public:
|
||||
|
||||
static inline JSTaggedValue CallGetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder,
|
||||
JSTaggedValue value);
|
||||
static inline JSTaggedValue FastGetPropertyByPorpsIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index);
|
||||
private:
|
||||
static inline JSTaggedValue CallSetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value,
|
||||
JSTaggedValue accessorValue);
|
||||
|
Loading…
x
Reference in New Issue
Block a user