14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci// case 1
174514f5e3Sopenharmony_cifunction test1() {
184514f5e3Sopenharmony_ci    try {
194514f5e3Sopenharmony_ci        var base = null;
204514f5e3Sopenharmony_ci        var prop = {
214514f5e3Sopenharmony_ci            toString: function () {
224514f5e3Sopenharmony_ci                print("toString");
234514f5e3Sopenharmony_ci                throw "111";
244514f5e3Sopenharmony_ci            },
254514f5e3Sopenharmony_ci        };
264514f5e3Sopenharmony_ci        base[prop];
274514f5e3Sopenharmony_ci    } catch (e) {
284514f5e3Sopenharmony_ci        print("error");
294514f5e3Sopenharmony_ci    }
304514f5e3Sopenharmony_ci}
314514f5e3Sopenharmony_ci
324514f5e3Sopenharmony_cifunction test2() {
334514f5e3Sopenharmony_ci    // case 2
344514f5e3Sopenharmony_ci    print(Number.NaN != Number.NaN);
354514f5e3Sopenharmony_ci}
364514f5e3Sopenharmony_ci
374514f5e3Sopenharmony_ci// case 3
384514f5e3Sopenharmony_cifunction _test() {
394514f5e3Sopenharmony_ci    this.x = 0.1;
404514f5e3Sopenharmony_ci}
414514f5e3Sopenharmony_cifunction test3() {
424514f5e3Sopenharmony_ci    var a = new _test();
434514f5e3Sopenharmony_ci    print(a.x);
444514f5e3Sopenharmony_ci}
454514f5e3Sopenharmony_ci
464514f5e3Sopenharmony_cifunction test4() {
474514f5e3Sopenharmony_ci    // case 4: n mod d = r
484514f5e3Sopenharmony_ci    // If r = 0 and n < -0, return -0.
494514f5e3Sopenharmony_ci    print(1 / (-1 % 1));
504514f5e3Sopenharmony_ci    print(1 / (-1 % -1));
514514f5e3Sopenharmony_ci    print(1 / (-3 % 1));
524514f5e3Sopenharmony_ci    print(1 / (-3 % -1));
534514f5e3Sopenharmony_ci    print(1 / (-3 % 3));
544514f5e3Sopenharmony_ci    print(1 / (-3 % -3));
554514f5e3Sopenharmony_ci    print(1 / (-3.3 % 3.3));
564514f5e3Sopenharmony_ci    print(1 / (-3.3 % -3.3));
574514f5e3Sopenharmony_ci}
584514f5e3Sopenharmony_ci
594514f5e3Sopenharmony_cifunction test5() {
604514f5e3Sopenharmony_ci    // case 5: mod
614514f5e3Sopenharmony_ci    var a = {};
624514f5e3Sopenharmony_ci    a._toString = function (value) {
634514f5e3Sopenharmony_ci        if (value === 0 && 1 / value === -Infinity) {
644514f5e3Sopenharmony_ci            return "-0";
654514f5e3Sopenharmony_ci        }
664514f5e3Sopenharmony_ci        return String(value);
674514f5e3Sopenharmony_ci    };
684514f5e3Sopenharmony_ci    var x;
694514f5e3Sopenharmony_ci    x = -1;
704514f5e3Sopenharmony_ci    print(a._toString((x %= -1)));
714514f5e3Sopenharmony_ci}
724514f5e3Sopenharmony_ci
734514f5e3Sopenharmony_cifunction test6() {
744514f5e3Sopenharmony_ci    // case6: prototype
754514f5e3Sopenharmony_ci    var a = [0];
764514f5e3Sopenharmony_ci    a.length = 3;
774514f5e3Sopenharmony_ci    Object.prototype[2] = 2;
784514f5e3Sopenharmony_ci    print(a[2]);
794514f5e3Sopenharmony_ci}
804514f5e3Sopenharmony_ci
814514f5e3Sopenharmony_cifunction test7() {
824514f5e3Sopenharmony_ci	// onheap mode test
834514f5e3Sopenharmony_ci    var onheap = new Uint8Array(1)
844514f5e3Sopenharmony_ci    var onheap2 = new Uint8Array(1)
854514f5e3Sopenharmony_ci    var notOnHeap = new Uint8Array(512 * 8 + 1)
864514f5e3Sopenharmony_ci    onheap[0] = 1  // root on heap
874514f5e3Sopenharmony_ci    notOnHeap[0] = 2 // root not onheap-
884514f5e3Sopenharmony_ci    onheap2[0] = 3  // root on heap
894514f5e3Sopenharmony_ci    print(ArkTools.isOnHeap(onheap));
904514f5e3Sopenharmony_ci    print(ArkTools.isOnHeap(notOnHeap));
914514f5e3Sopenharmony_ci    print(ArkTools.isOnHeap(onheap2));
924514f5e3Sopenharmony_ci    print(onheap[0])
934514f5e3Sopenharmony_ci    print(notOnHeap[0])
944514f5e3Sopenharmony_ci    onheap.buffer  // root not on heap
954514f5e3Sopenharmony_ci    print(ArkTools.isOnHeap(onheap));
964514f5e3Sopenharmony_ci    print(onheap[0])
974514f5e3Sopenharmony_ci    onheap2.x = 2  // transition
984514f5e3Sopenharmony_ci    onheap2.buffer  // clone hclass and set not on heap
994514f5e3Sopenharmony_ci    print(ArkTools.isOnHeap(onheap2));
1004514f5e3Sopenharmony_ci    print(onheap2.x)
1014514f5e3Sopenharmony_ci    print(onheap2[0])
1024514f5e3Sopenharmony_ci}
1034514f5e3Sopenharmony_ci
1044514f5e3Sopenharmony_citest1()
1054514f5e3Sopenharmony_citest2()
1064514f5e3Sopenharmony_citest3()
1074514f5e3Sopenharmony_citest4()
1084514f5e3Sopenharmony_citest5()
1094514f5e3Sopenharmony_citest6()
1104514f5e3Sopenharmony_citest7()
1114514f5e3Sopenharmony_ci
112