1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16let globalCond = true; 17function testCatchPhiDataflow() { 18 let a = '0'; 19 try { 20 if (globalCond) { 21 a = '1'; 22 throw a; 23 } else { 24 a = '2'; 25 } 26 } catch (e) { 27 a = e; 28 } 29 print(a); 30} 31 32function testTryWithAccCatchPhi() { 33 let a = 1; 34 try { 35 throw a; 36 } catch (e) { 37 print(e); 38 } 39} 40 41function testTryWithMoveConstants() { 42 let a = 1; 43 try { 44 a = 2; 45 throw a; 46 } catch (e) { 47 print(a === 2); 48 } 49 try { 50 a = 3; 51 throw a; 52 } catch (e) { 53 print(a === 3); 54 } 55} 56 57function testTryWithRegAccAlloc() { 58 let a = 's1'; 59 let b = 's2'; 60 let c = a + b; 61 print(c); 62 try { 63 a = 's1'; 64 b = 's2'; 65 throw 1; 66 } catch (e) { 67 c = a + b; 68 print(c); 69 } 70 c = a + b; 71 print(c); 72} 73 74testCatchPhiDataflow(); 75testTryWithAccCatchPhi(); 76testTryWithMoveConstants(); 77testTryWithRegAccAlloc(); 78