update Array/From files ESID to sec-array.from (#1077)

This commit is contained in:
Sue Lockwood 2017-06-27 14:12:06 -07:00 committed by Leo Balter
parent c74e1e4edf
commit b07621ded1
41 changed files with 578 additions and 537 deletions

View File

@ -5,6 +5,7 @@
description: Testing descriptor property of Array.from
includes:
- propertyHelper.js
esid: sec-array.from
es6id: 22.1.2.1
---*/

View File

@ -1,6 +1,7 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: '`name` property'
info: >

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: >
The length property of the Array.from method is 1.

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: >
If this is a constructor, and items doesn't have an @@iterator,

View File

@ -1,66 +1,67 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
es6id: 22.1.2.1
description: Map function without thisArg on non strict mode
info: >
22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
...
10. Let len be ToLength(Get(arrayLike, "length")).
11. ReturnIfAbrupt(len).
12. If IsConstructor(C) is true, then
a. Let A be Construct(C, «len»).
13. Else,
b. Let A be ArrayCreate(len).
14. ReturnIfAbrupt(A).
15. Let k be 0.
16. Repeat, while k < len
a. Let Pk be ToString(k).
b. Let kValue be Get(arrayLike, Pk).
c. ReturnIfAbrupt(kValue).
d. If mapping is true, then
i. Let mappedValue be Call(mapfn, T, «kValue, k»).
...
flags: [noStrict]
---*/
var list = {
'0': 41,
'1': 42,
'2': 43,
length: 3
};
var calls = [];
function mapFn (value) {
calls.push({
args: arguments,
thisArg: this
});
return value * 2;
}
var result = Array.from(list, mapFn);
assert.sameValue(result.length, 3, 'result.length');
assert.sameValue(result[0], 82, 'result[0]');
assert.sameValue(result[1], 84, 'result[1]');
assert.sameValue(result[2], 86, 'result[2]');
assert.sameValue(calls.length, 3, 'calls.length');
assert.sameValue(calls[0].args.length, 2, 'calls[0].args.length');
assert.sameValue(calls[0].args[0], 41, 'calls[0].args[0]');
assert.sameValue(calls[0].args[1], 0, 'calls[0].args[1]');
assert.sameValue(calls[0].thisArg, this, 'calls[0].thisArg');
assert.sameValue(calls[1].args.length, 2, 'calls[1].args.length');
assert.sameValue(calls[1].args[0], 42, 'calls[1].args[0]');
assert.sameValue(calls[1].args[1], 1, 'calls[1].args[1]');
assert.sameValue(calls[1].thisArg, this, 'calls[1].thisArg');
assert.sameValue(calls[2].args.length, 2, 'calls[2].args.length');
assert.sameValue(calls[2].args[0], 43, 'calls[2].args[0]');
assert.sameValue(calls[2].args[1], 2, 'calls[2].args[1]');
assert.sameValue(calls[2].thisArg, this, 'calls[2].thisArg');
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Map function without thisArg on non strict mode
info: >
22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
...
10. Let len be ToLength(Get(arrayLike, "length")).
11. ReturnIfAbrupt(len).
12. If IsConstructor(C) is true, then
a. Let A be Construct(C, «len»).
13. Else,
b. Let A be ArrayCreate(len).
14. ReturnIfAbrupt(A).
15. Let k be 0.
16. Repeat, while k < len
a. Let Pk be ToString(k).
b. Let kValue be Get(arrayLike, Pk).
c. ReturnIfAbrupt(kValue).
d. If mapping is true, then
i. Let mappedValue be Call(mapfn, T, «kValue, k»).
...
flags: [noStrict]
---*/
var list = {
'0': 41,
'1': 42,
'2': 43,
length: 3
};
var calls = [];
function mapFn (value) {
calls.push({
args: arguments,
thisArg: this
});
return value * 2;
}
var result = Array.from(list, mapFn);
assert.sameValue(result.length, 3, 'result.length');
assert.sameValue(result[0], 82, 'result[0]');
assert.sameValue(result[1], 84, 'result[1]');
assert.sameValue(result[2], 86, 'result[2]');
assert.sameValue(calls.length, 3, 'calls.length');
assert.sameValue(calls[0].args.length, 2, 'calls[0].args.length');
assert.sameValue(calls[0].args[0], 41, 'calls[0].args[0]');
assert.sameValue(calls[0].args[1], 0, 'calls[0].args[1]');
assert.sameValue(calls[0].thisArg, this, 'calls[0].thisArg');
assert.sameValue(calls[1].args.length, 2, 'calls[1].args.length');
assert.sameValue(calls[1].args[0], 42, 'calls[1].args[0]');
assert.sameValue(calls[1].args[1], 1, 'calls[1].args[1]');
assert.sameValue(calls[1].thisArg, this, 'calls[1].thisArg');
assert.sameValue(calls[2].args.length, 2, 'calls[2].args.length');
assert.sameValue(calls[2].args[0], 43, 'calls[2].args[0]');
assert.sameValue(calls[2].args[1], 2, 'calls[2].args[1]');
assert.sameValue(calls[2].thisArg, this, 'calls[2].thisArg');

View File

@ -1,66 +1,67 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
es6id: 22.1.2.1
description: Map function without thisArg on strict mode
info: >
22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
...
10. Let len be ToLength(Get(arrayLike, "length")).
11. ReturnIfAbrupt(len).
12. If IsConstructor(C) is true, then
a. Let A be Construct(C, «len»).
13. Else,
b. Let A be ArrayCreate(len).
14. ReturnIfAbrupt(A).
15. Let k be 0.
16. Repeat, while k < len
a. Let Pk be ToString(k).
b. Let kValue be Get(arrayLike, Pk).
c. ReturnIfAbrupt(kValue).
d. If mapping is true, then
i. Let mappedValue be Call(mapfn, T, «kValue, k»).
...
flags: [onlyStrict]
---*/
var list = {
'0': 41,
'1': 42,
'2': 43,
length: 3
};
var calls = [];
function mapFn (value) {
calls.push({
args: arguments,
thisArg: this
});
return value * 2;
}
var result = Array.from(list, mapFn);
assert.sameValue(result.length, 3, 'result.length');
assert.sameValue(result[0], 82, 'result[0]');
assert.sameValue(result[1], 84, 'result[1]');
assert.sameValue(result[2], 86, 'result[2]');
assert.sameValue(calls.length, 3, 'calls.length');
assert.sameValue(calls[0].args.length, 2, 'calls[0].args.length');
assert.sameValue(calls[0].args[0], 41, 'calls[0].args[0]');
assert.sameValue(calls[0].args[1], 0, 'calls[0].args[1]');
assert.sameValue(calls[0].thisArg, undefined, 'calls[0].thisArg');
assert.sameValue(calls[1].args.length, 2, 'calls[1].args.length');
assert.sameValue(calls[1].args[0], 42, 'calls[1].args[0]');
assert.sameValue(calls[1].args[1], 1, 'calls[1].args[1]');
assert.sameValue(calls[1].thisArg, undefined, 'calls[1].thisArg');
assert.sameValue(calls[2].args.length, 2, 'calls[2].args.length');
assert.sameValue(calls[2].args[0], 43, 'calls[2].args[0]');
assert.sameValue(calls[2].args[1], 2, 'calls[2].args[1]');
assert.sameValue(calls[2].thisArg, undefined, 'calls[2].thisArg');
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Map function without thisArg on strict mode
info: >
22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
...
10. Let len be ToLength(Get(arrayLike, "length")).
11. ReturnIfAbrupt(len).
12. If IsConstructor(C) is true, then
a. Let A be Construct(C, «len»).
13. Else,
b. Let A be ArrayCreate(len).
14. ReturnIfAbrupt(A).
15. Let k be 0.
16. Repeat, while k < len
a. Let Pk be ToString(k).
b. Let kValue be Get(arrayLike, Pk).
c. ReturnIfAbrupt(kValue).
d. If mapping is true, then
i. Let mappedValue be Call(mapfn, T, «kValue, k»).
...
flags: [onlyStrict]
---*/
var list = {
'0': 41,
'1': 42,
'2': 43,
length: 3
};
var calls = [];
function mapFn (value) {
calls.push({
args: arguments,
thisArg: this
});
return value * 2;
}
var result = Array.from(list, mapFn);
assert.sameValue(result.length, 3, 'result.length');
assert.sameValue(result[0], 82, 'result[0]');
assert.sameValue(result[1], 84, 'result[1]');
assert.sameValue(result[2], 86, 'result[2]');
assert.sameValue(calls.length, 3, 'calls.length');
assert.sameValue(calls[0].args.length, 2, 'calls[0].args.length');
assert.sameValue(calls[0].args[0], 41, 'calls[0].args[0]');
assert.sameValue(calls[0].args[1], 0, 'calls[0].args[1]');
assert.sameValue(calls[0].thisArg, undefined, 'calls[0].thisArg');
assert.sameValue(calls[1].args.length, 2, 'calls[1].args.length');
assert.sameValue(calls[1].args[0], 42, 'calls[1].args[0]');
assert.sameValue(calls[1].args[1], 1, 'calls[1].args[1]');
assert.sameValue(calls[1].thisArg, undefined, 'calls[1].thisArg');
assert.sameValue(calls[2].args.length, 2, 'calls[2].args.length');
assert.sameValue(calls[2].args[0], 43, 'calls[2].args[0]');
assert.sameValue(calls[2].args[1], 2, 'calls[2].args[1]');
assert.sameValue(calls[2].thisArg, undefined, 'calls[2].thisArg');

View File

@ -1,67 +1,68 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
es6id: 22.1.2.1
description: Calling from with a valid map function with thisArg
info: >
22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
...
10. Let len be ToLength(Get(arrayLike, "length")).
11. ReturnIfAbrupt(len).
12. If IsConstructor(C) is true, then
a. Let A be Construct(C, «len»).
13. Else,
b. Let A be ArrayCreate(len).
14. ReturnIfAbrupt(A).
15. Let k be 0.
16. Repeat, while k < len
a. Let Pk be ToString(k).
b. Let kValue be Get(arrayLike, Pk).
c. ReturnIfAbrupt(kValue).
d. If mapping is true, then
i. Let mappedValue be Call(mapfn, T, «kValue, k»).
...
---*/
var list = {
'0': 41,
'1': 42,
'2': 43,
length: 3
};
var calls = [];
var thisArg = {};
function mapFn (value) {
calls.push({
args: arguments,
thisArg: this
});
return value * 2;
}
var result = Array.from(list, mapFn, thisArg);
assert.sameValue(result.length, 3, 'result.length');
assert.sameValue(result[0], 82, 'result[0]');
assert.sameValue(result[1], 84, 'result[1]');
assert.sameValue(result[2], 86, 'result[2]');
assert.sameValue(calls.length, 3, 'calls.length');
assert.sameValue(calls[0].args.length, 2, 'calls[0].args.length');
assert.sameValue(calls[0].args[0], 41, 'calls[0].args[0]');
assert.sameValue(calls[0].args[1], 0, 'calls[0].args[1]');
assert.sameValue(calls[0].thisArg, thisArg, 'calls[0].thisArg');
assert.sameValue(calls[1].args.length, 2, 'calls[1].args.length');
assert.sameValue(calls[1].args[0], 42, 'calls[1].args[0]');
assert.sameValue(calls[1].args[1], 1, 'calls[1].args[1]');
assert.sameValue(calls[1].thisArg, thisArg, 'calls[1].thisArg');
assert.sameValue(calls[2].args.length, 2, 'calls[2].args.length');
assert.sameValue(calls[2].args[0], 43, 'calls[2].args[0]');
assert.sameValue(calls[2].args[1], 2, 'calls[2].args[1]');
assert.sameValue(calls[2].thisArg, thisArg, 'calls[2].thisArg');
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Calling from with a valid map function with thisArg
info: >
22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
...
10. Let len be ToLength(Get(arrayLike, "length")).
11. ReturnIfAbrupt(len).
12. If IsConstructor(C) is true, then
a. Let A be Construct(C, «len»).
13. Else,
b. Let A be ArrayCreate(len).
14. ReturnIfAbrupt(A).
15. Let k be 0.
16. Repeat, while k < len
a. Let Pk be ToString(k).
b. Let kValue be Get(arrayLike, Pk).
c. ReturnIfAbrupt(kValue).
d. If mapping is true, then
i. Let mappedValue be Call(mapfn, T, «kValue, k»).
...
---*/
var list = {
'0': 41,
'1': 42,
'2': 43,
length: 3
};
var calls = [];
var thisArg = {};
function mapFn (value) {
calls.push({
args: arguments,
thisArg: this
});
return value * 2;
}
var result = Array.from(list, mapFn, thisArg);
assert.sameValue(result.length, 3, 'result.length');
assert.sameValue(result[0], 82, 'result[0]');
assert.sameValue(result[1], 84, 'result[1]');
assert.sameValue(result[2], 86, 'result[2]');
assert.sameValue(calls.length, 3, 'calls.length');
assert.sameValue(calls[0].args.length, 2, 'calls[0].args.length');
assert.sameValue(calls[0].args[0], 41, 'calls[0].args[0]');
assert.sameValue(calls[0].args[1], 0, 'calls[0].args[1]');
assert.sameValue(calls[0].thisArg, thisArg, 'calls[0].thisArg');
assert.sameValue(calls[1].args.length, 2, 'calls[1].args.length');
assert.sameValue(calls[1].args[0], 42, 'calls[1].args[0]');
assert.sameValue(calls[1].args[1], 1, 'calls[1].args[1]');
assert.sameValue(calls[1].thisArg, thisArg, 'calls[1].thisArg');
assert.sameValue(calls[2].args.length, 2, 'calls[2].args.length');
assert.sameValue(calls[2].args[0], 43, 'calls[2].args[0]');
assert.sameValue(calls[2].args[1], 2, 'calls[2].args[1]');
assert.sameValue(calls[2].thisArg, thisArg, 'calls[2].thisArg');

View File

@ -1,37 +1,38 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Elements added after the call to from
es6id: 22.1.2.1
---*/
var arrayIndex = -1;
var originalLength = 7;
var obj = {
length: originalLength,
0: 2,
1: 4,
2: 8,
3: 16,
4: 32,
5: 64,
6: 128
};
var array = [ 2, 4, 8, 16, 32, 64, 128 ];
function mapFn(value, index) {
arrayIndex++;
assert.sameValue(value, obj[arrayIndex], "Value mismatch in mapFn at index " + index + ".");
assert.sameValue(index, arrayIndex, "Index mismatch in mapFn.");
obj[originalLength + arrayIndex] = 2 * arrayIndex + 1;
return obj[arrayIndex];
}
var a = Array.from(obj, mapFn);
assert.sameValue(a.length, array.length, "Length mismatch.");
for (var j = 0; j < a.length; j++) {
assert.sameValue(a[j], array[j], "Element mismatch for array at index " + j + ".");
}
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Elements added after the call to from
esid: sec-array.from
es6id: 22.1.2.1
---*/
var arrayIndex = -1;
var originalLength = 7;
var obj = {
length: originalLength,
0: 2,
1: 4,
2: 8,
3: 16,
4: 32,
5: 64,
6: 128
};
var array = [ 2, 4, 8, 16, 32, 64, 128 ];
function mapFn(value, index) {
arrayIndex++;
assert.sameValue(value, obj[arrayIndex], "Value mismatch in mapFn at index " + index + ".");
assert.sameValue(index, arrayIndex, "Index mismatch in mapFn.");
obj[originalLength + arrayIndex] = 2 * arrayIndex + 1;
return obj[arrayIndex];
}
var a = Array.from(obj, mapFn);
assert.sameValue(a.length, array.length, "Length mismatch.");
for (var j = 0; j < a.length; j++) {
assert.sameValue(a[j], array[j], "Element mismatch for array at index " + j + ".");
}

View File

@ -1,31 +1,32 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: >
Elements deleted after the call started and before visited are not
visited
es6id: 22.1.2.1
---*/
var originalArray = [ 0, 1, -2, 4, -8, 16 ];
var array = [ 0, 1, -2, 4, -8, 16 ];
var a = [];
var arrayIndex = -1;
function mapFn(value, index) {
this.arrayIndex++;
assert.sameValue(value, array[this.arrayIndex], "Value mismatch in mapFn at index " + index + ".");
assert.sameValue(index, this.arrayIndex, "Index mismatch in mapFn.");
array.splice(array.length - 1, 1);
return 127;
}
a = Array.from(array, mapFn, this);
assert.sameValue(a.length, originalArray.length / 2, "Length mismatch. Old array : " + (originalArray.length / 2) + ". array : " + a.length + ".");
for (var j = 0; j < originalArray.length / 2; j++) {
assert.sameValue(a[j], 127, "Element mismatch for mapped array at index " + j + ".");
}
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: >
Elements deleted after the call started and before visited are not
visited
esid: sec-array.from
es6id: 22.1.2.1
---*/
var originalArray = [ 0, 1, -2, 4, -8, 16 ];
var array = [ 0, 1, -2, 4, -8, 16 ];
var a = [];
var arrayIndex = -1;
function mapFn(value, index) {
this.arrayIndex++;
assert.sameValue(value, array[this.arrayIndex], "Value mismatch in mapFn at index " + index + ".");
assert.sameValue(index, this.arrayIndex, "Index mismatch in mapFn.");
array.splice(array.length - 1, 1);
return 127;
}
a = Array.from(array, mapFn, this);
assert.sameValue(a.length, originalArray.length / 2, "Length mismatch. Old array : " + (originalArray.length / 2) + ". array : " + a.length + ".");
for (var j = 0; j < originalArray.length / 2; j++) {
assert.sameValue(a[j], 127, "Element mismatch for mapped array at index " + j + ".");
}

View File

@ -1,26 +1,27 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Elements are updated after the call to from
es6id: 22.1.2.1
---*/
var array = [ 127, 4, 8, 16, 32, 64, 128 ];
var arrayIndex = -1;
function mapFn(value, index) {
arrayIndex++;
if (index + 1 < array.length) {
array[index + 1] = 127;
}
assert.sameValue(value, 127, "Value mismatch in mapFn at index " + index + ".");
assert.sameValue(index, arrayIndex, "Index mismatch in mapFn.");
return value;
}
var a = Array.from(array, mapFn);
assert.sameValue(a.length, array.length, "Length mismatch.");
for (var j = 0; j < a.length; j++) {
assert.sameValue(a[j], 127, "Element mismatch for mapped array.");
}
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Elements are updated after the call to from
esid: sec-array.from
es6id: 22.1.2.1
---*/
var array = [ 127, 4, 8, 16, 32, 64, 128 ];
var arrayIndex = -1;
function mapFn(value, index) {
arrayIndex++;
if (index + 1 < array.length) {
array[index + 1] = 127;
}
assert.sameValue(value, 127, "Value mismatch in mapFn at index " + index + ".");
assert.sameValue(index, arrayIndex, "Index mismatch in mapFn.");
return value;
}
var a = Array.from(array, mapFn);
assert.sameValue(a.length, array.length, "Length mismatch.");
for (var j = 0; j < a.length; j++) {
assert.sameValue(a[j], 127, "Element mismatch for mapped array.");
}

View File

@ -1,23 +1,24 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Passing a valid array
es6id: 22.1.2.1
---*/
var array = [0, 'foo', , Infinity];
var result = Array.from(array);
assert.sameValue(result.length, 4, 'result.length');
assert.sameValue(result[0], 0, 'result[0]');
assert.sameValue(result[1], 'foo', 'result[1]');
assert.sameValue(result[2], undefined, 'result[2]');
assert.sameValue(result[3], Infinity, 'result[3]');
assert.notSameValue(
result, array,
'result is not the object from items argument'
);
assert(result instanceof Array, 'result instanceof Array');
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Passing a valid array
esid: sec-array.from
es6id: 22.1.2.1
---*/
var array = [0, 'foo', , Infinity];
var result = Array.from(array);
assert.sameValue(result.length, 4, 'result.length');
assert.sameValue(result[0], 0, 'result[0]');
assert.sameValue(result[1], 'foo', 'result[1]');
assert.sameValue(result[2], undefined, 'result[2]');
assert.sameValue(result[3], Infinity, 'result[3]');
assert.notSameValue(
result, array,
'result is not the object from items argument'
);
assert(result instanceof Array, 'result instanceof Array');

View File

@ -2,7 +2,8 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.1.2.1_T1
esid: sec-array.from
es6id: 22.1.2.1
description: Testing Array.from when passed a String
author: Hank Yates (hankyates@gmail.com)
---*/

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Error accessing items' `Symbol.iterator` attribute
info: >

View File

@ -1,6 +1,7 @@
// Copyright 2015 Leonardo Balter. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Return empty array if items argument is an ArrayBuffer
info: >

View File

@ -1,6 +1,7 @@
// Copyright 2015 Leonardo Balter. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Throws a TypeError if items argument is null
info: >

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Error advancing iterator
info: >

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: >
Error creating object with custom constructor (traversed via iterator)

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Creating object with custom constructor (traversed via iterator)
info: >

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Error creating iterator object
info: >

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Error retrieving value of iterator result
info: >

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: >
Arguments of mapping function (traversed via iterator)

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Error invoking map function (traversed via iterator)
info: >

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Value returned by mapping function (traversed via iterator)
info: >

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: >
`this` value of mapping function with custom `this` argument (traversed via iterator)

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: >
`this` value of mapping function in non-strict mode (traversed via iterator)

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: >
`this` value of mapping function in strict mode (traversed via iterator)

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Error setting property on result value (traversed via iterator)
info: >

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Setting property on result value (traversed via iterator)
info: >

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Error setting length of object (traversed via iterator)
info: >

View File

@ -1,6 +1,7 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Setting length of object (traversed via iterator)
info: >

View File

@ -1,34 +1,35 @@
// Copyright 2015 Leonardo Balter. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
es6id: 22.1.2.1
description: Throws a TypeError if mapFn is not callable
info: >
22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
...
2. If mapfn is undefined, let mapping be false.
3. else
a. If IsCallable(mapfn) is false, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Array.from([], null);
});
assert.throws(TypeError, function() {
Array.from([], {});
});
assert.throws(TypeError, function() {
Array.from([], 'string');
});
assert.throws(TypeError, function() {
Array.from([], true);
});
assert.throws(TypeError, function() {
Array.from([], 42);
});
// Copyright 2015 Leonardo Balter. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Throws a TypeError if mapFn is not callable
info: >
22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
...
2. If mapfn is undefined, let mapping be false.
3. else
a. If IsCallable(mapfn) is false, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Array.from([], null);
});
assert.throws(TypeError, function() {
Array.from([], {});
});
assert.throws(TypeError, function() {
Array.from([], 'string');
});
assert.throws(TypeError, function() {
Array.from([], true);
});
assert.throws(TypeError, function() {
Array.from([], 42);
});

View File

@ -1,6 +1,7 @@
// Copyright 2015 Leonardo Balter. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Throws a TypeError if mapFn is not callable (Symbol)
info: >

View File

@ -1,14 +1,15 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: mapFn throws an exception
es6id: 22.1.2.1
---*/
var array = [ 2, 4, 8, 16, 32, 64, 128 ];
function mapFn(value, index, obj) {
throw new Test262Error();
}
assert.throws(Test262Error, function(){Array.from(array, mapFn);});
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: mapFn throws an exception
esid: sec-array.from
es6id: 22.1.2.1
---*/
var array = [ 2, 4, 8, 16, 32, 64, 128 ];
function mapFn(value, index, obj) {
throw new Test262Error();
}
assert.throws(Test262Error, function(){Array.from(array, mapFn);});

View File

@ -1,26 +1,27 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Source array with boundary values
es6id: 22.1.2.1
---*/
var array = [ Number.MAX_VALUE, Number.MIN_VALUE, Number.NaN, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY ];
var arrayIndex = -1;
function mapFn(value, index) {
this.arrayIndex++;
assert.sameValue(value, array[this.arrayIndex], "Value mismatch in mapFn at index " + index + ".");
assert.sameValue(index, this.arrayIndex, "Index mismatch in mapFn.");
return value;
}
var a = Array.from(array, mapFn, this);
assert.sameValue(a.length, array.length, "Length mismatch.");
assert.sameValue(a[0], Number.MAX_VALUE, "Element mismatch for mapped array at index 0.");
assert.sameValue(a[1], Number.MIN_VALUE, "Element mismatch for mapped array at index 1.");
assert.sameValue(a[2], Number.NaN, "Element mismatch for mapped array at index 2.");
assert.sameValue(a[3], Number.NEGATIVE_INFINITY, "Element mismatch for mapped array at index 3.");
assert.sameValue(a[4], Number.POSITIVE_INFINITY, "Element mismatch for mapped array at index 4.");
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Source array with boundary values
esid: sec-array.from
es6id: 22.1.2.1
---*/
var array = [ Number.MAX_VALUE, Number.MIN_VALUE, Number.NaN, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY ];
var arrayIndex = -1;
function mapFn(value, index) {
this.arrayIndex++;
assert.sameValue(value, array[this.arrayIndex], "Value mismatch in mapFn at index " + index + ".");
assert.sameValue(index, this.arrayIndex, "Index mismatch in mapFn.");
return value;
}
var a = Array.from(array, mapFn, this);
assert.sameValue(a.length, array.length, "Length mismatch.");
assert.sameValue(a[0], Number.MAX_VALUE, "Element mismatch for mapped array at index 0.");
assert.sameValue(a[1], Number.MIN_VALUE, "Element mismatch for mapped array at index 1.");
assert.sameValue(a[2], Number.NaN, "Element mismatch for mapped array at index 2.");
assert.sameValue(a[3], Number.NEGATIVE_INFINITY, "Element mismatch for mapped array at index 3.");
assert.sameValue(a[4], Number.POSITIVE_INFINITY, "Element mismatch for mapped array at index 4.");

View File

@ -1,10 +1,11 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: >
Array.from uses a constructor other than Array.
es6id: 22.1.2.1
---*/
assert.sameValue(Array.from.call(Object, []).constructor, Object);
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: >
Array.from uses a constructor other than Array.
esid: sec-array.from
es6id: 22.1.2.1
---*/
assert.sameValue(Array.from.call(Object, []).constructor, Object);

View File

@ -1,28 +1,29 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Source object has iterator which throws
es6id: 22.1.2.1
---*/
var array = [ 2, 4, 8, 16, 32, 64, 128 ];
var obj = {
[Symbol.iterator]() {
return {
index: 0,
next() {
throw new Test262Error();
},
isDone : false,
get val() {
this.index++;
if (this.index > 7) {
this.isDone = true;
}
return 1 << this.index;
}
};
}
};
assert.throws(Test262Error, function(){Array.from(obj);});
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Source object has iterator which throws
esid: sec-array.from
es6id: 22.1.2.1
---*/
var array = [ 2, 4, 8, 16, 32, 64, 128 ];
var obj = {
[Symbol.iterator]() {
return {
index: 0,
next() {
throw new Test262Error();
},
isDone : false,
get val() {
this.index++;
if (this.index > 7) {
this.isDone = true;
}
return 1 << this.index;
}
};
}
};
assert.throws(Test262Error, function(){Array.from(obj);});

View File

@ -1,35 +1,36 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Source object has iterator
es6id: 22.1.2.1
---*/
var array = [ 2, 4, 8, 16, 32, 64, 128 ];
var obj = {
[Symbol.iterator]() {
return {
index: 0,
next() {
return {
value: this.val,
done: this.isDone
};
},
isDone : false,
get val() {
this.index++;
if (this.index > 7) {
this.isDone = true;
}
return 1 << this.index;
}
};
}
};
var a = Array.from.call(Object, obj);
assert.sameValue(typeof a, typeof {}, "The returned type is expected to be object.");
for (var j = 0; j < a.length; j++) {
assert.sameValue(a[j], array[j], "Elements mismatch at " + j + ".");
}
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Source object has iterator
esid: sec-array.from
es6id: 22.1.2.1
---*/
var array = [ 2, 4, 8, 16, 32, 64, 128 ];
var obj = {
[Symbol.iterator]() {
return {
index: 0,
next() {
return {
value: this.val,
done: this.isDone
};
},
isDone : false,
get val() {
this.index++;
if (this.index > 7) {
this.isDone = true;
}
return 1 << this.index;
}
};
}
};
var a = Array.from.call(Object, obj);
assert.sameValue(typeof a, typeof {}, "The returned type is expected to be object.");
for (var j = 0; j < a.length; j++) {
assert.sameValue(a[j], array[j], "Elements mismatch at " + j + ".");
}

View File

@ -1,24 +1,25 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: >
Source is an object with length property and one item is deleted
from the source
es6id: 22.1.2.1
---*/
var array = [2, 4, 0, 16];
var expectedArray = [2, 4, , 16];
var obj = {
length : 4,
0 : 2,
1 : 4,
2 : 0,
3 : 16
};
delete obj[2];
var a = Array.from(obj);
for (var j = 0; j < expectedArray.length; j++) {
assert.sameValue(a[j], expectedArray[j], "Elements mismatch at " + j + ".");
}
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: >
Source is an object with length property and one item is deleted
from the source
esid: sec-array.from
es6id: 22.1.2.1
---*/
var array = [2, 4, 0, 16];
var expectedArray = [2, 4, , 16];
var obj = {
length : 4,
0 : 2,
1 : 4,
2 : 0,
3 : 16
};
delete obj[2];
var a = Array.from(obj);
for (var j = 0; j < expectedArray.length; j++) {
assert.sameValue(a[j], expectedArray[j], "Elements mismatch at " + j + ".");
}

View File

@ -1,21 +1,22 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Source is an object with missing values
es6id: 22.1.2.1
---*/
var array = [2, 4, , 16];
var obj = {
length: 4,
0: 2,
1: 4,
3: 16
};
var a = Array.from.call(Object, obj);
assert.sameValue(typeof a, "object", "The returned type is expected to be object.");
for (var j = 0; j < a.length; j++) {
assert.sameValue(a[j], array[j], "Elements mismatch at " + j + ".");
}
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Source is an object with missing values
esid: sec-array.from
es6id: 22.1.2.1
---*/
var array = [2, 4, , 16];
var obj = {
length: 4,
0: 2,
1: 4,
3: 16
};
var a = Array.from.call(Object, obj);
assert.sameValue(typeof a, "object", "The returned type is expected to be object.");
for (var j = 0; j < a.length; j++) {
assert.sameValue(a[j], array[j], "Elements mismatch at " + j + ".");
}

View File

@ -1,17 +1,18 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Source is an object without length property
es6id: 22.1.2.1
---*/
var obj = {
0: 2,
1: 4,
2: 8,
3: 16
}
var a = Array.from(obj);
assert.sameValue(a.length, 0, "Expected an array of length 0.");
// Copyright 2015 Microsoft Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Source is an object without length property
esid: sec-array.from
es6id: 22.1.2.1
---*/
var obj = {
0: 2,
1: 4,
2: 8,
3: 16
}
var a = Array.from(obj);
assert.sameValue(a.length, 0, "Expected an array of length 0.");

View File

@ -1,11 +1,12 @@
// Copyright 2015 Leonardo Balter. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
es6id: 22.1.2.1
description: Does not throw if this is null
---*/
var result = Array.from.call(null, []);
assert(result instanceof Array, 'Does not throw if this is null');
assert.sameValue(result.length, 0, 'result.length');
// Copyright 2015 Leonardo Balter. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-array.from
es6id: 22.1.2.1
description: Does not throw if this is null
---*/
var result = Array.from.call(null, []);
assert(result instanceof Array, 'Does not throw if this is null');
assert.sameValue(result.length, 0, 'result.length');