From a253786a4fc64d0f5518f43e6af55ff9efaf0e7c Mon Sep 17 00:00:00 2001 From: chenyiyuan Date: Fri, 1 Sep 2023 16:33:05 +0800 Subject: [PATCH] Shield error in hotreload && add nexlexenv Ins in patch's func_main_0 Change-Id: I8d10ab0cff2f7c17f4cd7724456720bb00105b6b Signed-off-by: chenyiyuan --- es2panda/binder/variable.cpp | 4 +- .../hotreload-noerror/exist-lexenv-3/base.js | 8 +++ .../exist-lexenv-3/base_mod.js | 8 +++ .../exist-lexenv-3/expected.txt | 53 +++++++++++++++ .../hotreload-noerror/lexenv-increase/base.js | 9 +++ .../lexenv-increase/base_mod.js | 10 +++ .../lexenv-increase/expected.txt | 65 +++++++++++++++++++ .../hotreload-noerror/lexenv-reduce/base.js | 9 +++ .../lexenv-reduce/base_mod.js | 9 +++ .../lexenv-reduce/expected.txt | 39 +++++++++++ es2panda/test/runner.py | 7 +- 11 files changed, 216 insertions(+), 5 deletions(-) create mode 100644 es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base.js create mode 100644 es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base_mod.js create mode 100644 es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/expected.txt create mode 100644 es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base.js create mode 100644 es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base_mod.js create mode 100644 es2panda/test/hotreload/hotreload-noerror/lexenv-increase/expected.txt create mode 100644 es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base.js create mode 100644 es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base_mod.js create mode 100644 es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/expected.txt diff --git a/es2panda/binder/variable.cpp b/es2panda/binder/variable.cpp index 2d5536c1120..14ee1f3ee99 100644 --- a/es2panda/binder/variable.cpp +++ b/es2panda/binder/variable.cpp @@ -50,11 +50,11 @@ void LocalVariable::SetLexical(Scope *scope, util::PatchFix *patchFixHelper) uint32_t slot = 0; auto name = Declaration()->Name(); - if (patchFixHelper && patchFixHelper->IsScopeValidToPatchLexical(varScope)) { + if (patchFixHelper && !patchFixHelper->IsHotReload() && patchFixHelper->IsScopeValidToPatchLexical(varScope)) { slot = patchFixHelper->GetSlotIdFromSymbolTable(std::string(name)); if (patchFixHelper->IsPatchVar(slot)) { patchFixHelper->AllocSlotfromPatchEnv(std::string(name)); - } + } } else { slot = varScope->NextSlot(); } diff --git a/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base.js b/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base.js new file mode 100644 index 00000000000..2d829a51e74 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/exist-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; +} \ No newline at end of file diff --git a/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base_mod.js b/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base_mod.js new file mode 100644 index 00000000000..5761bc6f08c --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/exist-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/exist-lexenv-3/expected.txt b/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/expected.txt new file mode 100644 index 00000000000..f79be095e6f --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/exist-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-noerror/lexenv-increase/base.js b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base.js new file mode 100644 index 00000000000..b377a08164d --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base.js @@ -0,0 +1,9 @@ +let a = 1; +let b = 1; +let c = 1; +function A() { + let d = a + b; + let e = 3; + let m = d + e; + return m; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base_mod.js b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base_mod.js new file mode 100644 index 00000000000..f9fecd7991c --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base_mod.js @@ -0,0 +1,10 @@ +let a = 1; +let b = 1; +let c = 1; +let n = 2; +function A() { + let d = a + b + c; + let e = 3; + let m = d + e + n; + return m; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/expected.txt b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/expected.txt new file mode 100644 index 00000000000..5d8ca0489d4 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/expected.txt @@ -0,0 +1,65 @@ +# 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 + sta v0 + throw.undefinedifholewithname a + ldlexvar 0x0, 0x1 + sta v1 + throw.undefinedifholewithname b + lda v1 + add2 0x0, v0 + sta v0 + ldlexvar 0x0, 0x2 + sta v1 + throw.undefinedifholewithname c + lda v1 + add2 0x1, v0 + sta v0 + ldai 0x3 + add2 0x2, v0 + sta v0 + ldlexvar 0x0, 0x3 + sta v1 + throw.undefinedifholewithname n + lda v1 + add2 0x3, v0 + return +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + newlexenv 0x4 + definefunc 0x0, .A, 0x0 + ldai 0x1 + sta v0 + lda v0 + stlexvar 0x0, 0x0 + lda v0 + stlexvar 0x0, 0x1 + lda v0 + stlexvar 0x0, 0x2 + ldai 0x2 + stlexvar 0x0, 0x3 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base.js b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base.js new file mode 100644 index 00000000000..b377a08164d --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base.js @@ -0,0 +1,9 @@ +let a = 1; +let b = 1; +let c = 1; +function A() { + let d = a + b; + let e = 3; + let m = d + e; + return m; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base_mod.js b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base_mod.js new file mode 100644 index 00000000000..3f9da8bb7be --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base_mod.js @@ -0,0 +1,9 @@ +let a = 1; +let b = 1; +let c = 1; +function A() { + let d = a; + let e = 3; + let m = d + e; + return m; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/expected.txt b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/expected.txt new file mode 100644 index 00000000000..d94e48e6757 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/expected.txt @@ -0,0 +1,39 @@ +# 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 + sta v0 + throw.undefinedifholewithname a + ldai 0x3 + add2 0x0, v0 + return +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + newlexenv 0x1 + definefunc 0x0, .A, 0x0 + ldai 0x1 + stlexvar 0x0, 0x0 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 91b2bab2096..9d86b1d2023 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', 'exist-lexenv-3', 'lexenv-reduce', 'lexenv-increase'] + 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) -- Gitee