Bug fix of hot reload

Issue:    https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IASRXV
Signed-off-by: zitongli <lizitong1@huawei.com>
This commit is contained in:
ZitongLi 2024-09-22 12:09:16 +08:00
parent 5c2b6ad057
commit 073a634f8c
6 changed files with 59 additions and 6 deletions

View File

@ -21,6 +21,7 @@
#include "ecmascript/tests/test_helper.h"
#include "ecmascript/napi/include/jsnapi.h"
#include "ecmascript/patch/quick_fix_manager.h"
#include "ecmascript/jspandafile/program_object.h"
using namespace panda::ecmascript;
using namespace panda::panda_file;
@ -28,6 +29,8 @@ using namespace panda::pandasm;
namespace panda::test {
using PatchErrorCode = panda::JSNApi::PatchErrorCode;
using Program = panda::ecmascript::Program;
using EcmaContext = panda::ecmascript::EcmaContext;
class QuickFixTest : public testing::Test {
public:
static void SetUpTestCase()
@ -159,6 +162,42 @@ HWTEST_F_L0(QuickFixTest, HotReload_Buffer)
pfManager->RemoveJSPandaFile(patchFile.get());
}
HWTEST_F_L0(QuickFixTest, HotReload_Instantiate)
{
ThreadManagedScope managedScope(thread);
CString baseFileName = QUICKFIX_ABC_PATH "multi_file/base/merge.abc";
std::shared_ptr<JSPandaFile> baseFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFileName, "");
EXPECT_TRUE(baseFile != nullptr);
CString patchFileName = QUICKFIX_ABC_PATH "multi_file/patch/merge.abc";
std::shared_ptr<JSPandaFile> patchFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, patchFileName, "");
EXPECT_TRUE(patchFile != nullptr);
CString replacedRecordName = "main";
EcmaContext *context = thread->GetCurrentEcmaContext();
context->SetStageOfHotReload(StageOfHotReload::BEGIN_EXECUTE_PATCHMAIN);
ModuleManager *moduleManager = context->GetModuleManager();
JSHandle<JSTaggedValue> module =
moduleManager->HostResolveImportedModuleWithMergeForHotReload(patchFileName, replacedRecordName, false);
EXPECT_FALSE(module->IsHole());
JSHandle<Program> program =
JSPandaFileManager::GetInstance()->GenerateProgram(instance, patchFile.get(), replacedRecordName);
EXPECT_FALSE(program.IsEmpty());
SourceTextModule::Instantiate(thread, module, false);
EXPECT_TRUE(JSHandle<SourceTextModule>::Cast(module)->GetStatus() == ModuleStatus::INSTANTIATED);
context->SetStageOfHotReload(StageOfHotReload::LOAD_END_EXECUTE_PATCHMAIN);
JSHandle<SourceTextModule>::Cast(module)->SetStatus(ModuleStatus::UNINSTANTIATED);
SourceTextModule::Instantiate(thread, module, false);
EXPECT_TRUE(JSHandle<SourceTextModule>::Cast(module)->GetStatus() == ModuleStatus::INSTANTIATED);
}
bool QuickFixQueryFunc(
std::string baseFileName, std::string &patchFileName, uint8_t ** patchBuffer, size_t &patchBufferSize)
{

View File

@ -12,12 +12,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { nop } from './module.js';
import { nop, bar } from './module.js';
function foo() {
print('base foo()');
}
function getBar() {
print('base bar');
return bar;
}
class A {
constructor(a) {
this.a = a;

View File

@ -13,4 +13,5 @@
* limitations under the License.
*/
export let nop = undefined;
export let nop = undefined;
export let bar = 'bar';

View File

@ -13,12 +13,17 @@
* limitations under the License.
*/
import { nop } from './module.js';
import { nop, bar } from './module.js';
function foo() {
print('patch foo()');
}
function getBar() {
print('patch bar');
return bar;
}
class A {
constructor(a) {
this.a = a;

View File

@ -13,4 +13,5 @@
* limitations under the License.
*/
export let nop = undefined;
export let nop = undefined;
export let bar = 'bar';

View File

@ -83,8 +83,10 @@ JSHandle<JSTaggedValue> SourceTextModule::HostResolveImportedModuleWithMerge(JST
CString moduleRequestName = ModulePathHelper::Utf8ConvertToString(moduleRequest.GetTaggedValue());
CString requestStr = ReplaceModuleThroughFeature(thread, moduleRequestName);
CString baseFilename;
if (thread->GetCurrentEcmaContext()->GetStageOfHotReload() == StageOfHotReload::BEGIN_EXECUTE_PATCHMAIN) {
CString baseFilename {};
StageOfHotReload stageOfHotReload = thread->GetCurrentEcmaContext()->GetStageOfHotReload();
if (stageOfHotReload == StageOfHotReload::BEGIN_EXECUTE_PATCHMAIN ||
stageOfHotReload == StageOfHotReload::LOAD_END_EXECUTE_PATCHMAIN) {
baseFilename = thread->GetEcmaVM()->GetQuickFixManager()->GetBaseFileName(module);
} else {
baseFilename = module->GetEcmaModuleFilenameString();