regress-4665.js 867 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2015 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.

// First test case

function FirstBuffer () {}
FirstBuffer.prototype.__proto__ = Uint8Array.prototype
FirstBuffer.__proto__ = Uint8Array

var buf = new Uint8Array(10)
buf.__proto__ = FirstBuffer.prototype

14
assertThrows(() => buf.subarray(2), TypeError);
15 16 17

// Second test case

18 19
let seen_args = [];

20
function SecondBuffer (arg) {
21
  seen_args.push(arg);
22 23 24 25 26 27 28 29
  var arr = new Uint8Array(arg)
  arr.__proto__ = SecondBuffer.prototype
  return arr
}
SecondBuffer.prototype.__proto__ = Uint8Array.prototype
SecondBuffer.__proto__ = Uint8Array

var buf3 = new SecondBuffer(10)
30
assertEquals([10], seen_args);
31 32 33

var buf4 = buf3.subarray(2)

34 35
assertEquals(10, buf4.length);
assertEquals([10, buf3.buffer], seen_args);