typedarray-construct-offset-not-smi.js 1.12 KB
Newer Older
1 2 3 4
// 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.

5
// Flags: --allow-natives-syntax --mock-arraybuffer-allocator
6 7

(function TestBufferByteLengthNonSmi() {
8
  var non_smi_byte_length = %MaxSmi() + 1;
9

10 11
  var buffer = new ArrayBuffer(non_smi_byte_length);

12 13 14 15 16 17 18 19 20 21 22
  var arr = new Uint16Array(buffer);

  assertEquals(non_smi_byte_length, arr.byteLength);
  assertEquals(non_smi_byte_length / 2, arr.length);

  arr = new Uint32Array(buffer);
  assertEquals(non_smi_byte_length, arr.byteLength);
  assertEquals(non_smi_byte_length / 4, arr.length);
})();

(function TestByteOffsetNonSmi() {
23
  var non_smi_byte_length = %MaxSmi() + 11;
24 25 26

  var buffer = new ArrayBuffer(non_smi_byte_length);

27 28
  var whole = new Uint16Array(buffer);

29
  assertEquals(non_smi_byte_length, whole.byteLength);
30 31 32 33 34 35 36 37
  assertEquals(non_smi_byte_length / 2, whole.length);

  var arr = new Uint16Array(buffer, non_smi_byte_length - 10, 5);

  assertEquals(non_smi_byte_length, arr.buffer.byteLength);
  assertEquals(10, arr.byteLength);
  assertEquals(5, arr.length);
})();