14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021 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/*
174514f5e3Sopenharmony_ci * @tc.name:spreadoperator
184514f5e3Sopenharmony_ci * @tc.desc:test spread (...)
194514f5e3Sopenharmony_ci * @tc.type: FUNC
204514f5e3Sopenharmony_ci * @tc.require: issueI5NO8G
214514f5e3Sopenharmony_ci */
224514f5e3Sopenharmony_ci// test spread Array
234514f5e3Sopenharmony_civar arr1 = [...Array(16).keys()];
244514f5e3Sopenharmony_ciprint(arr1.length);
254514f5e3Sopenharmony_ciprint(arr1);
264514f5e3Sopenharmony_ci
274514f5e3Sopenharmony_civar arr2 = [1, 2, 4, 6, 7, 8, 9, 54];
284514f5e3Sopenharmony_civar arr3 = [...arr2];
294514f5e3Sopenharmony_ciprint(arr3.length);
304514f5e3Sopenharmony_ciprint(arr3);
314514f5e3Sopenharmony_ci
324514f5e3Sopenharmony_ci// test spread Set
334514f5e3Sopenharmony_ciconst set1 = new Set();
344514f5e3Sopenharmony_ciset1.add(42);
354514f5e3Sopenharmony_ciset1.add(42);
364514f5e3Sopenharmony_ciset1.add(13);
374514f5e3Sopenharmony_ciset1.add(23);
384514f5e3Sopenharmony_ci
394514f5e3Sopenharmony_civar arr4 = [...set1.keys()];
404514f5e3Sopenharmony_ciprint(arr4.length);
414514f5e3Sopenharmony_ciprint(arr4);
424514f5e3Sopenharmony_ci
434514f5e3Sopenharmony_civar arr5 = [...set1];
444514f5e3Sopenharmony_ciprint(arr5.length);
454514f5e3Sopenharmony_ciprint(arr5);
464514f5e3Sopenharmony_ci
474514f5e3Sopenharmony_ci// test spread map
484514f5e3Sopenharmony_ciconst map1 = new Map();
494514f5e3Sopenharmony_cimap1.set('a', 1);
504514f5e3Sopenharmony_cimap1.set('b', 2);
514514f5e3Sopenharmony_cimap1.set('c', 3);
524514f5e3Sopenharmony_ci
534514f5e3Sopenharmony_civar arr6 = [...map1.keys()];
544514f5e3Sopenharmony_ciprint(arr6.length);
554514f5e3Sopenharmony_ciprint(arr6);
564514f5e3Sopenharmony_ci
574514f5e3Sopenharmony_civar arr7 = [...map1.values()];
584514f5e3Sopenharmony_ciprint(arr7.length);
594514f5e3Sopenharmony_ciprint(arr7);
604514f5e3Sopenharmony_ci
614514f5e3Sopenharmony_ci// test change Symbol.iterator
624514f5e3Sopenharmony_cilet iterFunc = function *() {
634514f5e3Sopenharmony_ci    yield 1;
644514f5e3Sopenharmony_ci    yield 2;
654514f5e3Sopenharmony_ci    yield 3;
664514f5e3Sopenharmony_ci}
674514f5e3Sopenharmony_ciprint(...map1);
684514f5e3Sopenharmony_ciMap.prototype[Symbol.iterator] = iterFunc;
694514f5e3Sopenharmony_ciprint(...map1);
704514f5e3Sopenharmony_ci
714514f5e3Sopenharmony_cilet set  = new Set()
724514f5e3Sopenharmony_ciset.add('a');
734514f5e3Sopenharmony_ciset.add('b');
744514f5e3Sopenharmony_ciset.add('c');
754514f5e3Sopenharmony_ciprint(...set);
764514f5e3Sopenharmony_ciSet.prototype[Symbol.iterator] = iterFunc;
774514f5e3Sopenharmony_ciprint(...set);
784514f5e3Sopenharmony_ci
794514f5e3Sopenharmony_cilet uint8 = new Uint8Array(2);
804514f5e3Sopenharmony_ciprint(...uint8);
814514f5e3Sopenharmony_ciUint8Array.prototype[Symbol.iterator] = iterFunc;
824514f5e3Sopenharmony_ciprint(...uint8);
834514f5e3Sopenharmony_ci
844514f5e3Sopenharmony_cilet arr8 = ['foo'];
854514f5e3Sopenharmony_cilet warn1 = print.bind(print);
864514f5e3Sopenharmony_cifunction show1(message, ...args) {
874514f5e3Sopenharmony_ci    return warn1(message, ...args);
884514f5e3Sopenharmony_ci}
894514f5e3Sopenharmony_cishow1(...arr8);
904514f5e3Sopenharmony_ci
914514f5e3Sopenharmony_cilet arr9 = ['foo'];
924514f5e3Sopenharmony_cilet warn2 = print.bind(print);
934514f5e3Sopenharmony_cifunction show2(message, ...args) {
944514f5e3Sopenharmony_ci    warn2(message, ...args);
954514f5e3Sopenharmony_ci}
964514f5e3Sopenharmony_ciconst handler = {
974514f5e3Sopenharmony_ci    apply: function (target, thisArg, argumentsList) {
984514f5e3Sopenharmony_ci        return target(...argumentsList);
994514f5e3Sopenharmony_ci    }
1004514f5e3Sopenharmony_ci};
1014514f5e3Sopenharmony_cilet proxy = new Proxy(show2, handler);
1024514f5e3Sopenharmony_ciproxy(...arr9);
1034514f5e3Sopenharmony_ci
1044514f5e3Sopenharmony_cilet fruits1 = ['Apple']
1054514f5e3Sopenharmony_cilet fruits2 = ['Apple', 'Banana']
1064514f5e3Sopenharmony_ciprint(...fruits2)
1074514f5e3Sopenharmony_ciArray.prototype[Symbol.iterator] = function* () {
1084514f5e3Sopenharmony_ci    yield 1;
1094514f5e3Sopenharmony_ci    yield 2;
1104514f5e3Sopenharmony_ci    yield 3;
1114514f5e3Sopenharmony_ci}
1124514f5e3Sopenharmony_ciprint(...fruits1)
1134514f5e3Sopenharmony_ciprint(...fruits2)
1144514f5e3Sopenharmony_ci
1154514f5e3Sopenharmony_ci// test spread array when encounter situations like [...arr, elem1, elem2] with arr be StableJSArray
1164514f5e3Sopenharmony_cifunction appendChild(newNode) {
1174514f5e3Sopenharmony_ci    this.childNodes = [...this.childNodes, newNode];
1184514f5e3Sopenharmony_ci}
1194514f5e3Sopenharmony_ciconst app = { tageName: 'VIEW', childNodes: [], appendChild };
1204514f5e3Sopenharmony_cifor (let i = 0; i < 5; ++i) {
1214514f5e3Sopenharmony_ci    const el = { tageName: 'VIEW', childNodes: [], appendChild };
1224514f5e3Sopenharmony_ci    const text = { tageName: 'VIEW', childNodes: [], appendChild };
1234514f5e3Sopenharmony_ci    const content = { tageName: '#text', content: i };
1244514f5e3Sopenharmony_ci    text.appendChild(content);
1254514f5e3Sopenharmony_ci    el.appendChild(text);
1264514f5e3Sopenharmony_ci    app.appendChild(el);
1274514f5e3Sopenharmony_ci}
1284514f5e3Sopenharmony_cifor (let i = 0; i < 5; ++i) {
1294514f5e3Sopenharmony_ci    print(app.childNodes[i].childNodes[0].childNodes[0].content);
1304514f5e3Sopenharmony_ci}
1314514f5e3Sopenharmony_cilet result = []
1324514f5e3Sopenharmony_citry {
1334514f5e3Sopenharmony_ci    class C29 {};
1344514f5e3Sopenharmony_ci    const v66 = undefined;
1354514f5e3Sopenharmony_ci    new C29(...v66);
1364514f5e3Sopenharmony_ci} catch (err) {
1374514f5e3Sopenharmony_ci    result.push(err.name == "TypeError");
1384514f5e3Sopenharmony_ci}
1394514f5e3Sopenharmony_ciprint(result)
1404514f5e3Sopenharmony_ci
1414514f5e3Sopenharmony_cilet arr=[];
1424514f5e3Sopenharmony_ciprint([,...arr].length)
1434514f5e3Sopenharmony_ciprint([,...''].length)
144