summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/flatMap/array-like-objects-poisoned-length.js
blob: b7a8d20ef4a8975f6b44385d214c73e4cb88d369 (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
53
54
55
56
57
58
59
60
61
62
// 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: >
  Observe abrupt completion in poisoned lengths of array-like objects
info: |
  Array.prototype.flatMap ( mapperFunction [ , thisArg ] )

  1. Let O be ? ToObject(this value).
  2. Let sourceLen be ? ToLength(? Get(O, "length")).
features: [Array.prototype.flatMap, Symbol.toPrimitive]
---*/

assert.sameValue(typeof Array.prototype.flatMap, 'function');

function fn(e) {
  return e;
}

var arr = {
  length: Symbol(),
};
assert.throws(TypeError, function() {
  [].flatMap.call(arr, fn);
}, 'length is a symbol');

arr = {
  get length() { throw new Test262Error() }
};
assert.throws(Test262Error, function() {
  [].flatMap.call(arr, fn);
}, 'custom get error');

arr = {
  length: {
    valueOf() { throw new Test262Error() }
  }
};
assert.throws(Test262Error, function() {
  [].flatMap.call(arr, fn);
}, 'custom valueOf error');

arr = {
  length: {
    toString() { throw new Test262Error() }
  }
};
assert.throws(Test262Error, function() {
  [].flatMap.call(arr, fn);
}, 'custom toString error');

arr = {
  length: {
    [Symbol.toPrimitive]() { throw new Test262Error() }
  }
};
assert.throws(Test262Error, function() {
  [].flatMap.call(arr, fn);
}, 'custom Symbol.toPrimitive error');

reportCompare(0, 0);