• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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:jsonstringifier
18 * @tc.desc:test JSON.stringify
19 * @tc.type: FUNC
20 * @tc.require: issue#I7DFJC
21 */
22
23try {
24    const v0 = [1, 2, 3, 4]
25    function Foo(a) {
26        Object.defineProperty(this, "ownKeys", { configurable: true, enumerable: true, value: a });
27    }
28    const v1 = new Foo("2060681564", v0, 9.53248718923);
29    const v2 = new Proxy({}, v1);
30    JSON.stringify(v2);
31} catch (e) {
32    print("test successful");
33}
34
35var obj = {
36    2147483648: 2289
37}
38print(JSON.stringify(obj));
39
40const a = new Uint32Array(0x10);
41let  b = a.__proto__;
42b[1073741823] = {}
43print(JSON.stringify(a))
44
45let o = {
46    get g() {
47        this[1225] |= 4294967295;
48        return 9;
49    },
50    "f1":1,
51    "f2":1,
52    "f3":1,
53    "f4":1,
54    "f5":1,
55    "f6":1,
56    "f7":1,
57    "f8":1,
58}
59print(JSON.stringify(o))
60let o2 = {
61    get g() {
62        delete this.f1;
63        return 8;
64    },
65    "f1":1,
66    "f2":1,
67}
68print(JSON.stringify(o2))
69var handler2 = {
70    get:function(target,name) {
71        delete parent2.c;
72        return name.toUpperCase();
73    },
74}
75var proxy2 = new Proxy({},handler2);
76var parent2 = {a:proxy2,c:"remove"};
77print(JSON.stringify(parent2))
78
79var obj={
80    get 1() {
81        delete this['2'];
82    },
83    2:2,
84    3:3,
85}
86print(JSON.stringify(obj))
87
88var List = undefined;
89var LinkedList = undefined;
90if (globalThis["ArkPrivate"] != undefined) {
91    List = ArkPrivate.Load(ArkPrivate.List);
92    let list = new List();
93    list.add({"f1": 1});
94    list.add({"f2": 2});
95    print(JSON.stringify(list));
96
97    LinkedList = ArkPrivate.Load(ArkPrivate.LinkedList);
98    let linkList = new LinkedList();
99    linkList.add({"f3": 3});
100    linkList.add({"f4": 4});
101    print(JSON.stringify(linkList));
102}
103
104var v6="123456789\u0000";
105print(JSON.stringify([{}],[String],v6))
106
107var handler2 = {
108  get: function(target, name) {
109    delete parent2.c;
110    return name.toUpperCase();
111  }
112}
113var proxy2 = new Proxy({}, handler2);
114var parent2 = { a: "delete", b: proxy2, c: "remove" };
115print(JSON.stringify(parent2))
116parent2.c = "remove";  // Revert side effect.
117print(JSON.stringify(parent2))
118Reflect.defineProperty(globalThis,"c",{
119    get:()=>{
120        delete this["d"];
121        return "c";
122    },
123    enumerable:true,
124});
125Reflect.set(globalThis,"d","d");
126JSON.stringify(globalThis);
127print("end JSON.stringify(globalThis)")
128