2014-03-18 10:55:29 +00:00
|
|
|
// 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);
|
|
|
|
|
2017-11-27 15:08:18 +00:00
|
|
|
assertThrows(function() {
|
|
|
|
var array1 = new Uint8Array(buffer1, {valueOf : function() {
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(buffer1);
|
2017-11-27 15:08:18 +00:00
|
|
|
return 0;
|
|
|
|
}});
|
|
|
|
}, TypeError);
|
2014-03-18 10:55:29 +00:00
|
|
|
|
|
|
|
var buffer2 = new ArrayBuffer(100 * 1024);
|
|
|
|
|
|
|
|
assertThrows(function() {
|
|
|
|
var array2 = new Uint8Array(buffer2, 0, {valueOf : function() {
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(buffer2);
|
2014-03-18 10:55:29 +00:00
|
|
|
return 100 * 1024;
|
|
|
|
}});
|
2017-11-27 15:08:18 +00:00
|
|
|
}, TypeError);
|
|
|
|
|
|
|
|
let convertedOffset = false;
|
|
|
|
let convertedLength = false;
|
|
|
|
assertThrows(() =>
|
|
|
|
new Uint8Array(buffer1, {valueOf : function() {
|
|
|
|
convertedOffset = true;
|
|
|
|
return 0;
|
|
|
|
}}, {valueOf : function() {
|
|
|
|
convertedLength = true;
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(buffer1);
|
2017-11-27 15:08:18 +00:00
|
|
|
return 0;
|
|
|
|
}}), TypeError);
|
|
|
|
assertTrue(convertedOffset);
|
|
|
|
assertTrue(convertedLength);
|
2014-03-18 10:55:29 +00:00
|
|
|
|
|
|
|
var buffer3 = new ArrayBuffer(100 * 1024 * 1024);
|
|
|
|
var dataView1 = new DataView(buffer3, {valueOf : function() {
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(buffer3);
|
2014-03-18 10:55:29 +00:00
|
|
|
return 0;
|
|
|
|
}});
|
|
|
|
|
|
|
|
assertEquals(0, dataView1.byteLength);
|
|
|
|
|
|
|
|
var buffer4 = new ArrayBuffer(100 * 1024);
|
|
|
|
assertThrows(function() {
|
|
|
|
var dataView2 = new DataView(buffer4, 0, {valueOf : function() {
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(buffer4);
|
2014-03-18 10:55:29 +00:00
|
|
|
return 100 * 1024 * 1024;
|
|
|
|
}});
|
|
|
|
}, RangeError);
|
|
|
|
|
|
|
|
|
|
|
|
var buffer5 = new ArrayBuffer(100 * 1024);
|
2016-04-28 22:49:44 +00:00
|
|
|
assertThrows(function() {
|
|
|
|
buffer5.slice({valueOf : function() {
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(buffer5);
|
2016-04-28 22:49:44 +00:00
|
|
|
return 0;
|
|
|
|
}}, 100 * 1024 * 1024);
|
|
|
|
}, TypeError);
|
2014-03-18 10:55:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
var buffer7 = new ArrayBuffer(100 * 1024 * 1024);
|
2016-04-28 22:49:44 +00:00
|
|
|
assertThrows(function() {
|
|
|
|
buffer7.slice(0, {valueOf : function() {
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(buffer7);
|
2016-04-28 22:49:44 +00:00
|
|
|
return 100 * 1024 * 1024;
|
|
|
|
}});
|
|
|
|
}, TypeError);
|
2014-03-18 10:55:29 +00:00
|
|
|
|
|
|
|
var buffer9 = new ArrayBuffer(1024);
|
|
|
|
var array9 = new Uint8Array(buffer9);
|
2017-04-26 06:10:17 +00:00
|
|
|
assertThrows(() =>
|
|
|
|
array9.subarray({valueOf : function() {
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(buffer9);
|
2014-03-18 10:55:29 +00:00
|
|
|
return 0;
|
2017-04-26 06:10:17 +00:00
|
|
|
}}, 1024), TypeError);
|
2014-03-18 10:55:29 +00:00
|
|
|
assertEquals(0, array9.length);
|
|
|
|
|
|
|
|
var buffer11 = new ArrayBuffer(1024);
|
|
|
|
var array11 = new Uint8Array(buffer11);
|
2017-04-26 06:10:17 +00:00
|
|
|
assertThrows(() =>
|
|
|
|
array11.subarray(0, {valueOf : function() {
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(buffer11);
|
2017-04-26 06:10:17 +00:00
|
|
|
return 1024;
|
|
|
|
}}), TypeError);
|
2014-03-18 10:55:29 +00:00
|
|
|
assertEquals(0, array11.length);
|