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:arrayjoin 184514f5e3Sopenharmony_ci * @tc.desc:test Array.join 194514f5e3Sopenharmony_ci * @tc.type: FUNC 204514f5e3Sopenharmony_ci * @tc.require: issueI5NO8G 214514f5e3Sopenharmony_ci */ 224514f5e3Sopenharmony_civar a = new Array(1).join(" "); 234514f5e3Sopenharmony_ciprint(a.length); 244514f5e3Sopenharmony_civar str1 = JSON.stringify(Array(3).join("0")); 254514f5e3Sopenharmony_ciprint(str1); 264514f5e3Sopenharmony_civar str2 = JSON.stringify(new Array(3).join("0")); 274514f5e3Sopenharmony_ciprint(str2); 284514f5e3Sopenharmony_ciconst arr = [] 294514f5e3Sopenharmony_ciarr.length = 3 304514f5e3Sopenharmony_civar str3 = JSON.stringify(arr.join("0")); 314514f5e3Sopenharmony_ciprint(str3) 324514f5e3Sopenharmony_ci 334514f5e3Sopenharmony_ci// test circular reference 344514f5e3Sopenharmony_civar arr1 = [1]; 354514f5e3Sopenharmony_ciarr1.push(arr1); 364514f5e3Sopenharmony_ciarr1.push(arr1); 374514f5e3Sopenharmony_ciprint(arr1.toString()); 384514f5e3Sopenharmony_ciprint(arr1.toString()); 394514f5e3Sopenharmony_ci 404514f5e3Sopenharmony_civar arr2 = [1]; 414514f5e3Sopenharmony_civar arr3 = [2]; 424514f5e3Sopenharmony_ciarr2[10] = arr3; 434514f5e3Sopenharmony_ciarr3[10] = arr2; 444514f5e3Sopenharmony_ciprint(arr2.toString()); 454514f5e3Sopenharmony_ciprint(arr2.toString()); 464514f5e3Sopenharmony_ci 474514f5e3Sopenharmony_civar arr4 = [1]; 484514f5e3Sopenharmony_civar arr5 = [2]; 494514f5e3Sopenharmony_civar arr6 = [3]; 504514f5e3Sopenharmony_ciarr4.push(arr5); 514514f5e3Sopenharmony_ciarr5.push(arr6); 524514f5e3Sopenharmony_ciarr6.push(arr4); 534514f5e3Sopenharmony_ciprint(arr4.toString()); 544514f5e3Sopenharmony_ciprint(arr4.toString()); 554514f5e3Sopenharmony_ci 564514f5e3Sopenharmony_civar arr7 = [ 574514f5e3Sopenharmony_ci { 584514f5e3Sopenharmony_ci toLocaleString() { 594514f5e3Sopenharmony_ci return [1, arr7]; 604514f5e3Sopenharmony_ci } 614514f5e3Sopenharmony_ci } 624514f5e3Sopenharmony_ci]; 634514f5e3Sopenharmony_ciprint(arr7.toLocaleString()); 644514f5e3Sopenharmony_ci 654514f5e3Sopenharmony_civar aa = this; 664514f5e3Sopenharmony_civar bb = {}; 674514f5e3Sopenharmony_ciaa.length = 4294967296; // 2 ^ 32 (max array length + 1) 684514f5e3Sopenharmony_citry { 694514f5e3Sopenharmony_ci Array.prototype.join.call(aa,bb) 704514f5e3Sopenharmony_ci} catch (e) { 714514f5e3Sopenharmony_ci print(e instanceof TypeError); 724514f5e3Sopenharmony_ci} 734514f5e3Sopenharmony_ci 744514f5e3Sopenharmony_citry { 754514f5e3Sopenharmony_ci Object.getOwnPropertyDescriptors(Array(1e9).join('c')) 764514f5e3Sopenharmony_ci} catch (e) { 774514f5e3Sopenharmony_ci print(e instanceof RangeError); 784514f5e3Sopenharmony_ci} 794514f5e3Sopenharmony_ci 804514f5e3Sopenharmony_ci([11])["join"]('쏄'); 814514f5e3Sopenharmony_ci 824514f5e3Sopenharmony_cilet proxy1 = new Proxy([123], {}); 834514f5e3Sopenharmony_ciproxy1.pop(); 844514f5e3Sopenharmony_ciproxy1.toString(); 854514f5e3Sopenharmony_ciproxy1.push(456); 864514f5e3Sopenharmony_ciprint(`proxy1: ${proxy1}`); 874514f5e3Sopenharmony_ci 884514f5e3Sopenharmony_cilet proxy2 = new Proxy([123, 456], {}); 894514f5e3Sopenharmony_ciproxy2.pop(); 904514f5e3Sopenharmony_ciproxy2.toString(); 914514f5e3Sopenharmony_ciproxy2.push(456); 924514f5e3Sopenharmony_ciprint(`proxy2: ${proxy2}`); 934514f5e3Sopenharmony_ci 944514f5e3Sopenharmony_ciconst v5 = new Float32Array(1); 954514f5e3Sopenharmony_civ5[0] = NaN; 964514f5e3Sopenharmony_ciprint(v5.join(String.fromCodePoint(0))); 974514f5e3Sopenharmony_ci 984514f5e3Sopenharmony_ciconst v6 = new Float32Array(1); 994514f5e3Sopenharmony_civ6[0] = NaN; 1004514f5e3Sopenharmony_civ6[1] = NaN; 1014514f5e3Sopenharmony_ciprint(v6.join(String.fromCodePoint(0))); 1024514f5e3Sopenharmony_ci 1034514f5e3Sopenharmony_ciconst v7 = new Float32Array(2); 1044514f5e3Sopenharmony_civ7[0] = NaN; 1054514f5e3Sopenharmony_ciprint(v7.join(String.fromCodePoint(0))); 1064514f5e3Sopenharmony_ci 1074514f5e3Sopenharmony_ciconst element = { 1084514f5e3Sopenharmony_ci toString() { 1094514f5e3Sopenharmony_ci Array.prototype[1] = 'b'; 1104514f5e3Sopenharmony_ci return 'a'; 1114514f5e3Sopenharmony_ci } 1124514f5e3Sopenharmony_ci}; 1134514f5e3Sopenharmony_ciconst arr_join = [element, ,'c']; 1144514f5e3Sopenharmony_ciprint("abc" == arr_join.join(''));