summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/es6/typedarray-map.js
blob: e8d97879b61ed73cd991b0a8943fdb7a9588a130 (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
// Copyright 2017 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.

// Flags: --allow-natives-syntax

var typedArrayConstructors = [
  Uint8Array,
  Int8Array,
  Uint16Array,
  Int16Array,
  Uint32Array,
  Int32Array,
  Uint8ClampedArray,
  Float32Array,
  Float64Array];

function TestTypedArrayMap(constructor) {
  assertEquals(1, constructor.prototype.map.length);

  var target;

  class EscapingArray extends constructor {
    constructor(...args) {
      super(...args);
      target = this;
    }
  }

  class DetachingArray extends constructor {
    static get [Symbol.species]() {
      return EscapingArray;
    }
  }

  assertThrows(function(){
    new DetachingArray(5).map(function(v,i,a){
      print(i);
      if (i == 1) {
        %ArrayBufferDetach(target.buffer);
      }
    })
  }, TypeError);

}

for (i = 0; i < typedArrayConstructors.length; i++) {
  TestTypedArrayMap(typedArrayConstructors[i]);
}