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 16// case 1 17function test1() { 18 try { 19 var base = null; 20 var prop = { 21 toString: function () { 22 print("toString"); 23 throw "111"; 24 }, 25 }; 26 base[prop]; 27 } catch (e) { 28 print("error"); 29 } 30} 31 32function test2() { 33 // case 2 34 print(Number.NaN != Number.NaN); 35} 36 37// case 3 38function _test() { 39 this.x = 0.1; 40} 41function test3() { 42 var a = new _test(); 43 print(a.x); 44} 45 46function test4() { 47 // case 4: n mod d = r 48 // If r = 0 and n < -0, return -0. 49 print(1 / (-1 % 1)); 50 print(1 / (-1 % -1)); 51 print(1 / (-3 % 1)); 52 print(1 / (-3 % -1)); 53 print(1 / (-3 % 3)); 54 print(1 / (-3 % -3)); 55 print(1 / (-3.3 % 3.3)); 56 print(1 / (-3.3 % -3.3)); 57} 58 59function test5() { 60 // case 5: mod 61 var a = {}; 62 a._toString = function (value) { 63 if (value === 0 && 1 / value === -Infinity) { 64 return "-0"; 65 } 66 return String(value); 67 }; 68 var x; 69 x = -1; 70 print(a._toString((x %= -1))); 71} 72 73function test6() { 74 // case6: prototype 75 var a = [0]; 76 a.length = 3; 77 Object.prototype[2] = 2; 78 print(a[2]); 79} 80 81function test7() { 82 // onheap mode test 83 var onheap = new Uint8Array(1) 84 var onheap2 = new Uint8Array(1) 85 var notOnHeap = new Uint8Array(512 * 8 + 1) 86 onheap[0] = 1 // root on heap 87 notOnHeap[0] = 2 // root not onheap- 88 onheap2[0] = 3 // root on heap 89 print(ArkTools.isOnHeap(onheap)); 90 print(ArkTools.isOnHeap(notOnHeap)); 91 print(ArkTools.isOnHeap(onheap2)); 92 print(onheap[0]) 93 print(notOnHeap[0]) 94 onheap.buffer // root not on heap 95 print(ArkTools.isOnHeap(onheap)); 96 print(onheap[0]) 97 onheap2.x = 2 // transition 98 onheap2.buffer // clone hclass and set not on heap 99 print(ArkTools.isOnHeap(onheap2)); 100 print(onheap2.x) 101 print(onheap2[0]) 102} 103 104test1() 105test2() 106test3() 107test4() 108test5() 109test6() 110test7() 111 112