1 // Copyright 2014 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Flags: --allow-natives-syntax 6 7 var buffer1 = new ArrayBuffer(100 * 1024); 8 9 var array1 = new Uint8Array(buffer1, {valueOf : function() { 10 %ArrayBufferNeuter(buffer1); 11 return 0; 12 }}); 13 14 assertEquals(0, array1.length); 15 16 var buffer2 = new ArrayBuffer(100 * 1024); 17 18 assertThrows(function() { 19 var array2 = new Uint8Array(buffer2, 0, {valueOf : function() { 20 %ArrayBufferNeuter(buffer2); 21 return 100 * 1024; 22 }}); 23 }, RangeError); 24 25 26 var buffer3 = new ArrayBuffer(100 * 1024 * 1024); 27 var dataView1 = new DataView(buffer3, {valueOf : function() { 28 %ArrayBufferNeuter(buffer3); 29 return 0; 30 }}); 31 32 assertEquals(0, dataView1.byteLength); 33 34 var buffer4 = new ArrayBuffer(100 * 1024); 35 assertThrows(function() { 36 var dataView2 = new DataView(buffer4, 0, {valueOf : function() { 37 %ArrayBufferNeuter(buffer4); 38 return 100 * 1024 * 1024; 39 }}); 40 }, RangeError); 41 42 43 var buffer5 = new ArrayBuffer(100 * 1024); 44 var buffer6 = buffer5.slice({valueOf : function() { 45 %ArrayBufferNeuter(buffer5); 46 return 0; 47 }}, 100 * 1024 * 1024); 48 assertEquals(0, buffer6.byteLength); 49 50 51 var buffer7 = new ArrayBuffer(100 * 1024 * 1024); 52 var buffer8 = buffer7.slice(0, {valueOf : function() { 53 %ArrayBufferNeuter(buffer7); 54 return 100 * 1024 * 1024; 55 }}); 56 assertEquals(0, buffer8.byteLength); 57 58 var buffer9 = new ArrayBuffer(1024); 59 var array9 = new Uint8Array(buffer9); 60 var array10 = array9.subarray({valueOf : function() { 61 %ArrayBufferNeuter(buffer9); 62 return 0; 63 }}, 1024); 64 assertEquals(0, array9.length); 65 assertEquals(0, array10.length); 66 67 var buffer11 = new ArrayBuffer(1024); 68 var array11 = new Uint8Array(buffer11); 69 var array12 = array11.subarray(0, {valueOf : function() { 70 %ArrayBufferNeuter(buffer11); 71 return 1024; 72 }}); 73 assertEquals(0, array11.length); 74 assertEquals(0, array12.length); 75