diff --git a/es2panda/binder/scope.h b/es2panda/binder/scope.h index df26bb49997abf2221fc1608ec3b6e559ef50ff1..9dc0cf11c136741c2ce0b3d7df7b8b429395b58c 100644 --- a/es2panda/binder/scope.h +++ b/es2panda/binder/scope.h @@ -390,6 +390,11 @@ public: return (flags_ & flag) != 0; } + void RestoreFuncMain0LexEnv(uint32_t slotSize) + { + slotIndex_ = slotSize; + } + uint32_t NextSlot() { return slotIndex_++; diff --git a/es2panda/binder/variable.cpp b/es2panda/binder/variable.cpp index 2d5536c11207a7b6b4afbb4ddab8f27e24d7ffe4..77f909c3796f81a699c5745ae22aaea340506cfc 100644 --- a/es2panda/binder/variable.cpp +++ b/es2panda/binder/variable.cpp @@ -54,6 +54,8 @@ void LocalVariable::SetLexical(Scope *scope, util::PatchFix *patchFixHelper) slot = patchFixHelper->GetSlotIdFromSymbolTable(std::string(name)); if (patchFixHelper->IsPatchVar(slot)) { patchFixHelper->AllocSlotfromPatchEnv(std::string(name)); + } else { + varScope->RestoreFuncMain0LexEnv(patchFixHelper->GetEnvSizeOfFuncMain0()); } } else { slot = varScope->NextSlot(); diff --git a/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base.js b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base.js new file mode 100644 index 0000000000000000000000000000000000000000..adfba7025506cd92a2af03ec24c0aeb0d596fcb6 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base.js @@ -0,0 +1,8 @@ +let a = 1; +let b = 1; +let c = 1; +function A() { + a = 2; + b = 2; + c = 2; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base_mod.js b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..5761bc6f08c4e1cf529aa90f5216ac014f4e7949 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base_mod.js @@ -0,0 +1,8 @@ +let a = 1; +let b = 2; +let c = 1; +function A() { + a = 4; + b = 2; + c = 3; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/expected.txt b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f79be095e6f9f04da8406bce072d4e7c18b340a0 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/expected.txt @@ -0,0 +1,53 @@ +# Copyright (c) 2023 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. +.language ECMAScript + +.function any .A(any a0, any a1, any a2) { +label_1: +label_0: + ldlexvar 0x0, 0x0 + throw.undefinedifholewithname a + ldai 0x4 + stlexvar 0x0, 0x0 + ldlexvar 0x0, 0x1 + throw.undefinedifholewithname b + ldai 0x2 + stlexvar 0x0, 0x1 + ldlexvar 0x0, 0x2 + throw.undefinedifholewithname c + ldai 0x3 + stlexvar 0x0, 0x2 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + newlexenv 0x3 + definefunc 0x0, .A, 0x0 + ldai 0x1 + sta v0 + lda v0 + stlexvar 0x0, 0x0 + ldai 0x2 + stlexvar 0x0, 0x1 + lda v0 + stlexvar 0x0, 0x2 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt b/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt index 2bb598719068c469f82e8cece69639f6ae97fe45..c2769ab6dc4abb2adc0d0ccfb9875a422c6de285 100644 --- a/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt +++ b/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -[Patch] Found class .Model changed, not supported! If .Model is not changed and you are changing UI Component, please only change one Component at a time and make sure the Component is placed at the bottom of the file. +[Patch] Found class .Model changed, not supported! [Patch] Found unsupported change in file, will not generate patch! Error: [base_mod.js:0:0] the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 91b2bab2096af640e2cc686720ca9088bd901e21..0ca2655cc5d7bd9d94d588c4f169b3694583e1d4 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -1083,9 +1083,10 @@ class PatchTest(Test): patch_test_cmd.extend([os.path.join(self.path, modified_input_file)]) if 'record-name-with-dots' in os.path.basename(self.path): patch_test_cmd.extend(['--merge-abc', '--record-name=record.name.with.dots']) - if ('modify-anon-content-keep-origin-name' in os.path.basename(self.path) or - 'modify-class-memeber-function' in os.path.basename(self.path)): - patch_test_cmd.extend(['--dump-assembly']) + dump_assembly_testname = ['modify-anon-content-keep-origin-name', 'modify-class-memeber-function', 'add-lexenv-3'] + for name in dump_assembly_testname: + if name in os.path.basename(self.path): + patch_test_cmd.extend(['--dump-assembly']) self.log_cmd(patch_test_cmd) process_base = subprocess.Popen(gen_base_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/es2panda/util/patchFix.cpp b/es2panda/util/patchFix.cpp index e5a8a8ad55b151f7a9a6063fe186bf1e58b6658d..fff3fbf62a2be8328426798465ea6881c203b5b8 100644 --- a/es2panda/util/patchFix.cpp +++ b/es2panda/util/patchFix.cpp @@ -293,6 +293,13 @@ uint32_t PatchFix::GetSlotIdFromSymbolTable(const std::string &variableName) return UINT32_MAX; } +uint32_t PatchFix::GetEnvSizeOfFuncMain0() +{ + auto functionIter = originFunctionInfo_->find(funcMain0_); + ASSERT(functionIter != originFunctionInfo_->end()); + return functionIter->second.lexenv.size(); +} + uint32_t PatchFix::GetPatchLexicalIdx(const std::string &variableName) { ASSERT(topScopeLexEnvs_.count(variableName)); @@ -497,11 +504,6 @@ bool PatchFix::CompareClassHash(std::vector> if (IsColdFix()) { modifiedClassNames_.insert(className); continue; - } else if (IsHotReload()) { - std::cerr << "[Patch] Found class " << hashList[i].first << " changed, not supported! If " << - hashList[i].first << " is not changed and you are changing UI Component, please only " << - "change one Component at a time and make sure the Component is placed at the bottom " << - "of the file." << std::endl; } else { ASSERT(IsHotFix()); std::cerr << "[Patch] Found class " << hashList[i].first << " changed, not supported!" << std::endl; diff --git a/es2panda/util/patchFix.h b/es2panda/util/patchFix.h index 3b255b2328902fd024f2c699f42a33584f147811..794358cfa7d846d52abe77387a1596ea57f1808d 100644 --- a/es2panda/util/patchFix.h +++ b/es2panda/util/patchFix.h @@ -66,6 +66,7 @@ public: void Finalize(panda::pandasm::Program **prog); bool IsScopeValidToPatchLexical(binder::VariableScope *scope) const; uint32_t GetSlotIdFromSymbolTable(const std::string &variableName); + uint32_t GetEnvSizeOfFuncMain0(); void AllocSlotfromPatchEnv(const std::string &variableName); uint32_t GetPatchLexicalIdx(const std::string &variableName); bool IsPatchVar(uint32_t slot);