regress-353004.js 1.83 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 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.

// Flags: --allow-natives-syntax

var buffer1 = new ArrayBuffer(100 * 1024);

9 10
assertThrows(function() {
  var array1 = new Uint8Array(buffer1, {valueOf : function() {
11
    %ArrayBufferDetach(buffer1);
12 13 14
    return 0;
  }});
}, TypeError);
15 16 17 18 19

var buffer2 = new ArrayBuffer(100 * 1024);

assertThrows(function() {
  var array2 = new Uint8Array(buffer2, 0, {valueOf : function() {
20
      %ArrayBufferDetach(buffer2);
21 22
      return 100 * 1024;
  }});
23 24 25 26 27 28 29 30 31 32
}, TypeError);

let convertedOffset = false;
let convertedLength = false;
assertThrows(() =>
  new Uint8Array(buffer1, {valueOf : function() {
      convertedOffset = true;
      return 0;
    }}, {valueOf : function() {
      convertedLength = true;
33
      %ArrayBufferDetach(buffer1);
34 35 36 37
      return 0;
  }}), TypeError);
assertTrue(convertedOffset);
assertTrue(convertedLength);
38 39

var buffer5 = new ArrayBuffer(100 * 1024);
40 41
assertThrows(function() {
  buffer5.slice({valueOf : function() {
42
    %ArrayBufferDetach(buffer5);
43 44 45
    return 0;
  }}, 100 * 1024 * 1024);
}, TypeError);
46 47 48


var buffer7 = new ArrayBuffer(100 * 1024 * 1024);
49 50
assertThrows(function() {
  buffer7.slice(0, {valueOf : function() {
51
    %ArrayBufferDetach(buffer7);
52 53 54
    return 100 * 1024 * 1024;
  }});
}, TypeError);
55 56 57

var buffer9 = new ArrayBuffer(1024);
var array9 = new Uint8Array(buffer9);
58 59
assertThrows(() =>
  array9.subarray({valueOf : function() {
60
    %ArrayBufferDetach(buffer9);
61
    return 0;
62
  }}, 1024), TypeError);
63 64 65 66
assertEquals(0, array9.length);

var buffer11 = new ArrayBuffer(1024);
var array11 = new Uint8Array(buffer11);
67 68
assertThrows(() =>
  array11.subarray(0, {valueOf : function() {
69
    %ArrayBufferDetach(buffer11);
70 71
    return 1024;
  }}), TypeError);
72
assertEquals(0, array11.length);