summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-species.js
blob: 3cf2636d01fffd6e35e1d73a5a83bd91173c879f (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
// 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-%typedarray%.prototype.filter
description: callbackfn is called for each item before TypedArraySpeciesCreate
info: |
  22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] )

  ...
  9. Repeat, while k < len
    ...
    c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
    ...
  10. Let A be ? TypedArraySpeciesCreate(O, « captured »).
  ...
includes: [testBigIntTypedArray.js]
features: [BigInt, Symbol.species, TypedArray]
---*/

testWithBigIntTypedArrayConstructors(function(TA) {
  var length = 42;
  var sample = new TA(length);
  var calls = 0;
  var before = false;

  sample.constructor = {};
  Object.defineProperty(sample.constructor, Symbol.species, {
    get: function() {
      before = calls === length;
    }
  });

  sample.filter(function() {
    calls++;
  });

  assert.sameValue(calls, 42, "callbackfn called for each item");
  assert.sameValue(before, true, "all callbackfn called before");
});

reportCompare(0, 0);