diff --git a/ecmascript/ecma_context.h b/ecmascript/ecma_context.h index e4d177d2f6..71825280ec 100644 --- a/ecmascript/ecma_context.h +++ b/ecmascript/ecma_context.h @@ -24,6 +24,7 @@ #include "ecmascript/js_tagged_value.h" #include "ecmascript/mem/c_containers.h" #include "ecmascript/mem/visitor.h" +#include "ecmascript/patch/patch_loader.h" #include "ecmascript/regexp/regexp_parser_cache.h" #include "ecmascript/waiter_list.h" #include "global_handle_collection.h" @@ -425,11 +426,11 @@ public: cachedPatchModules_.clear(); } - int32_t GetStageOfHotReload() const + StageOfHotReload GetStageOfHotReload() const { return stageOfHotReload_; } - void SetStageOfHotReload(int32_t stageOfHotReload) + void SetStageOfHotReload(StageOfHotReload stageOfHotReload) { stageOfHotReload_ = stageOfHotReload; } @@ -490,7 +491,7 @@ private: // for HotReload of module. CMap> cachedPatchModules_ {}; - int32_t stageOfHotReload_ = 0; + StageOfHotReload stageOfHotReload_ = StageOfHotReload::INITIALIZE_STAGE_OF_HOTRELOAD; // VM resources. ModuleManager *moduleManager_ {nullptr}; diff --git a/ecmascript/jspandafile/js_pandafile_executor.cpp b/ecmascript/jspandafile/js_pandafile_executor.cpp index f5b5d85f39..370260286a 100644 --- a/ecmascript/jspandafile/js_pandafile_executor.cpp +++ b/ecmascript/jspandafile/js_pandafile_executor.cpp @@ -226,7 +226,7 @@ Expected JSPandaFileExecutor::Execute(JSThread *thread, con Expected result; - if (context->GetStageOfHotReload() < 0) { + if (context->GetStageOfHotReload() == StageOfHotReload::BEGIN_EXECUTE_PATCHMAIN) { result = context->InvokeEcmaEntrypointForHotReload(jsPandaFile, entryPoint, excuteFromJob); } else { QuickFixManager *quickFixManager = thread->GetEcmaVM()->GetQuickFixManager(); diff --git a/ecmascript/module/js_module_manager.cpp b/ecmascript/module/js_module_manager.cpp index ccfa1134f4..a6e4466f10 100644 --- a/ecmascript/module/js_module_manager.cpp +++ b/ecmascript/module/js_module_manager.cpp @@ -115,8 +115,7 @@ JSTaggedValue ModuleManager::GetModuleValueOutterInternal(int32_t index, JSTagge // 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(); - int32_t InterceptGetModuleValue = 1; // 1: for Interceptint get module var - if (context->GetStageOfHotReload() == InterceptGetModuleValue) { + if (context->GetStageOfHotReload() == StageOfHotReload::LOAD_END_EXECUTE_PATCHMAIN) { const JSHandle resolvedModuleOfHotReload = context->FindPatchModule(ConvertToString(module->GetEcmaModuleRecordName())); if (!resolvedModuleOfHotReload->IsHole()) { diff --git a/ecmascript/patch/patch_loader.cpp b/ecmascript/patch/patch_loader.cpp index 4ed615e0c7..4c8ef1d484 100644 --- a/ecmascript/patch/patch_loader.cpp +++ b/ecmascript/patch/patch_loader.cpp @@ -74,7 +74,7 @@ void PatchLoader::ExecuteFuncOrPatchMain( { LOG_ECMA(DEBUG) << "execute main begin"; EcmaContext *context = thread->GetCurrentEcmaContext(); - context->SetStageOfHotReload(BEGIN_EXECUTE_PATCHMAIN); + context->SetStageOfHotReload(StageOfHotReload::BEGIN_EXECUTE_PATCHMAIN); const auto &replacedRecordNames = patchInfo.replacedRecordNames; @@ -104,9 +104,9 @@ void PatchLoader::ExecuteFuncOrPatchMain( } if (loadPatch) { - context->SetStageOfHotReload(LOAD_END_EXECUTE_PATCHMAIN); + context->SetStageOfHotReload(StageOfHotReload::LOAD_END_EXECUTE_PATCHMAIN); } else { - context->SetStageOfHotReload(UNLOAD_END_EXECUTE_PATCHMAIN); + context->SetStageOfHotReload(StageOfHotReload::UNLOAD_END_EXECUTE_PATCHMAIN); } LOG_ECMA(DEBUG) << "execute main end"; } diff --git a/ecmascript/patch/patch_loader.h b/ecmascript/patch/patch_loader.h index 88d1d3c8e4..6991a201d2 100644 --- a/ecmascript/patch/patch_loader.h +++ b/ecmascript/patch/patch_loader.h @@ -20,7 +20,6 @@ #include "ecmascript/js_tagged_value.h" #include "ecmascript/js_thread.h" #include "ecmascript/mem/c_containers.h" -#include "ecmascript/module/js_module_source_text.h" #include "ecmascript/napi/include/jsnapi.h" namespace panda::ecmascript { @@ -58,6 +57,14 @@ struct PatchInfo { // patch replaced recordNames. CUnorderedSet replacedRecordNames; }; + +enum class StageOfHotReload : int32_t { + BEGIN_EXECUTE_PATCHMAIN = -1, // -1: For intercepting Evaluate() + INITIALIZE_STAGE_OF_HOTRELOAD, // 0 : initialize stageOfHotreload_ in ecma_context.h + LOAD_END_EXECUTE_PATCHMAIN, // 1: for Interceptint get module var + UNLOAD_END_EXECUTE_PATCHMAIN // 2 :for execute abc normally +}; + class PatchLoader { public: PatchLoader() = default; @@ -90,10 +97,6 @@ private: static void ClearPatchInfo(JSThread *thread, const CString &patchFileName); static void ReplaceModuleOfMethod(JSThread *thread, const JSPandaFile *baseFile, PatchInfo &patchInfo); - - static constexpr int32_t BEGIN_EXECUTE_PATCHMAIN = -1; // -1: For intercepting Evaluate() - static constexpr int32_t LOAD_END_EXECUTE_PATCHMAIN = 1; // 1 :For intercepting get module value - static constexpr int32_t UNLOAD_END_EXECUTE_PATCHMAIN = 2; // 2 :for execute abc normally }; } // namespace panda::ecmascript #endif // ECMASCRIPT_PATCH_PATCH_LOADER_H