summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/from
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/from')
-rw-r--r--js/src/tests/test262/built-ins/Array/from/Array.from-descriptor.js14
-rw-r--r--js/src/tests/test262/built-ins/Array/from/Array.from-name.js32
-rw-r--r--js/src/tests/test262/built-ins/Array/from/Array.from_arity.js23
-rw-r--r--js/src/tests/test262/built-ins/Array/from/Array.from_forwards-length-for-array-likes.js41
-rw-r--r--js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js41
-rw-r--r--js/src/tests/test262/built-ins/Array/from/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/Array/from/calling-from-valid-1-noStrict.js68
-rw-r--r--js/src/tests/test262/built-ins/Array/from/calling-from-valid-1-onlyStrict-strict.js69
-rw-r--r--js/src/tests/test262/built-ins/Array/from/calling-from-valid-2.js69
-rw-r--r--js/src/tests/test262/built-ins/Array/from/elements-added-after.js40
-rw-r--r--js/src/tests/test262/built-ins/Array/from/elements-deleted-after.js34
-rw-r--r--js/src/tests/test262/built-ins/Array/from/elements-updated-after.js29
-rw-r--r--js/src/tests/test262/built-ins/Array/from/from-array.js25
-rw-r--r--js/src/tests/test262/built-ins/Array/from/from-string.js19
-rw-r--r--js/src/tests/test262/built-ins/Array/from/get-iter-method-err.js24
-rw-r--r--js/src/tests/test262/built-ins/Array/from/items-is-arraybuffer.js21
-rw-r--r--js/src/tests/test262/built-ins/Array/from/items-is-null-throws.js19
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-adv-err.js30
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-cstm-ctor-err.js28
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-cstm-ctor.js50
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-get-iter-err.js24
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-get-iter-val-err.js36
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-map-fn-args.js73
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-map-fn-err.js43
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-map-fn-return.js72
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-arg.js59
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-non-strict.js62
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-strict-strict.js60
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop-err.js54
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop-non-writable.js45
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop.js60
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-set-length-err.js39
-rw-r--r--js/src/tests/test262/built-ins/Array/from/iter-set-length.js48
-rw-r--r--js/src/tests/test262/built-ins/Array/from/mapfn-is-not-callable-typeerror.js36
-rw-r--r--js/src/tests/test262/built-ins/Array/from/mapfn-is-symbol-throws.js22
-rw-r--r--js/src/tests/test262/built-ins/Array/from/mapfn-throws-exception.js20
-rw-r--r--js/src/tests/test262/built-ins/Array/from/not-a-constructor.js31
-rw-r--r--js/src/tests/test262/built-ins/Array/from/proto-from-ctor-realm.js37
-rw-r--r--js/src/tests/test262/built-ins/Array/from/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/Array/from/source-array-boundary.js30
-rw-r--r--js/src/tests/test262/built-ins/Array/from/source-object-constructor.js17
-rw-r--r--js/src/tests/test262/built-ins/Array/from/source-object-iterator-1.js34
-rw-r--r--js/src/tests/test262/built-ins/Array/from/source-object-iterator-2.js39
-rw-r--r--js/src/tests/test262/built-ins/Array/from/source-object-length-set-elem-prop-err.js54
-rw-r--r--js/src/tests/test262/built-ins/Array/from/source-object-length-set-elem-prop-non-writable.js48
-rw-r--r--js/src/tests/test262/built-ins/Array/from/source-object-length.js27
-rw-r--r--js/src/tests/test262/built-ins/Array/from/source-object-missing.js24
-rw-r--r--js/src/tests/test262/built-ins/Array/from/source-object-without.js20
-rw-r--r--js/src/tests/test262/built-ins/Array/from/this-null.js14
49 files changed, 1804 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/from/Array.from-descriptor.js b/js/src/tests/test262/built-ins/Array/from/Array.from-descriptor.js
new file mode 100644
index 0000000000..4d68536a30
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/Array.from-descriptor.js
@@ -0,0 +1,14 @@
+// Copyright 2015 Microsoft Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+description: Testing descriptor property of Array.from
+includes: [propertyHelper.js]
+esid: sec-array.from
+---*/
+
+verifyWritable(Array, "from");
+verifyNotEnumerable(Array, "from");
+verifyConfigurable(Array, "from");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/Array.from-name.js b/js/src/tests/test262/built-ins/Array/from/Array.from-name.js
new file mode 100644
index 0000000000..267647c639
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/Array.from-name.js
@@ -0,0 +1,32 @@
+// Copyright 2015 Microsoft Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+/*---
+esid: sec-array.from
+description: '`name` property'
+info: |
+ ES6 Section 17:
+
+ Every built-in Function object, including constructors, that is not
+ identified as an anonymous function has a name property whose value is a
+ String. Unless otherwise specified, this value is the name that is given to
+ the function in this specification.
+
+ [...]
+
+ Unless otherwise specified, the name property of a built-in Function
+ object, if it exists, has the attributes { [[Writable]]: false,
+ [[Enumerable]]: false, [[Configurable]]: true }.
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+ Array.from.name,
+ 'from',
+ 'The value of Array.from.name is expected to be "from"'
+);
+
+verifyNotEnumerable(Array.from, 'name');
+verifyNotWritable(Array.from, 'name');
+verifyConfigurable(Array.from, 'name');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/Array.from_arity.js b/js/src/tests/test262/built-ins/Array/from/Array.from_arity.js
new file mode 100644
index 0000000000..68b3287765
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/Array.from_arity.js
@@ -0,0 +1,23 @@
+// Copyright (c) 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+/*---
+esid: sec-array.from
+description: >
+ The length property of the Array.from method is 1.
+info: |
+ 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
+
+ ...
+
+ The length property of the from method is 1.
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(Array.from.length, 1, 'The value of Array.from.length is expected to be 1');
+
+verifyNotEnumerable(Array.from, 'length');
+verifyNotWritable(Array.from, 'length');
+verifyConfigurable(Array.from, 'length');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/Array.from_forwards-length-for-array-likes.js b/js/src/tests/test262/built-ins/Array/from/Array.from_forwards-length-for-array-likes.js
new file mode 100644
index 0000000000..8bb73635ee
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/Array.from_forwards-length-for-array-likes.js
@@ -0,0 +1,41 @@
+// Copyright (c) 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+/*---
+esid: sec-array.from
+description: >
+ If this is a constructor, and items doesn't have an @@iterator,
+ returns a new instance of this
+info: |
+ 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
+
+ 4. Let usingIterator be GetMethod(items, @@iterator).
+ ...
+ 6. If usingIterator is not undefined, then
+ ...
+ 12. If IsConstructor(C) is true, then
+ a. Let A be Construct(C, «len»).
+ 13. Else,
+ a. Let A be ArrayCreate(len).
+ ...
+ 19. Return A.
+---*/
+
+var result;
+
+function MyCollection() {
+ this.args = arguments;
+}
+
+result = Array.from.call(MyCollection, {
+ length: 42
+});
+
+assert.sameValue(result.args.length, 1, 'The value of result.args.length is expected to be 1');
+assert.sameValue(result.args[0], 42, 'The value of result.args[0] is expected to be 42');
+assert(
+ result instanceof MyCollection,
+ 'The result of evaluating (result instanceof MyCollection) is expected to be true'
+);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js b/js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js
new file mode 100644
index 0000000000..e83db0f656
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js
@@ -0,0 +1,41 @@
+// Copyright (c) 2021 Rick Waldron. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+esid: sec-array.from
+description: >
+ Creates an array with length that is equal to the value of the
+ length property of the given array-like, regardless of
+ the presence of corresponding indices and values.
+info: |
+ Array.from ( items [ , mapfn [ , thisArg ] ] )
+
+ 7. Let arrayLike be ! ToObject(items).
+ 8. Let len be ? LengthOfArrayLike(arrayLike).
+ 9. If IsConstructor(C) is true, then
+ a. Let A be ? Construct(C, « 𝔽(len) »).
+ 10. Else,
+ a. Let A be ? ArrayCreate(len).
+
+includes: [compareArray.js]
+---*/
+
+const length = 5;
+
+const newlyCreatedArray = Array.from({ length });
+assert.sameValue(
+ newlyCreatedArray.length,
+ length,
+ "The newly created array's length is equal to the value of the length property for the provided array like object"
+);
+assert.compareArray(newlyCreatedArray, [undefined, undefined, undefined, undefined, undefined]);
+
+const newlyCreatedAndMappedArray = Array.from({ length }).map(x => 1);
+assert.sameValue(
+ newlyCreatedAndMappedArray.length,
+ length,
+ "The newly created and mapped array's length is equal to the value of the length property for the provided array like object"
+);
+assert.compareArray(newlyCreatedAndMappedArray, [1, 1, 1, 1, 1]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/browser.js b/js/src/tests/test262/built-ins/Array/from/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/browser.js
diff --git a/js/src/tests/test262/built-ins/Array/from/calling-from-valid-1-noStrict.js b/js/src/tests/test262/built-ins/Array/from/calling-from-valid-1-noStrict.js
new file mode 100644
index 0000000000..21eb245493
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/calling-from-valid-1-noStrict.js
@@ -0,0 +1,68 @@
+// Copyright 2015 Microsoft Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+/*---
+esid: sec-array.from
+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, 'The value of result.length is expected to be 3');
+assert.sameValue(result[0], 82, 'The value of result[0] is expected to be 82');
+assert.sameValue(result[1], 84, 'The value of result[1] is expected to be 84');
+assert.sameValue(result[2], 86, 'The value of result[2] is expected to be 86');
+
+assert.sameValue(calls.length, 3, 'The value of calls.length is expected to be 3');
+
+assert.sameValue(calls[0].args.length, 2, 'The value of calls[0].args.length is expected to be 2');
+assert.sameValue(calls[0].args[0], 41, 'The value of calls[0].args[0] is expected to be 41');
+assert.sameValue(calls[0].args[1], 0, 'The value of calls[0].args[1] is expected to be 0');
+assert.sameValue(calls[0].thisArg, this, 'The value of calls[0].thisArg is expected to be this');
+
+assert.sameValue(calls[1].args.length, 2, 'The value of calls[1].args.length is expected to be 2');
+assert.sameValue(calls[1].args[0], 42, 'The value of calls[1].args[0] is expected to be 42');
+assert.sameValue(calls[1].args[1], 1, 'The value of calls[1].args[1] is expected to be 1');
+assert.sameValue(calls[1].thisArg, this, 'The value of calls[1].thisArg is expected to be this');
+
+assert.sameValue(calls[2].args.length, 2, 'The value of calls[2].args.length is expected to be 2');
+assert.sameValue(calls[2].args[0], 43, 'The value of calls[2].args[0] is expected to be 43');
+assert.sameValue(calls[2].args[1], 2, 'The value of calls[2].args[1] is expected to be 2');
+assert.sameValue(calls[2].thisArg, this, 'The value of calls[2].thisArg is expected to be this');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/calling-from-valid-1-onlyStrict-strict.js b/js/src/tests/test262/built-ins/Array/from/calling-from-valid-1-onlyStrict-strict.js
new file mode 100644
index 0000000000..415c0f8a35
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/calling-from-valid-1-onlyStrict-strict.js
@@ -0,0 +1,69 @@
+'use strict';
+// Copyright 2015 Microsoft Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+/*---
+esid: sec-array.from
+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, 'The value of result.length is expected to be 3');
+assert.sameValue(result[0], 82, 'The value of result[0] is expected to be 82');
+assert.sameValue(result[1], 84, 'The value of result[1] is expected to be 84');
+assert.sameValue(result[2], 86, 'The value of result[2] is expected to be 86');
+
+assert.sameValue(calls.length, 3, 'The value of calls.length is expected to be 3');
+
+assert.sameValue(calls[0].args.length, 2, 'The value of calls[0].args.length is expected to be 2');
+assert.sameValue(calls[0].args[0], 41, 'The value of calls[0].args[0] is expected to be 41');
+assert.sameValue(calls[0].args[1], 0, 'The value of calls[0].args[1] is expected to be 0');
+assert.sameValue(calls[0].thisArg, undefined, 'The value of calls[0].thisArg is expected to equal undefined');
+
+assert.sameValue(calls[1].args.length, 2, 'The value of calls[1].args.length is expected to be 2');
+assert.sameValue(calls[1].args[0], 42, 'The value of calls[1].args[0] is expected to be 42');
+assert.sameValue(calls[1].args[1], 1, 'The value of calls[1].args[1] is expected to be 1');
+assert.sameValue(calls[1].thisArg, undefined, 'The value of calls[1].thisArg is expected to equal undefined');
+
+assert.sameValue(calls[2].args.length, 2, 'The value of calls[2].args.length is expected to be 2');
+assert.sameValue(calls[2].args[0], 43, 'The value of calls[2].args[0] is expected to be 43');
+assert.sameValue(calls[2].args[1], 2, 'The value of calls[2].args[1] is expected to be 2');
+assert.sameValue(calls[2].thisArg, undefined, 'The value of calls[2].thisArg is expected to equal undefined');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/calling-from-valid-2.js b/js/src/tests/test262/built-ins/Array/from/calling-from-valid-2.js
new file mode 100644
index 0000000000..835f3d3b97
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/calling-from-valid-2.js
@@ -0,0 +1,69 @@
+// Copyright 2015 Microsoft Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+esid: sec-array.from
+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, 'The value of result.length is expected to be 3');
+assert.sameValue(result[0], 82, 'The value of result[0] is expected to be 82');
+assert.sameValue(result[1], 84, 'The value of result[1] is expected to be 84');
+assert.sameValue(result[2], 86, 'The value of result[2] is expected to be 86');
+
+assert.sameValue(calls.length, 3, 'The value of calls.length is expected to be 3');
+
+assert.sameValue(calls[0].args.length, 2, 'The value of calls[0].args.length is expected to be 2');
+assert.sameValue(calls[0].args[0], 41, 'The value of calls[0].args[0] is expected to be 41');
+assert.sameValue(calls[0].args[1], 0, 'The value of calls[0].args[1] is expected to be 0');
+assert.sameValue(calls[0].thisArg, thisArg, 'The value of calls[0].thisArg is expected to equal the value of thisArg');
+
+assert.sameValue(calls[1].args.length, 2, 'The value of calls[1].args.length is expected to be 2');
+assert.sameValue(calls[1].args[0], 42, 'The value of calls[1].args[0] is expected to be 42');
+assert.sameValue(calls[1].args[1], 1, 'The value of calls[1].args[1] is expected to be 1');
+assert.sameValue(calls[1].thisArg, thisArg, 'The value of calls[1].thisArg is expected to equal the value of thisArg');
+
+assert.sameValue(calls[2].args.length, 2, 'The value of calls[2].args.length is expected to be 2');
+assert.sameValue(calls[2].args[0], 43, 'The value of calls[2].args[0] is expected to be 43');
+assert.sameValue(calls[2].args[1], 2, 'The value of calls[2].args[1] is expected to be 2');
+assert.sameValue(calls[2].thisArg, thisArg, 'The value of calls[2].thisArg is expected to equal the value of thisArg');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/elements-added-after.js b/js/src/tests/test262/built-ins/Array/from/elements-added-after.js
new file mode 100644
index 0000000000..7676448d32
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/elements-added-after.js
@@ -0,0 +1,40 @@
+// 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
+---*/
+
+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], 'The value of value is expected to equal the value of obj[arrayIndex]');
+ assert.sameValue(index, arrayIndex, 'The value of index is expected to equal the value of arrayIndex');
+ obj[originalLength + arrayIndex] = 2 * arrayIndex + 1;
+
+ return obj[arrayIndex];
+}
+
+
+var a = Array.from(obj, mapFn);
+assert.sameValue(a.length, array.length, 'The value of a.length is expected to equal the value of array.length');
+
+for (var j = 0; j < a.length; j++) {
+ assert.sameValue(a[j], array[j], 'The value of a[j] is expected to equal the value of array[j]');
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/elements-deleted-after.js b/js/src/tests/test262/built-ins/Array/from/elements-deleted-after.js
new file mode 100644
index 0000000000..5b63a932aa
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/elements-deleted-after.js
@@ -0,0 +1,34 @@
+// 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
+---*/
+
+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], 'The value of value is expected to equal the value of array[this.arrayIndex]');
+ assert.sameValue(index, this.arrayIndex, 'The value of index is expected to equal the value of this.arrayIndex');
+
+ array.splice(array.length - 1, 1);
+ return 127;
+}
+
+
+a = Array.from(array, mapFn, this);
+
+assert.sameValue(a.length, originalArray.length / 2, 'The value of a.length is expected to be originalArray.length / 2');
+
+for (var j = 0; j < originalArray.length / 2; j++) {
+ assert.sameValue(a[j], 127, 'The value of a[j] is expected to be 127');
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/elements-updated-after.js b/js/src/tests/test262/built-ins/Array/from/elements-updated-after.js
new file mode 100644
index 0000000000..210aaf5fd4
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/elements-updated-after.js
@@ -0,0 +1,29 @@
+// 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
+---*/
+
+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, 'The value of value is expected to be 127');
+ assert.sameValue(index, arrayIndex, 'The value of index is expected to equal the value of arrayIndex');
+
+ return value;
+}
+
+var a = Array.from(array, mapFn);
+assert.sameValue(a.length, array.length, 'The value of a.length is expected to equal the value of array.length');
+for (var j = 0; j < a.length; j++) {
+ assert.sameValue(a[j], 127, 'The value of a[j] is expected to be 127');
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/from-array.js b/js/src/tests/test262/built-ins/Array/from/from-array.js
new file mode 100644
index 0000000000..708a4779bc
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/from-array.js
@@ -0,0 +1,25 @@
+// 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
+---*/
+
+var array = [0, 'foo', , Infinity];
+var result = Array.from(array);
+
+assert.sameValue(result.length, 4, 'The value of result.length is expected to be 4');
+assert.sameValue(result[0], 0, 'The value of result[0] is expected to be 0');
+assert.sameValue(result[1], 'foo', 'The value of result[1] is expected to be "foo"');
+assert.sameValue(result[2], undefined, 'The value of result[2] is expected to equal undefined');
+assert.sameValue(result[3], Infinity, 'The value of result[3] is expected to equal Infinity');
+
+assert.notSameValue(
+ result, array,
+ 'The value of result is expected to not equal the value of `array`'
+);
+
+assert(result instanceof Array, 'The result of evaluating (result instanceof Array) is expected to be true');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/from-string.js b/js/src/tests/test262/built-ins/Array/from/from-string.js
new file mode 100644
index 0000000000..88772a85ec
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/from-string.js
@@ -0,0 +1,19 @@
+// Copyright (c) 2014 Hank Yates. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-array.from
+description: Testing Array.from when passed a String
+author: Hank Yates (hankyates@gmail.com)
+---*/
+
+var arrLikeSource = 'Test';
+var result = Array.from(arrLikeSource);
+
+assert.sameValue(result.length, 4, 'The value of result.length is expected to be 4');
+assert.sameValue(result[0], 'T', 'The value of result[0] is expected to be "T"');
+assert.sameValue(result[1], 'e', 'The value of result[1] is expected to be "e"');
+assert.sameValue(result[2], 's', 'The value of result[2] is expected to be "s"');
+assert.sameValue(result[3], 't', 'The value of result[3] is expected to be "t"');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/get-iter-method-err.js b/js/src/tests/test262/built-ins/Array/from/get-iter-method-err.js
new file mode 100644
index 0000000000..c7795c53d1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/get-iter-method-err.js
@@ -0,0 +1,24 @@
+// 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
+description: Error accessing items' `Symbol.iterator` attribute
+info: |
+ [...]
+ 4. Let usingIterator be GetMethod(items, @@iterator).
+ 5. ReturnIfAbrupt(usingIterator).
+features: [Symbol.iterator]
+---*/
+
+var items = {};
+Object.defineProperty(items, Symbol.iterator, {
+ get: function() {
+ throw new Test262Error();
+ }
+});
+
+assert.throws(Test262Error, function() {
+ Array.from(items);
+}, 'Array.from(items) throws a Test262Error exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/items-is-arraybuffer.js b/js/src/tests/test262/built-ins/Array/from/items-is-arraybuffer.js
new file mode 100644
index 0000000000..6a93179741
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/items-is-arraybuffer.js
@@ -0,0 +1,21 @@
+// Copyright 2015 Leonardo Balter. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+/*---
+esid: sec-array.from
+description: Return empty array if items argument is an ArrayBuffer
+info: |
+ 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
+
+ ...
+ 4. Let usingIterator be GetMethod(items, @@iterator).
+ 5. ReturnIfAbrupt(usingIterator).
+ ...
+---*/
+
+var arrayBuffer = new ArrayBuffer(7);
+
+var result = Array.from(arrayBuffer);
+
+assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/items-is-null-throws.js b/js/src/tests/test262/built-ins/Array/from/items-is-null-throws.js
new file mode 100644
index 0000000000..4142bc2553
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/items-is-null-throws.js
@@ -0,0 +1,19 @@
+// Copyright 2015 Leonardo Balter. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+/*---
+esid: sec-array.from
+description: Throws a TypeError if items argument is null
+info: |
+ 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
+
+ ...
+ 4. Let usingIterator be GetMethod(items, @@iterator).
+ 5. ReturnIfAbrupt(usingIterator).
+ ...
+---*/
+
+assert.throws(TypeError, function() {
+ Array.from(null);
+}, 'Array.from(null) throws a TypeError exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-adv-err.js b/js/src/tests/test262/built-ins/Array/from/iter-adv-err.js
new file mode 100644
index 0000000000..66030a8e68
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-adv-err.js
@@ -0,0 +1,30 @@
+// 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
+description: Error advancing iterator
+info: |
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ i. Let Pk be ToString(k).
+ ii. Let next be IteratorStep(iterator).
+ iii. ReturnIfAbrupt(next).
+features: [Symbol.iterator]
+---*/
+
+var items = {};
+items[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ throw new Test262Error();
+ }
+ };
+};
+
+assert.throws(Test262Error, function() {
+ Array.from(items);
+}, 'Array.from(items) throws a Test262Error exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-cstm-ctor-err.js b/js/src/tests/test262/built-ins/Array/from/iter-cstm-ctor-err.js
new file mode 100644
index 0000000000..5b54e6d9e9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-cstm-ctor-err.js
@@ -0,0 +1,28 @@
+// 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
+description: >
+ Error creating object with custom constructor (traversed via iterator)
+info: |
+ [...]
+ 6. If usingIterator is not undefined, then
+ a. If IsConstructor(C) is true, then
+ i. Let A be Construct(C).
+ b. Else,
+ i. Let A be ArrayCreate(0).
+ c. ReturnIfAbrupt(A).
+features: [Symbol.iterator]
+---*/
+
+var C = function() {
+ throw new Test262Error();
+};
+var items = {};
+items[Symbol.iterator] = function() {};
+
+assert.throws(Test262Error, function() {
+ Array.from.call(C, items);
+}, 'Array.from.call(C, items) throws a Test262Error exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-cstm-ctor.js b/js/src/tests/test262/built-ins/Array/from/iter-cstm-ctor.js
new file mode 100644
index 0000000000..28922e7062
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-cstm-ctor.js
@@ -0,0 +1,50 @@
+// 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
+description: Creating object with custom constructor (traversed via iterator)
+info: |
+ [...]
+ 6. If usingIterator is not undefined, then
+ a. If IsConstructor(C) is true, then
+ i. Let A be Construct(C).
+ b. Else,
+ i. Let A be ArrayCreate(0).
+ c. ReturnIfAbrupt(A).
+features: [Symbol.iterator]
+---*/
+
+var thisVal, args;
+var callCount = 0;
+var C = function() {
+ thisVal = this;
+ args = arguments;
+ callCount += 1;
+};
+var result;
+var items = {};
+items[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ return {
+ done: true
+ };
+ }
+ };
+};
+
+result = Array.from.call(C, items);
+
+assert(
+ result instanceof C, 'The result of evaluating (result instanceof C) is expected to be true'
+);
+assert.sameValue(
+ result.constructor,
+ C,
+ 'The value of result.constructor is expected to equal the value of C'
+);
+assert.sameValue(callCount, 1, 'The value of callCount is expected to be 1');
+assert.sameValue(thisVal, result, 'The value of thisVal is expected to equal the value of result');
+assert.sameValue(args.length, 0, 'The value of args.length is expected to be 0');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-get-iter-err.js b/js/src/tests/test262/built-ins/Array/from/iter-get-iter-err.js
new file mode 100644
index 0000000000..278207b6b8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-get-iter-err.js
@@ -0,0 +1,24 @@
+// 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
+description: Error creating iterator object
+info: |
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ d. Let iterator be GetIterator(items, usingIterator).
+ e. ReturnIfAbrupt(iterator).
+features: [Symbol.iterator]
+---*/
+
+var itemsPoisonedSymbolIterator = {};
+itemsPoisonedSymbolIterator[Symbol.iterator] = function() {
+ throw new Test262Error();
+};
+
+assert.throws(Test262Error, function() {
+ Array.from(itemsPoisonedSymbolIterator);
+}, 'Array.from(itemsPoisonedSymbolIterator) throws a Test262Error exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-get-iter-val-err.js b/js/src/tests/test262/built-ins/Array/from/iter-get-iter-val-err.js
new file mode 100644
index 0000000000..c7ce81ce0b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-get-iter-val-err.js
@@ -0,0 +1,36 @@
+// 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
+description: Error retrieving value of iterator result
+info: |
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ v. Let nextValue be IteratorValue(next).
+ vi. ReturnIfAbrupt(nextValue).
+features: [Symbol.iterator]
+---*/
+
+var itemsPoisonedIteratorValue = {};
+var poisonedValue = {};
+Object.defineProperty(poisonedValue, 'value', {
+ get: function() {
+ throw new Test262Error();
+ }
+});
+itemsPoisonedIteratorValue[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ return poisonedValue;
+ }
+ };
+};
+
+assert.throws(Test262Error, function() {
+ Array.from(itemsPoisonedIteratorValue);
+}, 'Array.from(itemsPoisonedIteratorValue) throws a Test262Error exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-map-fn-args.js b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-args.js
new file mode 100644
index 0000000000..bab7631d3f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-args.js
@@ -0,0 +1,73 @@
+// 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
+description: >
+ Arguments of mapping function (traversed via iterator)
+info: |
+ [...]
+ 2. If mapfn is undefined, let mapping be false.
+ 3. else
+ a. If IsCallable(mapfn) is false, throw a TypeError exception.
+ b. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ c. Let mapping be true
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ vii. If mapping is true, then
+ 1. Let mappedValue be Call(mapfn, T, «nextValue, k»).
+ 2. If mappedValue is an abrupt completion, return
+ IteratorClose(iterator, mappedValue).
+ 3. Let mappedValue be mappedValue.[[value]].
+features: [Symbol.iterator]
+---*/
+
+var args = [];
+var firstResult = {
+ done: false,
+ value: {}
+};
+var secondResult = {
+ done: false,
+ value: {}
+};
+var mapFn = function(value, idx) {
+ args.push(arguments);
+};
+var items = {};
+var nextResult = firstResult;
+var nextNextResult = secondResult;
+
+items[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ var result = nextResult;
+ nextResult = nextNextResult;
+ nextNextResult = {
+ done: true
+ };
+
+ return result;
+ }
+ };
+};
+
+Array.from(items, mapFn);
+
+assert.sameValue(args.length, 2, 'The value of args.length is expected to be 2');
+
+assert.sameValue(args[0].length, 2, 'The value of args[0].length is expected to be 2');
+assert.sameValue(
+ args[0][0], firstResult.value, 'The value of args[0][0] is expected to equal the value of firstResult.value'
+);
+assert.sameValue(args[0][1], 0, 'The value of args[0][1] is expected to be 0');
+
+assert.sameValue(args[1].length, 2, 'The value of args[1].length is expected to be 2');
+assert.sameValue(
+ args[1][0], secondResult.value, 'The value of args[1][0] is expected to equal the value of secondResult.value'
+);
+assert.sameValue(args[1][1], 1, 'The value of args[1][1] is expected to be 1');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-map-fn-err.js b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-err.js
new file mode 100644
index 0000000000..beeca8e4eb
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-err.js
@@ -0,0 +1,43 @@
+// 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
+description: Error invoking map function (traversed via iterator)
+info: |
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ vii. If mapping is true, then
+ 1. Let mappedValue be Call(mapfn, T, «nextValue, k»).
+ 2. If mappedValue is an abrupt completion, return
+ IteratorClose(iterator, mappedValue).
+features: [Symbol.iterator]
+---*/
+
+var closeCount = 0;
+var mapFn = function() {
+ throw new Test262Error();
+};
+var items = {};
+items[Symbol.iterator] = function() {
+ return {
+ return: function() {
+ closeCount += 1;
+ },
+ next: function() {
+ return {
+ done: false
+ };
+ }
+ };
+};
+
+assert.throws(Test262Error, function() {
+ Array.from(items, mapFn);
+}, 'Array.from(items, mapFn) throws a Test262Error exception');
+
+assert.sameValue(closeCount, 1, 'The value of closeCount is expected to be 1');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-map-fn-return.js b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-return.js
new file mode 100644
index 0000000000..075bc6cd30
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-return.js
@@ -0,0 +1,72 @@
+// 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
+description: Value returned by mapping function (traversed via iterator)
+info: |
+ [...]
+ 2. If mapfn is undefined, let mapping be false.
+ 3. else
+ a. If IsCallable(mapfn) is false, throw a TypeError exception.
+ b. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ c. Let mapping be true
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ vii. If mapping is true, then
+ 1. Let mappedValue be Call(mapfn, T, «nextValue, k»).
+ 2. If mappedValue is an abrupt completion, return
+ IteratorClose(iterator, mappedValue).
+ 3. Let mappedValue be mappedValue.[[value]].
+features: [Symbol.iterator]
+---*/
+
+var thisVals = [];
+var nextResult = {
+ done: false,
+ value: {}
+};
+var nextNextResult = {
+ done: false,
+ value: {}
+};
+var firstReturnVal = {};
+var secondReturnVal = {};
+var mapFn = function(value, idx) {
+ var returnVal = nextReturnVal;
+ nextReturnVal = nextNextReturnVal;
+ nextNextReturnVal = null;
+ return returnVal;
+};
+var nextReturnVal = firstReturnVal;
+var nextNextReturnVal = secondReturnVal;
+var items = {};
+var result;
+
+items[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ var result = nextResult;
+ nextResult = nextNextResult;
+ nextNextResult = {
+ done: true
+ };
+
+ return result;
+ }
+ };
+};
+
+result = Array.from(items, mapFn);
+
+assert.sameValue(result.length, 2, 'The value of result.length is expected to be 2');
+assert.sameValue(result[0], firstReturnVal, 'The value of result[0] is expected to equal the value of firstReturnVal');
+assert.sameValue(
+ result[1],
+ secondReturnVal,
+ 'The value of result[1] is expected to equal the value of secondReturnVal'
+);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-arg.js b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-arg.js
new file mode 100644
index 0000000000..16e9381caf
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-arg.js
@@ -0,0 +1,59 @@
+// 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
+description: >
+ `this` value of mapping function with custom `this` argument (traversed via iterator)
+info: |
+ [...]
+ 2. If mapfn is undefined, let mapping be false.
+ 3. else
+ a. If IsCallable(mapfn) is false, throw a TypeError exception.
+ b. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ c. Let mapping be true
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ vii. If mapping is true, then
+ 1. Let mappedValue be Call(mapfn, T, «nextValue, k»).
+features: [Symbol.iterator]
+---*/
+
+var thisVals = [];
+var nextResult = {
+ done: false,
+ value: {}
+};
+var nextNextResult = {
+ done: false,
+ value: {}
+};
+var mapFn = function() {
+ thisVals.push(this);
+};
+var items = {};
+var thisVal = {};
+
+items[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ var result = nextResult;
+ nextResult = nextNextResult;
+ nextNextResult = {
+ done: true
+ };
+
+ return result;
+ }
+ };
+};
+
+Array.from(items, mapFn, thisVal);
+
+assert.sameValue(thisVals.length, 2, 'The value of thisVals.length is expected to be 2');
+assert.sameValue(thisVals[0], thisVal, 'The value of thisVals[0] is expected to equal the value of thisVal');
+assert.sameValue(thisVals[1], thisVal, 'The value of thisVals[1] is expected to equal the value of thisVal');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-non-strict.js b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-non-strict.js
new file mode 100644
index 0000000000..bd54bcfa19
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-non-strict.js
@@ -0,0 +1,62 @@
+// 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
+description: >
+ `this` value of mapping function in non-strict mode (traversed via iterator)
+info: |
+ [...]
+ 2. If mapfn is undefined, let mapping be false.
+ 3. else
+ a. If IsCallable(mapfn) is false, throw a TypeError exception.
+ b. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ c. Let mapping be true
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ vii. If mapping is true, then
+ 1. Let mappedValue be Call(mapfn, T, «nextValue, k»).
+features: [Symbol.iterator]
+flags: [noStrict]
+---*/
+
+var thisVals = [];
+var nextResult = {
+ done: false,
+ value: {}
+};
+var nextNextResult = {
+ done: false,
+ value: {}
+};
+var mapFn = function() {
+ thisVals.push(this);
+};
+var items = {};
+var global = function() {
+ return this;
+}();
+
+items[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ var result = nextResult;
+ nextResult = nextNextResult;
+ nextNextResult = {
+ done: true
+ };
+
+ return result;
+ }
+ };
+};
+
+Array.from(items, mapFn);
+
+assert.sameValue(thisVals.length, 2, 'The value of thisVals.length is expected to be 2');
+assert.sameValue(thisVals[0], global, 'The value of thisVals[0] is expected to equal the value of global');
+assert.sameValue(thisVals[1], global, 'The value of thisVals[1] is expected to equal the value of global');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-strict-strict.js b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-strict-strict.js
new file mode 100644
index 0000000000..0404185f10
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-map-fn-this-strict-strict.js
@@ -0,0 +1,60 @@
+'use strict';
+// 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
+description: >
+ `this` value of mapping function in strict mode (traversed via iterator)
+info: |
+ [...]
+ 2. If mapfn is undefined, let mapping be false.
+ 3. else
+ a. If IsCallable(mapfn) is false, throw a TypeError exception.
+ b. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ c. Let mapping be true
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ vii. If mapping is true, then
+ 1. Let mappedValue be Call(mapfn, T, «nextValue, k»).
+features: [Symbol.iterator]
+flags: [onlyStrict]
+---*/
+
+var thisVals = [];
+var nextResult = {
+ done: false,
+ value: {}
+};
+var nextNextResult = {
+ done: false,
+ value: {}
+};
+var mapFn = function() {
+ thisVals.push(this);
+};
+var items = {};
+
+items[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ var result = nextResult;
+ nextResult = nextNextResult;
+ nextNextResult = {
+ done: true
+ };
+
+ return result;
+ }
+ };
+};
+
+Array.from(items, mapFn);
+
+assert.sameValue(thisVals.length, 2, 'The value of thisVals.length is expected to be 2');
+assert.sameValue(thisVals[0], undefined, 'The value of thisVals[0] is expected to equal undefined');
+assert.sameValue(thisVals[1], undefined, 'The value of thisVals[1] is expected to equal undefined');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop-err.js b/js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop-err.js
new file mode 100644
index 0000000000..96ce7a6f71
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop-err.js
@@ -0,0 +1,54 @@
+// 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
+description: Error setting property on result value (traversed via iterator)
+info: |
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ ix. Let defineStatus be CreateDataPropertyOrThrow(A, Pk,
+ mappedValue).
+ x. If defineStatus is an abrupt completion, return
+ IteratorClose(iterator, defineStatus).
+features: [Symbol.iterator]
+---*/
+
+var constructorSetsIndex0ConfigurableFalse = function() {
+ Object.defineProperty(this, '0', {
+ writable: true,
+ configurable: false
+ });
+};
+var closeCount = 0;
+var items = {};
+var nextResult = {
+ done: false
+};
+
+items[Symbol.iterator] = function() {
+ return {
+ return: function() {
+ closeCount += 1;
+ },
+ next: function() {
+ var result = nextResult;
+
+ nextResult = {
+ done: true
+ };
+
+ return result;
+ }
+ };
+};
+
+assert.throws(TypeError, function() {
+ Array.from.call(constructorSetsIndex0ConfigurableFalse, items);
+}, 'Array.from.call(constructorSetsIndex0ConfigurableFalse, items) throws a TypeError exception');
+
+assert.sameValue(closeCount, 1, 'The value of closeCount is expected to be 1');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop-non-writable.js b/js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop-non-writable.js
new file mode 100644
index 0000000000..ff34d68d11
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop-non-writable.js
@@ -0,0 +1,45 @@
+// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-array.from
+description: >
+ Non-writable properties are overwritten by CreateDataProperty.
+ (result object's "0" is non-writable, items is iterable)
+info: |
+ Array.from ( items [ , mapfn [ , thisArg ] ] )
+
+ [...]
+ 5. If usingIterator is not undefined, then
+ [...]
+ e. Repeat,
+ [...]
+ viii. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, mappedValue).
+ [...]
+features: [generators]
+includes: [propertyHelper.js]
+---*/
+
+var items = function* () {
+ yield 2;
+};
+
+var A = function(_length) {
+ Object.defineProperty(this, "0", {
+ value: 1,
+ writable: false,
+ enumerable: false,
+ configurable: true,
+ });
+};
+
+var res = Array.from.call(A, items());
+
+verifyProperty(res, "0", {
+ value: 2,
+ writable: true,
+ enumerable: true,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop.js b/js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop.js
new file mode 100644
index 0000000000..20f0573f98
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-set-elem-prop.js
@@ -0,0 +1,60 @@
+// 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
+description: Setting property on result value (traversed via iterator)
+info: |
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ ix. Let defineStatus be CreateDataPropertyOrThrow(A, Pk,
+ mappedValue).
+features: [Symbol.iterator]
+---*/
+
+var items = {};
+var firstIterResult = {
+ done: false,
+ value: {}
+};
+var secondIterResult = {
+ done: false,
+ value: {}
+};
+var thirdIterResult = {
+ done: true,
+ value: {}
+};
+var nextIterResult = firstIterResult;
+var nextNextIterResult = secondIterResult;
+var result;
+
+items[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ var result = nextIterResult;
+
+ nextIterResult = nextNextIterResult;
+ nextNextIterResult = thirdIterResult;
+
+ return result;
+ }
+ };
+};
+
+result = Array.from(items);
+
+assert.sameValue(
+ result[0],
+ firstIterResult.value,
+ 'The value of result[0] is expected to equal the value of firstIterResult.value'
+);
+assert.sameValue(
+ result[1],
+ secondIterResult.value,
+ 'The value of result[1] is expected to equal the value of secondIterResult.value'
+);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-set-length-err.js b/js/src/tests/test262/built-ins/Array/from/iter-set-length-err.js
new file mode 100644
index 0000000000..215ca22e1e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-set-length-err.js
@@ -0,0 +1,39 @@
+// 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
+description: Error setting length of object (traversed via iterator)
+info: |
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ iv. If next is false, then
+ 1. Let setStatus be Set(A, "length", k, true).
+ 2. ReturnIfAbrupt(setStatus).
+features: [Symbol.iterator]
+---*/
+
+var poisonedPrototypeLength = function() {};
+var items = {};
+Object.defineProperty(poisonedPrototypeLength.prototype, 'length', {
+ set: function(_) {
+ throw new Test262Error();
+ }
+});
+items[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ return {
+ done: true
+ };
+ }
+ };
+};
+
+assert.throws(Test262Error, function() {
+ Array.from.call(poisonedPrototypeLength, items);
+}, 'Array.from.call(poisonedPrototypeLength, items) throws a Test262Error exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/iter-set-length.js b/js/src/tests/test262/built-ins/Array/from/iter-set-length.js
new file mode 100644
index 0000000000..341e0b4a14
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/iter-set-length.js
@@ -0,0 +1,48 @@
+// 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
+description: Setting length of object (traversed via iterator)
+info: |
+ [...]
+ 6. If usingIterator is not undefined, then
+ [...]
+ g. Repeat
+ [...]
+ iv. If next is false, then
+ 1. Let setStatus be Set(A, "length", k, true).
+ 2. ReturnIfAbrupt(setStatus).
+ 3. Return A.
+features: [Symbol.iterator]
+---*/
+
+var items = {};
+var result, nextIterResult, lastIterResult;
+items[Symbol.iterator] = function() {
+ return {
+ next: function() {
+ var result = nextIterResult;
+ nextIterResult = lastIterResult;
+ return result;
+ }
+ };
+};
+
+nextIterResult = lastIterResult = {
+ done: true
+};
+result = Array.from(items);
+
+assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0');
+
+nextIterResult = {
+ done: false
+};
+lastIterResult = {
+ done: true
+};
+result = Array.from(items);
+
+assert.sameValue(result.length, 1, 'The value of result.length is expected to be 1');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/mapfn-is-not-callable-typeerror.js b/js/src/tests/test262/built-ins/Array/from/mapfn-is-not-callable-typeerror.js
new file mode 100644
index 0000000000..663355bf7e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/mapfn-is-not-callable-typeerror.js
@@ -0,0 +1,36 @@
+// Copyright 2015 Leonardo Balter. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+/*---
+esid: sec-array.from
+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);
+}, 'Array.from([], null) throws a TypeError exception');
+
+assert.throws(TypeError, function() {
+ Array.from([], {});
+}, 'Array.from([], {}) throws a TypeError exception');
+
+assert.throws(TypeError, function() {
+ Array.from([], 'string');
+}, 'Array.from([], "string") throws a TypeError exception');
+
+assert.throws(TypeError, function() {
+ Array.from([], true);
+}, 'Array.from([], true) throws a TypeError exception');
+
+assert.throws(TypeError, function() {
+ Array.from([], 42);
+}, 'Array.from([], 42) throws a TypeError exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/mapfn-is-symbol-throws.js b/js/src/tests/test262/built-ins/Array/from/mapfn-is-symbol-throws.js
new file mode 100644
index 0000000000..8583e376c6
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/mapfn-is-symbol-throws.js
@@ -0,0 +1,22 @@
+// Copyright 2015 Leonardo Balter. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+/*---
+esid: sec-array.from
+description: Throws a TypeError if mapFn is not callable (Symbol)
+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.
+ ...
+features:
+ - Symbol
+---*/
+
+assert.throws(TypeError, function() {
+ Array.from([], Symbol('1'));
+}, 'Array.from([], Symbol("1")) throws a TypeError exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/mapfn-throws-exception.js b/js/src/tests/test262/built-ins/Array/from/mapfn-throws-exception.js
new file mode 100644
index 0000000000..3b3148e616
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/mapfn-throws-exception.js
@@ -0,0 +1,20 @@
+// 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 mapFnThrows(value, index, obj) {
+ throw new Test262Error();
+}
+
+assert.throws(Test262Error, function() {
+ Array.from(array, mapFnThrows);
+}, 'Array.from(array, mapFnThrows) throws a Test262Error exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/from/not-a-constructor.js
new file mode 100644
index 0000000000..067c4e88ad
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/not-a-constructor.js
@@ -0,0 +1,31 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-ecmascript-standard-built-in-objects
+description: >
+ Array.from does not implement [[Construct]], is not new-able
+info: |
+ ECMAScript Function Objects
+
+ Built-in function objects that are not identified as constructors do not
+ implement the [[Construct]] internal method unless otherwise specified in
+ the description of a particular function.
+
+ sec-evaluatenew
+
+ ...
+ 7. If IsConstructor(constructor) is false, throw a TypeError exception.
+ ...
+includes: [isConstructor.js]
+features: [Reflect.construct, arrow-function]
+---*/
+
+assert.sameValue(isConstructor(Array.from), false, 'isConstructor(Array.from) must return false');
+
+assert.throws(TypeError, () => {
+ new Array.from([]);
+}, 'new Array.from([]) throws a TypeError exception');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/Array/from/proto-from-ctor-realm.js
new file mode 100644
index 0000000000..2debc14d02
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/proto-from-ctor-realm.js
@@ -0,0 +1,37 @@
+// Copyright (C) 2016 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: Default [[Prototype]] value derived from realm of the constructor
+info: |
+ [...]
+ 5. If usingIterator is not undefined, then
+ a. If IsConstructor(C) is true, then
+ i. Let A be ? Construct(C).
+ [...]
+
+ 9.1.14 GetPrototypeFromConstructor
+
+ [...]
+ 3. Let proto be ? Get(constructor, "prototype").
+ 4. If Type(proto) is not Object, then
+ a. Let realm be ? GetFunctionRealm(constructor).
+ b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
+ [...]
+features: [cross-realm]
+---*/
+
+var other = $262.createRealm().global;
+var C = new other.Function();
+C.prototype = null;
+
+var a = Array.from.call(C, []);
+
+assert.sameValue(
+ Object.getPrototypeOf(a),
+ other.Object.prototype,
+ 'Object.getPrototypeOf(Array.from.call(C, [])) returns other.Object.prototype'
+);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/shell.js b/js/src/tests/test262/built-ins/Array/from/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/shell.js
diff --git a/js/src/tests/test262/built-ins/Array/from/source-array-boundary.js b/js/src/tests/test262/built-ins/Array/from/source-array-boundary.js
new file mode 100644
index 0000000000..69b35e4003
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/source-array-boundary.js
@@ -0,0 +1,30 @@
+// 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], 'The value of value is expected to equal the value of array[this.arrayIndex]');
+ assert.sameValue(index, this.arrayIndex, 'The value of index is expected to equal the value of this.arrayIndex');
+
+ return value;
+}
+
+var a = Array.from(array, mapFn, this);
+
+assert.sameValue(a.length, array.length, 'The value of a.length is expected to equal the value of array.length');
+assert.sameValue(a[0], Number.MAX_VALUE, 'The value of a[0] is expected to equal the value of Number.MAX_VALUE');
+assert.sameValue(a[1], Number.MIN_VALUE, 'The value of a[1] is expected to equal the value of Number.MIN_VALUE');
+assert.sameValue(a[2], Number.NaN, 'The value of a[2] is expected to equal the value of Number.NaN');
+assert.sameValue(a[3], Number.NEGATIVE_INFINITY, 'The value of a[3] is expected to equal the value of Number.NEGATIVE_INFINITY');
+assert.sameValue(a[4], Number.POSITIVE_INFINITY, 'The value of a[4] is expected to equal the value of Number.POSITIVE_INFINITY');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/source-object-constructor.js b/js/src/tests/test262/built-ins/Array/from/source-object-constructor.js
new file mode 100644
index 0000000000..7a0d1db9f1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/source-object-constructor.js
@@ -0,0 +1,17 @@
+// 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,
+ 'The value of Array.from.call(Object, []).constructor is expected to equal the value of Object'
+);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/source-object-iterator-1.js b/js/src/tests/test262/built-ins/Array/from/source-object-iterator-1.js
new file mode 100644
index 0000000000..908e5dad16
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/source-object-iterator-1.js
@@ -0,0 +1,34 @@
+// 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
+features: [Symbol.iterator]
+---*/
+
+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);
+}, 'Array.from(obj) throws a Test262Error exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/source-object-iterator-2.js b/js/src/tests/test262/built-ins/Array/from/source-object-iterator-2.js
new file mode 100644
index 0000000000..3f56c3ae78
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/source-object-iterator-2.js
@@ -0,0 +1,39 @@
+// 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
+features: [Symbol.iterator]
+---*/
+
+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 value of `typeof a` is expected to be typeof {}');
+for (var j = 0; j < a.length; j++) {
+ assert.sameValue(a[j], array[j], 'The value of a[j] is expected to equal the value of array[j]');
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/source-object-length-set-elem-prop-err.js b/js/src/tests/test262/built-ins/Array/from/source-object-length-set-elem-prop-err.js
new file mode 100644
index 0000000000..119e5898b9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/source-object-length-set-elem-prop-err.js
@@ -0,0 +1,54 @@
+// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-array.from
+description: >
+ TypeError is thrown if CreateDataProperty fails.
+ (items is not iterable)
+info: |
+ Array.from ( items [ , mapfn [ , thisArg ] ] )
+
+ [...]
+ 4. Let usingIterator be ? GetMethod(items, @@iterator).
+ 5. If usingIterator is not undefined, then
+ [...]
+ 6. NOTE: items is not an Iterable so assume it is an array-like object.
+ [...]
+ 12. Repeat, while k < len
+ [...]
+ e. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue).
+ [...]
+
+ CreateDataPropertyOrThrow ( O, P, V )
+
+ [...]
+ 3. Let success be ? CreateDataProperty(O, P, V).
+ 4. If success is false, throw a TypeError exception.
+---*/
+
+var items = {
+ length: 1,
+};
+
+var A1 = function(_length) {
+ this.length = 0;
+ Object.preventExtensions(this);
+};
+
+assert.throws(TypeError, function() {
+ Array.from.call(A1, items);
+}, 'Array.from.call(A1, items) throws a TypeError exception');
+
+var A2 = function(_length) {
+ Object.defineProperty(this, "0", {
+ writable: true,
+ configurable: false,
+ });
+};
+
+assert.throws(TypeError, function() {
+ Array.from.call(A2, items);
+}, 'Array.from.call(A2, items) throws a TypeError exception');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/source-object-length-set-elem-prop-non-writable.js b/js/src/tests/test262/built-ins/Array/from/source-object-length-set-elem-prop-non-writable.js
new file mode 100644
index 0000000000..0ade4a3579
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/source-object-length-set-elem-prop-non-writable.js
@@ -0,0 +1,48 @@
+// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-array.from
+description: >
+ Non-writable properties are overwritten by CreateDataProperty.
+ (result object's "0" is non-writable, items is not iterable)
+info: |
+ Array.from ( items [ , mapfn [ , thisArg ] ] )
+
+ [...]
+ 4. Let usingIterator be ? GetMethod(items, @@iterator).
+ 5. If usingIterator is not undefined, then
+ [...]
+ 6. NOTE: items is not an Iterable so assume it is an array-like object.
+ [...]
+ 12. Repeat, while k < len
+ [...]
+ e. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue).
+ [...]
+includes: [propertyHelper.js]
+---*/
+
+var items = {
+ "0": 2,
+ length: 1,
+};
+
+var A = function(_length) {
+ Object.defineProperty(this, "0", {
+ value: 1,
+ writable: false,
+ enumerable: false,
+ configurable: true,
+ });
+};
+
+var res = Array.from.call(A, items);
+
+verifyProperty(res, "0", {
+ value: 2,
+ writable: true,
+ enumerable: true,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/source-object-length.js b/js/src/tests/test262/built-ins/Array/from/source-object-length.js
new file mode 100644
index 0000000000..c9262c824b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/source-object-length.js
@@ -0,0 +1,27 @@
+// 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], 'The value of a[j] is expected to equal the value of expectedArray[j]');
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/source-object-missing.js b/js/src/tests/test262/built-ins/Array/from/source-object-missing.js
new file mode 100644
index 0000000000..0acd29a694
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/source-object-missing.js
@@ -0,0 +1,24 @@
+// 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 value of `typeof a` is expected to be "object"');
+for (var j = 0; j < a.length; j++) {
+ assert.sameValue(a[j], array[j], 'The value of a[j] is expected to equal the value of array[j]');
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/source-object-without.js b/js/src/tests/test262/built-ins/Array/from/source-object-without.js
new file mode 100644
index 0000000000..d3f131aead
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/source-object-without.js
@@ -0,0 +1,20 @@
+// 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, 'The value of a.length is expected to be 0');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/from/this-null.js b/js/src/tests/test262/built-ins/Array/from/this-null.js
new file mode 100644
index 0000000000..a46feccd51
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/this-null.js
@@ -0,0 +1,14 @@
+// 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, 'The result of evaluating (result instanceof Array) is expected to be true');
+assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0');
+
+reportCompare(0, 0);