creates-a-new-array-from-arguments.js (1648B)
1 // Copyright (c) 2015 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 /*--- 5 esid: sec-array.of 6 es6id: 22.1.2.3 7 description: > 8 Array.of method creates a new Array with a variable number of arguments. 9 info: | 10 22.1.2.3 Array.of ( ...items ) 11 12 ... 13 7. Let k be 0. 14 8. Repeat, while k < len 15 a. Let kValue be items[k]. 16 b. Let Pk be ToString(k). 17 c. Let defineStatus be CreateDataPropertyOrThrow(A,Pk, kValue). 18 d. ReturnIfAbrupt(defineStatus). 19 e. Increase k by 1. 20 9. Let setStatus be Set(A, "length", len, true). 21 10. ReturnIfAbrupt(setStatus). 22 11. Return A. 23 ---*/ 24 25 var a1 = Array.of('Mike', 'Rick', 'Leo'); 26 assert.sameValue( 27 a1.length, 3, 28 'The value of a1.length is expected to be 3' 29 ); 30 assert.sameValue(a1[0], 'Mike', 'The value of a1[0] is expected to be "Mike"'); 31 assert.sameValue(a1[1], 'Rick', 'The value of a1[1] is expected to be "Rick"'); 32 assert.sameValue(a1[2], 'Leo', 'The value of a1[2] is expected to be "Leo"'); 33 34 var a2 = Array.of(undefined, false, null, undefined); 35 assert.sameValue( 36 a2.length, 4, 37 'The value of a2.length is expected to be 4' 38 ); 39 assert.sameValue(a2[0], undefined, 'The value of a2[0] is expected to equal undefined'); 40 assert.sameValue(a2[1], false, 'The value of a2[1] is expected to be false'); 41 assert.sameValue(a2[2], null, 'The value of a2[2] is expected to be null'); 42 assert.sameValue(a2[3], undefined, 'The value of a2[3] is expected to equal undefined'); 43 44 var a3 = Array.of(); 45 assert.sameValue(a3.length, 0, 'The value of a3.length is expected to be 0'); 46 47 reportCompare(0, 0);