!8162 Support Lazy import cjs and so

Merge pull request !8162 from yaochaonan/lazyimport
This commit is contained in:
openharmony_ci 2024-07-19 03:44:21 +00:00 committed by Gitee
commit 5e34e003e6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
34 changed files with 380 additions and 324 deletions

View File

@ -145,11 +145,12 @@ JSTaggedValue ModuleManager::GetModuleValueOutterInternal(int32_t index, JSTagge
JSTaggedValue resolvedModule = binding->GetModule();
JSHandle<SourceTextModule> module(thread, resolvedModule);
if (SourceTextModule::IsNativeModule(module->GetTypes())) {
return ModuleManagerHelper::GetNativeModuleValue(thread, resolvedModule, binding->GetBindingName());
return ModuleManagerHelper::UpdateBindingAndGetModuleValue(
thread, currentModuleHdl, module, index, binding->GetBindingName());
}
if (module->GetTypes() == ModuleTypes::CJS_MODULE) {
JSHandle<JSTaggedValue> cjsModuleName(thread, SourceTextModule::GetModuleName(module.GetTaggedValue()));
return CjsModule::SearchFromModuleCache(thread, cjsModuleName).GetTaggedValue();
return ModuleManagerHelper::UpdateBindingAndGetModuleValue(
thread, currentModuleHdl, module, index, binding->GetBindingName());
}
}
if (resolvedBinding.IsResolvedRecordIndexBinding()) {
@ -187,10 +188,6 @@ JSTaggedValue ModuleManager::GetLazyModuleValueOutterInternal(int32_t index, JST
JSTaggedValue resolvedModule = binding->GetModule();
JSHandle<SourceTextModule> module(thread, resolvedModule);
ASSERT(resolvedModule.IsSourceTextModule());
SourceTextModule::Evaluate(thread, module, nullptr);
if (thread->HasPendingException()) {
return JSTaggedValue::Undefined();
}
// Support for only modifying var value of HotReload.
// Cause patchFile exclude the record of importing modifying var. Can't reresolve moduleRecord.
EcmaContext *context = thread->GetCurrentEcmaContext();
@ -200,9 +197,13 @@ JSTaggedValue ModuleManager::GetLazyModuleValueOutterInternal(int32_t index, JST
if (!resolvedModuleOfHotReload->IsHole()) {
resolvedModule = resolvedModuleOfHotReload.GetTaggedValue();
JSHandle<SourceTextModule> moduleOfHotReload(thread, resolvedModule);
SourceTextModule::Evaluate(thread, moduleOfHotReload, nullptr);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
return ModuleManagerHelper::GetModuleValue(thread, moduleOfHotReload, binding->GetIndex());
}
}
SourceTextModule::Evaluate(thread, module, nullptr);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
return ModuleManagerHelper::GetModuleValue(thread, module, binding->GetIndex());
}
if (resolvedBinding.IsResolvedBinding()) {
@ -212,18 +213,17 @@ JSTaggedValue ModuleManager::GetLazyModuleValueOutterInternal(int32_t index, JST
ModuleStatus status = module->GetStatus();
ModuleTypes moduleType = module->GetTypes();
if (SourceTextModule::IsNativeModule(moduleType)) {
SourceTextModule::InstantiateNativeModule(thread, currentModuleHdl, module, moduleType);
module->SetStatus(ModuleStatus::EVALUATED);
return ModuleManagerHelper::GetNativeModuleValue(thread, resolvedModule, binding->GetBindingName());
SourceTextModule::EvaluateNativeModule(thread, module, moduleType);
return ModuleManagerHelper::UpdateBindingAndGetModuleValue(
thread, currentModuleHdl, module, index, binding->GetBindingName());
}
if (moduleType == ModuleTypes::CJS_MODULE) {
if (status != ModuleStatus::EVALUATED) {
SourceTextModule::ModuleExecution(thread, module, nullptr, 0);
module->SetStatus(ModuleStatus::EVALUATED);
}
SourceTextModule::InstantiateCJS(thread, currentModuleHdl, module);
JSHandle<JSTaggedValue> cjsModuleName(thread, SourceTextModule::GetModuleName(module.GetTaggedValue()));
return CjsModule::SearchFromModuleCache(thread, cjsModuleName).GetTaggedValue();
return ModuleManagerHelper::UpdateBindingAndGetModuleValue(
thread, currentModuleHdl, module, index, binding->GetBindingName());
}
}
if (resolvedBinding.IsResolvedRecordIndexBinding()) {

View File

@ -19,6 +19,7 @@
#include "ecmascript/js_array.h"
#include "ecmascript/base/string_helper.h"
#include "ecmascript/object_factory-inl.h"
#include "ecmascript/module/module_manager_helper.h"
#include "ecmascript/module/js_module_deregister.h"
#include "ecmascript/module/js_module_record.h"
#include "ecmascript/module/js_module_source_text.h"
@ -120,8 +121,7 @@ OperationResult ModuleNamespace::GetProperty(JSThread *thread, const JSHandle<JS
// 9. Assert: targetModule is not undefined.
ASSERT(!targetModule.IsUndefined());
if (UNLIKELY(SourceTextModule::IsNativeModule(mm->GetTypes()))) {
result = SourceTextModule::Cast(mm.GetTaggedValue())->
GetNativeModuleValue(thread, resolvedBind);
result = ModuleManagerHelper::GetModuleValue(thread, mm, resolvedBind->GetBindingName());
} else {
result = SourceTextModule::Cast(targetModule.GetTaggedObject())->
GetModuleValue(thread, resolvedBind->GetBindingName(), true);
@ -134,8 +134,7 @@ OperationResult ModuleNamespace::GetProperty(JSThread *thread, const JSHandle<JS
// 9. Assert: targetModule is not undefined.
ASSERT(!targetModule.IsUndefined());
if (UNLIKELY(SourceTextModule::IsNativeModule(mm->GetTypes()))) {
result = SourceTextModule::Cast(mm.GetTaggedValue())->
GetNativeModuleValue(thread, resolvedBind);
result = ModuleManagerHelper::GetNativeOrCjsModuleValue(thread, targetModule, resolvedBind->GetIndex());
} else {
result = SourceTextModule::Cast(targetModule.GetTaggedObject())->
GetModuleValue(thread, resolvedBind->GetIndex(), true);

View File

@ -305,25 +305,6 @@ JSHandle<JSTaggedValue> SourceTextModule::ResolveExport(JSThread *thread, const
return starResolution;
}
void SourceTextModule::InstantiateCJS(JSThread *thread, const JSHandle<SourceTextModule> &currentModule,
const JSHandle<SourceTextModule> &requiredModule)
{
JSTaggedValue cjsFileName(requiredModule->GetEcmaModuleFilename());
JSTaggedValue cjsRecordName(requiredModule->GetEcmaModuleRecordName());
JSMutableHandle<JSTaggedValue> cjsModuleName(thread, JSTaggedValue::Undefined());
// Get exported cjs module
bool isBundle;
if (cjsRecordName.IsUndefined()) {
cjsModuleName.Update(cjsFileName);
isBundle = true;
} else {
cjsModuleName.Update(cjsRecordName);
isBundle = false;
}
JSHandle<JSTaggedValue> cjsExports = CjsModule::SearchFromModuleCache(thread, cjsModuleName);
InitializeEnvironment(thread, currentModule, cjsModuleName, cjsExports, isBundle);
}
std::pair<bool, ModuleTypes> SourceTextModule::CheckNativeModule(const CString &moduleRequestName)
{
if (moduleRequestName[0] != '@' ||
@ -486,74 +467,18 @@ bool SourceTextModule::LoadNativeModule(JSThread *thread, const JSHandle<SourceT
return true;
}
void SourceTextModule::InstantiateNativeModule(JSThread *thread, JSHandle<SourceTextModule> &currentModule,
JSHandle<SourceTextModule> &requiredModule, ModuleTypes moduleType)
void SourceTextModule::EvaluateNativeModule(JSThread *thread, JSHandle<SourceTextModule> nativeModule,
ModuleTypes moduleType)
{
if (requiredModule->GetStatus() != ModuleStatus::EVALUATED) {
if (!SourceTextModule::LoadNativeModule(thread, requiredModule, moduleType)) {
LOG_FULL(WARN) << "LoadNativeModule " <<
ModulePathHelper::Utf8ConvertToString(requiredModule->GetEcmaModuleRecordName()) << " failed";
return;
}
}
JSHandle<JSTaggedValue> nativeModuleName(thread, requiredModule->GetEcmaModuleRecordName());
JSHandle<JSTaggedValue> nativeExports(thread, requiredModule->GetModuleValue(thread, 0, false));
InitializeEnvironment(thread, currentModule, nativeModuleName, nativeExports, false);
}
void SourceTextModule::InitializeEnvironment(JSThread *thread, const JSHandle<SourceTextModule> &currentModule,
JSHandle<JSTaggedValue> &moduleName, JSHandle<JSTaggedValue> &exports, bool isBundle)
{
// Get esm environment
JSHandle<JSTaggedValue> moduleEnvironment(thread, currentModule->GetEnvironment());
auto globalConstants = thread->GlobalConstants();
if (moduleEnvironment->IsUndefined()) {
if (nativeModule->GetStatus() == ModuleStatus::EVALUATED) {
return;
}
JSHandle<TaggedArray> environment = JSHandle<TaggedArray>::Cast(moduleEnvironment);
size_t length = environment->GetLength();
JSHandle<TaggedArray> importEntries(thread, currentModule->GetImportEntries());
JSMutableHandle<ImportEntry> host(thread, globalConstants->GetUndefined());
JSMutableHandle<JSTaggedValue> importName(thread, globalConstants->GetUndefined());
// update required module
for (size_t idx = 0; idx < length; idx++) {
JSTaggedValue resolvedBinding = environment->Get(idx);
// if resolvedBinding.IsHole(), means that importname is * .
if (resolvedBinding.IsHole()) {
continue;
}
JSHandle<SourceTextModule> requestedModule = GetModuleFromBinding(thread, resolvedBinding);
JSMutableHandle<JSTaggedValue> requestedName(thread, JSTaggedValue::Undefined());
if (isBundle) {
requestedName.Update(requestedModule->GetEcmaModuleFilename());
} else {
requestedName.Update(requestedModule->GetEcmaModuleRecordName());
}
// if not the same module, then don't have to update
if (!JSTaggedValue::SameValue(requestedName, moduleName)) {
continue;
}
// rebinding here
host.Update(importEntries->Get(idx));
importName.Update(host->GetImportName());
JSHandle<JSTaggedValue> resolution =
SourceTextModule::ResolveExportObject(thread, requestedModule, exports, importName);
// ii. If resolution is null or "ambiguous", throw a SyntaxError exception.
if (resolution->IsNull() || resolution->IsString()) {
CString requestMod = ModulePathHelper::ReformatPath(
ModulePathHelper::Utf8ConvertToString(host->GetModuleRequest()));
CString recordStr = ModulePathHelper::ReformatPath(
ModulePathHelper::Utf8ConvertToString(currentModule->GetEcmaModuleRecordName()));
CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) +
ModulePathHelper::Utf8ConvertToString(importName.GetTaggedValue()) +
"' which imported by '" + recordStr + "'";
THROW_ERROR(thread, ErrorType::SYNTAX_ERROR, msg.c_str());
}
// iii. Call envRec.CreateImportBinding(
// in.[[LocalName]], resolution.[[Module]], resolution.[[BindingName]]).
environment->Set(thread, idx, resolution);
if (!SourceTextModule::LoadNativeModule(thread, nativeModule, moduleType)) {
LOG_FULL(INFO) << "LoadNativeModule " <<
ModulePathHelper::Utf8ConvertToString(nativeModule->GetEcmaModuleRecordName()) << " failed";
return;
}
nativeModule->SetStatus(ModuleStatus::EVALUATED);
}
JSHandle<SourceTextModule> SourceTextModule::GetModuleFromBinding(JSThread *thread,
@ -1131,8 +1056,7 @@ int SourceTextModule::InnerModuleEvaluationUnsafe(JSThread *thread, const JSHand
}
ModuleTypes moduleType = requiredModule->GetTypes();
if (SourceTextModule::IsNativeModule(moduleType)) {
InstantiateNativeModule(thread, module, requiredModule, moduleType);
requiredModule->SetStatus(ModuleStatus::EVALUATED);
EvaluateNativeModule(thread, requiredModule, moduleType);
continue;
}
// if requiredModule is jsonModule, then don't need to execute.
@ -1171,10 +1095,6 @@ int SourceTextModule::InnerModuleEvaluationUnsafe(JSThread *thread, const JSHand
module->SetPendingAsyncDependencies(module->GetPendingAsyncDependencies() + 1);
AddAsyncParentModule(thread, requiredModule, module);
}
// if requiredModule is CommonJS Module, instantiate here (after CommonJS execution).
if (moduleType == ModuleTypes::CJS_MODULE) {
InstantiateCJS(thread, module, requiredModule);
}
}
}
int pendingAsyncDependencies = module->GetPendingAsyncDependencies();
@ -1358,8 +1278,7 @@ int SourceTextModule::ModuleEvaluation(JSThread *thread, const JSHandle<ModuleRe
}
ModuleTypes moduleType = requiredModule->GetTypes();
if (SourceTextModule::IsNativeModule(moduleType)) {
InstantiateNativeModule(thread, module, requiredModule, moduleType);
requiredModule->SetStatus(ModuleStatus::EVALUATED);
EvaluateNativeModule(thread, requiredModule, moduleType);
continue;
}
if (moduleType == ModuleTypes::JSON_MODULE) {
@ -1371,11 +1290,6 @@ int SourceTextModule::ModuleEvaluation(JSThread *thread, const JSHandle<ModuleRe
index += result;
HandleConcurrentEvaluateResult(thread, requiredModule, stack, result);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, index);
[[maybe_unused]] ModuleStatus requiredModuleStatus = requiredModule->GetStatus();
ASSERT(requiredModuleStatus == ModuleStatus::EVALUATED);
if (moduleType == ModuleTypes::CJS_MODULE) {
InstantiateCJS(thread, module, requiredModule);
}
}
}
return index;
@ -1480,22 +1394,6 @@ void SourceTextModule::AddStarExportEntry(JSThread *thread, const JSHandle<Sourc
}
}
JSTaggedValue SourceTextModule::GetNativeModuleValue(JSThread *thread, JSHandle<ResolvedBinding> &binding)
{
DISALLOW_GARBAGE_COLLECTION;
ResolvedBinding *resolvedBinding = ResolvedBinding::Cast(binding.GetTaggedValue().GetTaggedObject());
return ModuleManagerHelper::GetNativeModuleValue(thread, resolvedBinding->GetModule(),
resolvedBinding->GetBindingName());
}
JSTaggedValue SourceTextModule::GetNativeModuleValue(JSThread *thread, JSHandle<ResolvedIndexBinding> &binding)
{
DISALLOW_GARBAGE_COLLECTION;
ResolvedIndexBinding *resolvedBinding = ResolvedIndexBinding::Cast(binding.GetTaggedValue().GetTaggedObject());
return ModuleManagerHelper::GetNativeModuleValue(thread, resolvedBinding->GetModule(),
resolvedBinding->GetIndex());
}
JSTaggedValue SourceTextModule::GetModuleValue(JSThread *thread, int32_t index, bool isThrow)
{
DISALLOW_GARBAGE_COLLECTION;

View File

@ -312,13 +312,12 @@ public:
const void *buffer = nullptr, size_t size = 0, bool executeFromJob = false);
// 15.2.1.16.4 Instantiate()
static int PUBLIC_API Instantiate(JSThread *thread, const JSHandle<JSTaggedValue> &moduleHdl,
bool executeFromJob = false);
static void InstantiateCJS(JSThread *thread, const JSHandle<SourceTextModule> &currentModule,
const JSHandle<SourceTextModule> &requiredModule);
static void InstantiateNativeModule(JSThread *thread, JSHandle<SourceTextModule> &currentModule,
JSHandle<SourceTextModule> &requiredModule,
ModuleTypes moduleType);
static int PUBLIC_API Instantiate(JSThread *thread,
const JSHandle<JSTaggedValue> &moduleHdl,
bool executeFromJob = false);
static void EvaluateNativeModule(JSThread *thread, JSHandle<SourceTextModule> nativeModule,
ModuleTypes moduleType);
JSTaggedValue GetModuleValue(JSThread *thread, int32_t index, bool isThrow);
void StoreModuleValue(JSThread *thread, int32_t index, const JSHandle<JSTaggedValue> &value);
@ -326,8 +325,6 @@ public:
JSTaggedValue GetModuleValue(JSThread *thread, JSTaggedValue key, bool isThrow);
void StoreModuleValue(JSThread *thread, const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &value);
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);
@ -352,6 +349,7 @@ public:
const JSHandle<SourceTextModule> &module, const JSHandle<JSTaggedValue> &moduleRequest);
static std::tuple<bool, JSHandle<SourceTextModule>> GetResolvedModuleWithMerge(JSThread *thread,
const JSHandle<SourceTextModule> &module, const JSHandle<JSTaggedValue> &moduleRequest);
private:
static void SetExportName(JSThread *thread,
const JSHandle<JSTaggedValue> &moduleRequest, const JSHandle<SourceTextModule> &module,
@ -372,10 +370,9 @@ private:
const JSHandle<JSTaggedValue> &exportName,
const JSHandle<SourceTextModule> &module);
static bool CheckCircularImport(const JSHandle<SourceTextModule> &module,
const JSHandle<JSTaggedValue> &exportName,
CVector<std::pair<JSHandle<SourceTextModule>, JSHandle<JSTaggedValue>>> &resolveVector);
static void InitializeEnvironment(JSThread *thread, const JSHandle<SourceTextModule> &currentModule,
JSHandle<JSTaggedValue> &moduleName, JSHandle<JSTaggedValue> &exports, bool isBundle);
const JSHandle<JSTaggedValue> &exportName,
CVector<std::pair<JSHandle<SourceTextModule>,
JSHandle<JSTaggedValue>>> &resolveVector);
static void CheckResolvedBinding(JSThread *thread, const JSHandle<SourceTextModule> &module);
static void CheckResolvedIndexBinding(JSThread *thread, const JSHandle<SourceTextModule> &module);

View File

@ -110,9 +110,7 @@ JSTaggedValue SharedModuleManager::GetLazySendableModuleValueImpl(
ResolvedIndexBinding *binding = ResolvedIndexBinding::Cast(resolvedBinding.GetTaggedObject());
JSHandle<SourceTextModule> resolvedModule(thread, binding->GetModule().GetTaggedObject());
SourceTextModule::Evaluate(thread, resolvedModule, nullptr);
if (thread->HasPendingException()) {
return JSTaggedValue::Undefined();
}
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
return ModuleManagerHelper::GetModuleValue(thread, resolvedModule, binding->GetIndex());
} else if (resolvedBinding.IsResolvedRecordBinding()) {
return ModuleManagerHelper::GetLazyModuleValueFromRecordBinding(thread, module, resolvedBinding);

View File

@ -25,146 +25,89 @@
namespace panda::ecmascript {
JSTaggedValue ModuleManagerHelper::GetModuleValue(JSThread *thread, JSHandle<SourceTextModule> module, int index)
{
ModuleTypes moduleType = module->GetTypes();
if (SourceTextModule::IsNativeModule(moduleType) || SourceTextModule::IsCjsModule(moduleType)) {
return GetNativeOrCjsModuleValue(thread, module.GetTaggedValue(), index);
}
return module->GetModuleValue(thread, index, false);
}
JSTaggedValue ModuleManagerHelper::GetNativeOrCjsModuleValue(JSThread *thread,
JSTaggedValue resolvedModule,
int32_t index)
{
JSHandle<JSTaggedValue> exports = GetNativeOrCjsExports(thread, resolvedModule);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
return SourceTextModule::GetValueFromExportObject(thread, exports, index);
}
JSHandle<JSTaggedValue> ModuleManagerHelper::GetNativeOrCjsExports(JSThread *thread, JSTaggedValue resolvedModule)
{
JSHandle<SourceTextModule> module(thread, resolvedModule);
// if cjsModule is not JSObject, means cjs uses default exports.
JSMutableHandle<JSTaggedValue> exports(thread, thread->GlobalConstants()->GetUndefined());
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) << "Load native module failed, so is " <<
ConvertToString(recordName.GetTaggedValue());
return nativeExports.GetTaggedValue();
exports.Update(module->GetModuleValue(thread, 0, false));
if (!exports->IsJSObject()) {
CString errorMsg =
"Loading native module:" + ConvertToString(SourceTextModule::GetModuleName(resolvedModule)) +
", failed";
JSHandle<JSTaggedValue> exception(thread, JSTaggedValue::Exception());
THROW_NEW_ERROR_WITH_MSG_AND_RETURN_VALUE(thread,
ErrorType::SYNTAX_ERROR, errorMsg.c_str(), exception);
}
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) << "Load cjs module failed, is " << ConvertToString(cjsModuleName.GetTaggedValue());
exports.Update(CjsModule::SearchFromModuleCache(thread, cjsModuleName).GetTaggedValue());
if (exports->IsHole()) {
CString errorMsg =
"Loading cjs module:" + ConvertToString(SourceTextModule::GetModuleName(resolvedModule)) + ", failed";
JSHandle<JSTaggedValue> exception(thread, JSTaggedValue::Exception());
THROW_NEW_ERROR_WITH_MSG_AND_RETURN_VALUE(thread,
ErrorType::SYNTAX_ERROR, errorMsg.c_str(), exception);
}
return SourceTextModule::GetValueFromExportObject(thread, cjsExports, index);
}
return module->GetModuleValue(thread, index, false);
return exports;
}
JSTaggedValue ModuleManagerHelper::GetModuleValue(JSThread *thread, JSHandle<SourceTextModule> module,
JSTaggedValue bindingName)
{
ModuleTypes moduleType = module->GetTypes();
if (SourceTextModule::IsNativeModule(moduleType)) {
return GetNativeModuleValue(thread, module.GetTaggedValue(), bindingName);
}
if (SourceTextModule::IsCjsModule(moduleType)) {
return GetCJSModuleValue(thread, module.GetTaggedValue(), bindingName);
}
LOG_FULL(FATAL) << "This line is not reachable";
UNREACHABLE();
}
JSTaggedValue ModuleManagerHelper::GetNativeModuleValue(JSThread *thread,
JSTaggedValue resolvedModule, JSTaggedValue bindingName)
{
JSHandle<JSTaggedValue> nativeExports = JSHandle<JSTaggedValue>(thread,
SourceTextModule::Cast(resolvedModule.GetTaggedObject())->GetModuleValue(thread, 0, false));
if (!nativeExports->IsJSObject()) {
JSHandle<JSTaggedValue> nativeModuleName(thread, SourceTextModule::GetModuleName(resolvedModule));
LOG_FULL(WARN) << "Load native module failed, so is " <<
ConvertToString(nativeModuleName.GetTaggedValue());
return nativeExports.GetTaggedValue();
}
if (UNLIKELY(JSTaggedValue::SameValue(bindingName,
thread->GlobalConstants()->GetHandledDefaultString().GetTaggedValue()))) {
return nativeExports.GetTaggedValue();
JSHandle<JSTaggedValue> exports = GetNativeOrCjsExports(thread, module.GetTaggedValue());
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
if (UNLIKELY(JSTaggedValue::SameValue(
bindingName, thread->GlobalConstants()->GetHandledDefaultString().GetTaggedValue()))) {
return exports.GetTaggedValue();
}
// need fix
return JSHandle<JSTaggedValue>(thread, SlowRuntimeStub::LdObjByName(thread,
nativeExports.GetTaggedValue(),
exports.GetTaggedValue(),
bindingName,
false,
JSTaggedValue::Undefined())).GetTaggedValue();
}
JSTaggedValue ModuleManagerHelper::GetNativeModuleValue(JSThread *thread, JSTaggedValue resolvedModule, int32_t index)
{
DISALLOW_GARBAGE_COLLECTION;
SourceTextModule *module = SourceTextModule::Cast(resolvedModule.GetTaggedObject());
JSHandle<JSTaggedValue> nativeExports = JSHandle<JSTaggedValue>(thread,
module->GetModuleValue(thread, 0, false));
if (!nativeExports->IsJSObject()) {
JSHandle<JSTaggedValue> recordName(thread, module->GetEcmaModuleRecordName());
LOG_FULL(WARN) << "Load native module failed, so is " <<
ConvertToString(recordName.GetTaggedValue());
return nativeExports.GetTaggedValue();
}
return SourceTextModule::GetValueFromExportObject(thread, nativeExports, index);
}
JSTaggedValue ModuleManagerHelper::GetCJSModuleValue(JSThread *thread, JSTaggedValue resolvedModule,
JSTaggedValue bindingName)
{
JSHandle<SourceTextModule> module(thread, resolvedModule);
JSHandle<JSTaggedValue> cjsModuleName(thread, SourceTextModule::GetModuleName(resolvedModule));
JSHandle<JSTaggedValue> cjsExports = CjsModule::SearchFromModuleCache(thread, cjsModuleName);
// if cjsModule is not JSObject, means cjs uses default exports.
if (!cjsExports->IsJSObject()) {
if (cjsExports->IsHole()) {
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
CString errorMsg = "Loading requireModule" + ConvertToString(cjsModuleName.GetTaggedValue()) + "failed";
JSHandle<JSObject> syntaxError =
factory->GetJSError(base::ErrorType::SYNTAX_ERROR, errorMsg.c_str(), StackCheck::NO);
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), JSTaggedValue::Exception());
}
return cjsExports.GetTaggedValue();
}
if (UNLIKELY(JSTaggedValue::SameValue(bindingName,
thread->GlobalConstants()->GetHandledDefaultString().GetTaggedValue()))) {
return cjsExports.GetTaggedValue();
}
return JSHandle<JSTaggedValue>(thread, SlowRuntimeStub::LdObjByName(thread,
cjsExports.GetTaggedValue(),
bindingName,
false,
JSTaggedValue::Undefined())).GetTaggedValue();
}
JSTaggedValue ModuleManagerHelper::GetCJSModuleValue(JSThread *thread, JSTaggedValue resolvedModule, int32_t index)
{
JSHandle<SourceTextModule> module(thread, resolvedModule);
JSHandle<JSTaggedValue> cjsModuleName(thread, SourceTextModule::GetModuleName(resolvedModule));
JSHandle<JSTaggedValue> cjsExports = CjsModule::SearchFromModuleCache(thread, cjsModuleName);
// if cjsModule is not JSObject, means cjs uses default exports.
if (!cjsExports->IsJSObject()) {
if (cjsExports->IsHole()) {
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
CString errorMsg = "Loading requireModule" + ConvertToString(cjsModuleName.GetTaggedValue()) + "failed";
JSHandle<JSObject> syntaxError =
factory->GetJSError(base::ErrorType::SYNTAX_ERROR, errorMsg.c_str(), StackCheck::NO);
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), JSTaggedValue::Exception());
}
return cjsExports.GetTaggedValue();
}
return SourceTextModule::GetValueFromExportObject(thread, cjsExports, index);
}
JSTaggedValue ModuleManagerHelper::GetModuleValueFromIndexBinding(JSThread *thread, JSHandle<SourceTextModule> module,
JSTaggedValue resolvedBinding)
{
JSHandle<ResolvedRecordIndexBinding> binding(thread, resolvedBinding);
JSHandle<JSTaggedValue> moduleRecord(thread, binding->GetModuleRecord());
ASSERT(moduleRecord->IsString());
CString record = ModulePathHelper::Utf8ConvertToString(moduleRecord.GetTaggedValue());
// moduleRecord is string, find at current vm
JSHandle<JSTaggedValue> recordName(thread, binding->GetModuleRecord());
ASSERT(recordName->IsString());
// recordName is string, find at current vm
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
CString recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue());
JSHandle<SourceTextModule> resolvedModule;
if (moduleManager->IsEvaluatedModule(record)) {
resolvedModule = moduleManager->HostGetImportedModule(record);
if (moduleManager->IsEvaluatedModule(recordNameStr)) {
resolvedModule = moduleManager->HostGetImportedModule(recordNameStr);
} else {
auto isMergedAbc = !module->GetEcmaModuleRecordName().IsUndefined();
CString fileName = ConvertToString(binding->GetAbcFileName());
if (!JSPandaFileExecutor::LazyExecuteModule(thread, record, fileName, isMergedAbc)) {
CString fileName = ModulePathHelper::Utf8ConvertToString((binding->GetAbcFileName()));
if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordNameStr, fileName, isMergedAbc)) {
LOG_ECMA(FATAL) << "LazyExecuteModule failed";
}
resolvedModule = moduleManager->HostGetImportedModule(record);
resolvedModule = moduleManager->HostGetImportedModule(recordNameStr);
}
return GetModuleValue(thread, resolvedModule, binding->GetIndex());
}
@ -173,21 +116,21 @@ JSTaggedValue ModuleManagerHelper::GetModuleValueFromRecordBinding(JSThread *thr
JSTaggedValue resolvedBinding)
{
JSHandle<ResolvedRecordBinding> binding(thread, resolvedBinding);
JSHandle<JSTaggedValue> moduleRecord(thread, binding->GetModuleRecord());
ASSERT(moduleRecord->IsString());
CString record = ModulePathHelper::Utf8ConvertToString(moduleRecord.GetTaggedValue());
JSHandle<JSTaggedValue> recordName(thread, binding->GetModuleRecord());
ASSERT(recordName->IsString());
CString recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue());
// moduleRecord is string, find at current vm
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<SourceTextModule> resolvedModule;
if (moduleManager->IsEvaluatedModule(record)) {
resolvedModule = moduleManager->HostGetImportedModule(record);
if (moduleManager->IsEvaluatedModule(recordNameStr)) {
resolvedModule = moduleManager->HostGetImportedModule(recordNameStr);
} else {
auto isMergedAbc = !module->GetEcmaModuleRecordName().IsUndefined();
CString fileName = ConvertToString(module->GetEcmaModuleFilename());
if (!JSPandaFileExecutor::LazyExecuteModule(thread, record, fileName, isMergedAbc)) {
CString fileName = ModulePathHelper::Utf8ConvertToString((module->GetEcmaModuleFilename()));
if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordNameStr, fileName, isMergedAbc)) {
LOG_ECMA(FATAL) << "LazyExecuteModule failed";
}
resolvedModule = moduleManager->HostGetImportedModule(record);
resolvedModule = moduleManager->HostGetImportedModule(recordNameStr);
}
return GetModuleValue(thread, resolvedModule, binding->GetBindingName());
}
@ -197,29 +140,25 @@ JSTaggedValue ModuleManagerHelper::GetLazyModuleValueFromIndexBinding(JSThread *
JSTaggedValue resolvedBinding)
{
JSHandle<ResolvedRecordIndexBinding> binding(thread, resolvedBinding);
JSHandle<JSTaggedValue> moduleRecord(thread, binding->GetModuleRecord());
ASSERT(moduleRecord->IsString());
JSHandle<JSTaggedValue> recordName(thread, binding->GetModuleRecord());
ASSERT(recordName->IsString());
// moduleRecord is string, find at current vm
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
CString recordName = ModulePathHelper::Utf8ConvertToString(moduleRecord.GetTaggedValue());
CString recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue());
JSHandle<SourceTextModule> resolvedModule;
if (moduleManager->IsLocalModuleLoaded(recordName)) {
if (moduleManager->IsEvaluatedModule(recordName)) {
resolvedModule = moduleManager->HostGetImportedModule(recordName);
} else {
resolvedModule = moduleManager->HostGetImportedModule(recordName);
if (moduleManager->IsLocalModuleLoaded(recordNameStr)) {
resolvedModule = moduleManager->HostGetImportedModule(recordNameStr);
if (!moduleManager->IsEvaluatedModule(recordNameStr)) {
SourceTextModule::Evaluate(thread, resolvedModule, nullptr);
if (thread->HasPendingException()) {
return JSTaggedValue::Undefined();
}
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
}
} else {
auto isMergedAbc = !module->GetEcmaModuleRecordName().IsUndefined();
CString fileName = ConvertToString(binding->GetAbcFileName());
if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordName, fileName, isMergedAbc)) {
CString fileName = ModulePathHelper::Utf8ConvertToString(binding->GetAbcFileName());
if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordNameStr, fileName, isMergedAbc)) {
LOG_ECMA(FATAL) << "LazyExecuteModule failed";
}
resolvedModule = moduleManager->HostGetImportedModule(recordName);
resolvedModule = moduleManager->HostGetImportedModule(recordNameStr);
}
return GetModuleValue(thread, resolvedModule, binding->GetIndex());
}
@ -228,30 +167,59 @@ JSTaggedValue ModuleManagerHelper::GetLazyModuleValueFromRecordBinding(
JSThread *thread, JSHandle<SourceTextModule> module, JSTaggedValue resolvedBinding)
{
JSHandle<ResolvedRecordBinding> binding(thread, resolvedBinding);
JSHandle<JSTaggedValue> moduleRecord(thread, binding->GetModuleRecord());
ASSERT(moduleRecord->IsString());
JSHandle<JSTaggedValue> recordName(thread, binding->GetModuleRecord());
ASSERT(recordName->IsString());
// moduleRecord is string, find at current vm
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
CString recordName = ConvertToString(moduleRecord.GetTaggedValue());
CString recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue());
JSHandle<SourceTextModule> resolvedModule;
if (moduleManager->IsLocalModuleLoaded(recordName)) {
if (moduleManager->IsEvaluatedModule(recordName)) {
resolvedModule = moduleManager->HostGetImportedModule(recordName);
} else {
resolvedModule = moduleManager->HostGetImportedModule(recordName);
if (moduleManager->IsLocalModuleLoaded(recordNameStr)) {
resolvedModule = moduleManager->HostGetImportedModule(recordNameStr);
if (!moduleManager->IsEvaluatedModule(recordNameStr)) {
SourceTextModule::Evaluate(thread, resolvedModule, nullptr);
if (thread->HasPendingException()) {
return JSTaggedValue::Undefined();
}
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
}
} else {
auto isMergedAbc = !module->GetEcmaModuleRecordName().IsUndefined();
CString fileName = ConvertToString(module->GetEcmaModuleFilename());
if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordName, fileName, isMergedAbc)) {
CString fileName = ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleFilename());
if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordNameStr, fileName, isMergedAbc)) {
LOG_ECMA(FATAL) << "LazyExecuteModule failed";
}
resolvedModule = moduleManager->HostGetImportedModule(recordName);
resolvedModule = moduleManager->HostGetImportedModule(recordNameStr);
}
return GetModuleValue(thread, resolvedModule, binding->GetBindingName());
}
JSTaggedValue ModuleManagerHelper::UpdateBindingAndGetModuleValue(JSThread *thread, JSHandle<SourceTextModule> module,
JSHandle<SourceTextModule> requiredModule, int32_t index, JSTaggedValue bindingName)
{
// Get esm environment
JSHandle<JSTaggedValue> moduleEnvironment(thread, module->GetEnvironment());
ASSERT(!moduleEnvironment->IsUndefined());
JSHandle<TaggedArray> environment = JSHandle<TaggedArray>::Cast(moduleEnvironment);
// rebinding here
JSHandle<JSTaggedValue> exports = GetNativeOrCjsExports(thread, requiredModule.GetTaggedValue());
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
JSHandle<JSTaggedValue> exportName(thread, bindingName);
JSHandle<JSTaggedValue> resolution =
SourceTextModule::ResolveExportObject(thread, requiredModule, exports, exportName);
// ii. If resolution is null or "ambiguous", throw a SyntaxError exception.
if (resolution->IsNull() || resolution->IsString()) {
CString requestMod = ModulePathHelper::ReformatPath(
ModulePathHelper::Utf8ConvertToString(SourceTextModule::GetModuleName(requiredModule.GetTaggedValue())));
CString recordStr = ModulePathHelper::ReformatPath(
ModulePathHelper::Utf8ConvertToString(SourceTextModule::GetModuleName(module.GetTaggedValue())));
CString msg = "the requested module '" + requestMod + SourceTextModule::GetResolveErrorReason(resolution) +
ModulePathHelper::Utf8ConvertToString(bindingName) +
"' which imported by '" + recordStr + "'";
THROW_NEW_ERROR_WITH_MSG_AND_RETURN_VALUE(
thread, ErrorType::SYNTAX_ERROR, msg.c_str(), JSTaggedValue::Exception());
}
// iii. Call envRec.CreateImportBinding(
// in.[[LocalName]], resolution.[[Module]], resolution.[[BindingName]]).
environment->Set(thread, index, resolution);
ASSERT(resolution->IsResolvedIndexBinding());
ResolvedIndexBinding *binding = ResolvedIndexBinding::Cast(resolution.GetTaggedValue());
return SourceTextModule::GetValueFromExportObject(thread, exports, binding->GetIndex());
}
} // namespace panda::ecmascript

View File

@ -24,19 +24,16 @@ class ModuleManagerHelper {
public:
static JSTaggedValue PUBLIC_API GetModuleValue(JSThread *thread, JSHandle<SourceTextModule> module, int index);
static JSTaggedValue GetModuleValue(JSThread *thread, JSHandle<SourceTextModule> module,
static JSTaggedValue GetModuleValue(JSThread *thread,
JSHandle<SourceTextModule> module,
JSTaggedValue bindingName);
static JSTaggedValue PUBLIC_API GetNativeModuleValue(JSThread *thread, JSTaggedValue resolvedModule,
JSTaggedValue bindingName);
static JSTaggedValue GetNativeOrCjsModuleValue(JSThread *thread,
JSTaggedValue resolvedModule,
int32_t index);
static JSTaggedValue PUBLIC_API GetNativeModuleValue(JSThread *thread, JSTaggedValue resolvedModule,
int32_t index);
static JSTaggedValue GetCJSModuleValue(JSThread *thread, JSTaggedValue resolvedModule, int32_t index);
static JSTaggedValue GetCJSModuleValue(JSThread *thread, JSTaggedValue resolvedModule,
JSTaggedValue bindingName);
static JSHandle<JSTaggedValue> GetNativeOrCjsExports(JSThread *thread,
JSTaggedValue resolvedModule);
static JSTaggedValue PUBLIC_API GetModuleValueFromIndexBinding(JSThread *thread,
JSHandle<SourceTextModule> module,
@ -53,6 +50,9 @@ public:
static JSTaggedValue GetLazyModuleValueFromRecordBinding(JSThread *thread,
JSHandle<SourceTextModule> module,
JSTaggedValue resolvedBinding);
static JSTaggedValue UpdateBindingAndGetModuleValue(JSThread *thread, JSHandle<SourceTextModule> module,
JSHandle<SourceTextModule> requiredModule, int32_t index, JSTaggedValue bindingName);
};
} // namespace panda::ecmascript
#endif // ECMASCRIPT_MODULE_JS_SHARED_MODULE_H

View File

@ -1,4 +1,4 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@ -18,6 +18,11 @@ host_moduletest_action("cjsC") {
is_commonjs = true
}
host_moduletest_action("cjsD") {
deps = []
is_commonjs = true
}
host_moduletest_action("esmB") {
deps = []
is_module = true
@ -26,6 +31,7 @@ host_moduletest_action("esmB") {
host_moduletest_action("esmnestedimportcjs") {
deps = [
":gen_cjsC_abc",
":gen_cjsD_abc",
":gen_esmB_abc",
]
is_module = true

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module.exports = {
name: "testcjs",
foo: function () {print("testcjs foo")}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -13,5 +13,7 @@
* limitations under the License.
*/
import T from './cjsC.js'
import {foo} from './cjsD.js'
print(T.name)
export {T}
foo()
export {T, foo}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -12,5 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {T} from './esmB.js'
import {T, foo} from './esmB.js'
print("test print: ", T.name)
foo()

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@ -12,4 +12,6 @@
# limitations under the License.
testcjs
testcjs foo
test print: testcjs
testcjs foo

View File

@ -14,8 +14,8 @@
*/
/*
* @tc.name:moduleCircularCheck
* @tc.desc:check module circular import
* @tc.name:lazyimport
* @tc.desc:lazyimport
* @tc.type: FUNC
* @tc.require: issueI5RC2C
*/

View File

@ -14,13 +14,13 @@
*/
/*
* @tc.name:moduleCircularCheck
* @tc.desc:check module circular import
* @tc.name:lazyimport
* @tc.desc:lazyimport
* @tc.type: FUNC
* @tc.require: issueI5RC2C
*/
import {fun} from './C_Cjs'
import lazy {fun} from './G'
import foo from './D_Cjs'
export let b = "3";
print("this is B", JSON.stringify(foo));

View File

@ -14,8 +14,8 @@
*/
/*
* @tc.name:cjsImportJson
* @tc.desc:test import Json
* @tc.name:lazyimport
* @tc.desc:lazyimport
* @tc.type: FUNC
* @tc.require: issueI5NO8G
*/

View File

@ -14,8 +14,8 @@
*/
/*
* @tc.name:moduleCircularCheck
* @tc.desc:check module circular import
* @tc.name:lazyimport
* @tc.desc:lazyimport
* @tc.type: FUNC
* @tc.require: issueI5RC2C
*/

View File

@ -14,8 +14,8 @@
*/
/*
* @tc.name:moduleCircularCheck
* @tc.desc:check module circular import
* @tc.name:lazyimport
* @tc.desc:lazyimport
* @tc.type: FUNC
* @tc.require: issueI5RC2C
*/

View File

@ -14,8 +14,8 @@
*/
/*
* @tc.name:moduleCircularCheck
* @tc.desc:check module circular import
* @tc.name:lazyimport
* @tc.desc:lazyimport
* @tc.type: FUNC
* @tc.require: issueI5RC2C
*/

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @tc.name:lazyimport
* @tc.desc:lazyimport
* @tc.type: FUNC
* @tc.require: issueI5RC2C
*/
import lazy {fun} from './C_Cjs'
export {fun};
fun();
print("this is G");

View File

@ -18,8 +18,8 @@ F func
this is D_Cjs
this is A
{"foo":"module use cjsModule"}
this is C_Cjs
this is B {"foo":"module use cjsModule"}
this is C_Cjs
foo5
instance 3
E func

View File

@ -4,4 +4,5 @@ C_Cjs.js;C_Cjs;commonjs;C_Cjs.js;xxC_Cjsxx
D_Cjs.js;D_Cjs;commonjs;D_Cjs.js;xxD_Cjsxx
E.js;E;esm;E.js;xxExx
F.js;F;esm;F.js;xxFxx
G.js;G;esm;G.js;xxGxx
moduleLazyImport.js;moduleLazyImport;esm;moduleLazyImport.js;xxmoduleLazyImportxx

View File

@ -18,3 +18,4 @@ testImportFunction
foo():(This is strA!)
testImportFunction
ClassB:
foo

View File

@ -24,7 +24,7 @@
declare function print(str: any): string;
import {Test1} from "./func"
import {strA, strB} from "./string"
import {strA, strB, foo} from "./string"
class SendableClassA {
static staticField: string = strA;
@ -74,3 +74,4 @@ class SendableClassB extends SendableClassA {
let sObjb = new SendableClassB("ClassB:");
sObjb.testImportFunction()
foo();

View File

@ -19,6 +19,13 @@
* @tc.type: FUNC
* @tc.require: issue#I9BIE5
*/
// @ts-nocheck
declare function print(str: any): string;
"shared module"
export var strA : string = "(This is strA!)";
export var strB : string = "(This is strB!)";
export var strB : string = "(This is strB!)";
export function foo() {
'use sendable'
print("foo");
}

View File

@ -25,6 +25,7 @@ hot_reload_test_list = [
"global_func",
"global_var",
"import_export",
"lazy_import",
"print_string",
"record_not_same",
"module_var",

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { a } from './module.js'
import { foo } from './module.js'
function A() {
print("print base: " + a);
foo()
}
globalThis.A = A;

View File

@ -0,0 +1,2 @@
base.js;base;esm;base.js;entry
module.js;module;esm;module.js;entry

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import lazy { a } from './module.js'
import lazy { foo } from './module.js'
function A() {
print("this is base_modify");
print("print patch: " + a);
foo()
}

View File

@ -0,0 +1,26 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
QuickFix Execute start
QuickFix start load patch
QuickFix load patch success
this is base_modify
print patch: 200
patch foo
QuickFix start check exception
QuickFix have no exception
QuickFix start unload patch
QuickFix unload patch success
print base: 100
base foo
QuickFix Execute end

View File

@ -0,0 +1,19 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export var a = 100
export function foo() {
print("base foo")
}

View File

@ -0,0 +1,19 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export var a = 200
export function foo() {
print("patch foo")
}

View File

@ -0,0 +1,2 @@
base_modify.js;base;esm;base.js;entry
module_modify.js;module;esm;module.js;entry

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
A();