From 26478064dcf8d351f41a1fecb89b8f3983c52cbb Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Wed, 26 Jul 2023 15:08:49 +0800 Subject: [PATCH] Fix do-while with break and loop env Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I7O66L Signed-off-by: ctw-ian Change-Id: Iecaa937714584399f4fcb3a07e235e8cc12d7148 --- es2panda/compiler/core/dynamicContext.cpp | 2 +- .../lexicalEnv/do-while-body-lexical-break.js | 2 +- .../do-while-body-lexical-continue.js | 2 +- ...while-body-lexical-exit-break-expected.txt | 1 + .../do-while-body-lexical-exit-break.js | 41 +++++++++++++++++++ .../do-while-body-lexical-return.js | 2 +- .../js/lexicalEnv/do-while-body-lexical.js | 2 +- 7 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-exit-break-expected.txt create mode 100644 es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-exit-break.js diff --git a/es2panda/compiler/core/dynamicContext.cpp b/es2panda/compiler/core/dynamicContext.cpp index b2cc4c26d6..372c3738bc 100644 --- a/es2panda/compiler/core/dynamicContext.cpp +++ b/es2panda/compiler/core/dynamicContext.cpp @@ -99,7 +99,7 @@ void LexEnvContext::AbortContext([[maybe_unused]] ControlFlowChange cfc, } const auto *node = envScope_->Scope()->Node(); - if (node->IsForUpdateStatement()) { + if (node->IsForUpdateStatement() || node->IsDoWhileStatement()) { return; } diff --git a/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-break.js b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-break.js index 56f5e8e8f8..fe3a950c6b 100644 --- a/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-break.js +++ b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-break.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 diff --git a/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-continue.js b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-continue.js index 2e06e43af6..f31590865c 100644 --- a/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-continue.js +++ b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-continue.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 diff --git a/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-exit-break-expected.txt b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-exit-break-expected.txt new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-exit-break-expected.txt @@ -0,0 +1 @@ +2 diff --git a/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-exit-break.js b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-exit-break.js new file mode 100644 index 0000000000..7b0cf73c9c --- /dev/null +++ b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-exit-break.js @@ -0,0 +1,41 @@ +/* + * 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. + */ + +function a2() { + let dd; + let a1 = 2 + function a() { + + var c = 1; + do { + let d = 1; + if (c == 2) { + break; + } + dd = function b() { + print(d, a1); + } + c++; + d++; + } while (true) + + print(a1); + } + + a(); +} + +a2(); + diff --git a/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-return.js b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-return.js index 2a1db269e7..9e4434d987 100644 --- a/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-return.js +++ b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical-return.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 diff --git a/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical.js b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical.js index 938eac345a..8d4da17a6d 100644 --- a/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical.js +++ b/es2panda/test/compiler/js/lexicalEnv/do-while-body-lexical.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 -- Gitee