summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/flatMap/array-like-objects-typedarrays.js
blob: 6215e4d2d95a1f8e2dc1e617bd3046b25d3d8596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (C) 2018 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.flatMap
description: >
  array-like objects can be flattened (typedArrays)
info: |
  Array.prototype.flatMap ( mapperFunction [ , thisArg ] )

  1. Let O be ? ToObject(this value).
  2. Let sourceLen be ? ToLength(? Get(O, "length")).
  ...
  5. Let A be ? ArraySpeciesCreate(O, 0).
  ...

  ArraySpeciesCreate ( originalArray, length )

  3. Let isArray be ? IsArray(originalArray).
  4. If isArray is false, return ? ArrayCreate(length).
  5. Let C be ? Get(originalArray, "constructor").
includes: [compareArray.js]
features: [Array.prototype.flatMap, Int32Array]
---*/

function same(e) {
  return e;
}

var ta;
var actual;

ta = new Int32Array([1, 0, 42]);

Object.defineProperty(ta, 'constructor', {
  get() { throw "it should not object the typedarray ctor"; }
});
actual = [].flatMap.call(ta, same);
assert.compareArray(actual, [1, 0, 42], 'The value of actual is expected to be [1, 0, 42]');
assert.sameValue(Object.getPrototypeOf(actual), Array.prototype, 'Object.getPrototypeOf([].flatMap.call(ta, same)") returns Array.prototype');
assert.sameValue(actual instanceof Int32Array, false, 'The result of evaluating (actual instanceof Int32Array) is expected to be false');

ta = new Int32Array(0);

Object.defineProperty(ta, 'constructor', {
  get() { throw "it should not object the typedarray ctor"; }
});
actual = [].flatMap.call(ta, same);
assert.compareArray(actual, [], 'The value of actual is expected to be []');
assert.sameValue(Object.getPrototypeOf(actual), Array.prototype, 'Object.getPrototypeOf([].flatMap.call(ta, same)") returns Array.prototype');
assert.sameValue(actual instanceof Int32Array, false, 'The result of evaluating (actual instanceof Int32Array) is expected to be false');

reportCompare(0, 0);