1// Copyright JS Foundation and other contributors, http://js.foundation 2// 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// Constructor creates longer array than expected. 16class LongArray extends Array { 17 constructor(len) { 18 super (42); 19 this.fill ("foo"); 20 } 21} 22 23var a = new LongArray (5); 24a.length = 5; 25var sliced = a.slice (); 26assert (sliced.length == 5); 27assert (JSON.stringify (sliced) == '["foo","foo","foo","foo","foo"]') 28 29// Constructor creates shorter array than expected. 30class ShortArray extends Array { 31 constructor(len) { 32 super (2); 33 this.fill ("bar"); 34 } 35} 36 37var b = new ShortArray (8); 38b.length = 8; 39b.fill ("asd", 2); 40var sliced2 = b.slice (); 41assert (sliced2.length == 8); 42assert (JSON.stringify (sliced2) == '["bar","bar","asd","asd","asd","asd","asd","asd"]'); 43 44// Constructor creates array of the expected size. 45class ExactArray extends Array { 46 constructor(len) { 47 super (len); 48 this.fill ("baz"); 49 } 50} 51 52var c = new ExactArray (5); 53var sliced3 = c.slice(); 54assert (sliced3.length == 5); 55assert (JSON.stringify (sliced3) == '["baz","baz","baz","baz","baz"]'); 56