• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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/*
17 * @tc.name:loadicbyvalue
18 * @tc.desc:test loadicbyvalue
19 * @tc.type: FUNC
20 * @tc.require: issueI5NO8G
21 */
22var i = 3;
23var obj = { 3: "icsuccess" };
24function func1(a) {
25    var b = a[i];
26}
27for (let j = 300; j > 0; j--) {
28    func1(obj);
29}
30assert_equal(obj[i],'icsuccess');
31
32// PoC testcase
33const arr = []
34for (let i = 0; i < 20; i++) {
35    const v0 = "p" + i;
36    const v1 = Symbol.iterator;
37    const v2 = {
38        [v1]() { },
39    };
40    arr[v0] = i;
41}
42const v3 = new Uint8Array(128);
43v3[arr];
44
45var obj1 = {
46    0: 0,
47    2147483647: 1,
48    2147483648: 2,
49    4294967295: 3,
50    4294967296: 4,
51}
52let obj1Key = [];
53let obj1Value = [];
54let obj1AssertKey = ['0', '2147483647', '2147483648', '4294967295', '4294967296'];
55let obj1AssertValue = [0, 1, 2, 3, 4];
56for (let item in obj1) {
57    obj1Key.push(item);
58    obj1Value.push(obj1[item]);
59}
60assert_equal(obj1Key, obj1AssertKey);
61assert_equal(obj1Value, obj1AssertValue);
62
63// test ic
64var lineStr = "方舟ArK TypeScript RuntimekTS运行时(ARK TypeScript Runtime)K TypeScript Runtime是OppeScript RK TypeScripK TypeScript Runtimet Runtimeuntime)是OpeK TypeScript RuntimenHarmony上ArkTS应用使用的运行时。包含ArkTS/JS对象的分配enHarmonypeScript Runtime)是OpenHarmony上ArkTS应用使用的运行时。包含ArkTS/JS对象的分配上ArkTS应用使用peScript Runtime)是OpenHarmony上ArkTS应用使用的运行时。包含ArkTS/JS对象的分配的运行时。包含ArkTS/JS对象的分配器以及垃圾回收器(GC)、符合ECMAScript规范的标准库、用于运行ARK前端组件生成的方舟字节码(ARK Bytecode简称abc)的解释器、用于加速的内联缓存、静态类型编译器、运行时的C++/C函数接口(NAPI)等模块.";
65var str = "方舟ArkTS运行时(ARK TypeScript Runtime)是OpenHarmony上ArkTS应用使用的运行时。包含ArkTS/JS对象的分配器以及垃圾回收器(GC)、符合ECMAScript规范的标准库、用于运行ARK前端组件生成的方舟字节码(ARK Bytecode简称abc)的解释器、用于加速的内联缓存、静态类型编译器、运行时的C++/C函数接口(NAPI)等模块.";
66str += str;
67str += str;
68str += str;
69var c;
70var l;
71var strC;
72for (let i = 0; i < 100; i++) {
73    strC = str.split("C");
74    c = str[i];
75    l = str.length;
76    strC = lineStr.split("C");
77    c = lineStr[i];
78    l = lineStr.length;
79}
80var strObj = new String("方舟ArkTS运行时(ARK TypeScript Runtime)是OpenHarmony上ArkTS应用使用的运行时。包含ArkTS/JS对象的分配器以及垃圾回收器(GC)、符合ECMAScript规范的标准库、用于运行ARK前端组件生成的方舟字节码(ARK Bytecode简称abc)的解释器、用于加速的内联缓存、静态类型编译器、运行时的C++/C函数接口(NAPI)等模块.");
81for (let i = 0; i < 100; i++) {
82    strC = strObj.split("C");
83    c = strObj[i];
84    l = strObj.length;
85}
86
87
88for (let i = 0; i < 100; i++) {
89    let arr = [0];
90    arr[0] = arr;
91}
92
93function g(o, v) {
94    let res;
95    for (let i = 0; i < 100; i++) {
96        res = o[1];
97        if (res != v) {
98            print("Error ",res);
99            assert_unreachable();
100        }
101    }
102    return res;
103}
104{
105    let pro = [1,1,1,1];
106    let o = {
107        __proto__: pro };
108    o[102500] = 1;
109    o["test"] = "test";
110    assert_equal(g(o, 1),1);
111    Object.defineProperty(o, "1", { value: 2 });
112    assert_equal(g(o, 2),2);
113}
114{
115    let pro = new Uint8Array(10);
116    pro[1]=1;
117    let o = {
118        __proto__: pro };
119    o[102500] = 1;
120    o["test"] = "test";
121    assert_equal(g(o, 1),1);
122    Object.defineProperty(o, "1", { value: 2 });
123    assert_equal(g(o, 2),2);
124}
125
126test_end();