1
// Copyright 2011 the V8 project authors. All rights reserved.
1
// Copyright 2012 the V8 project authors. All rights reserved.
2
2
// Redistribution and use in source and binary forms, with or without
3
3
// modification, are permitted provided that the following conditions are
43
43
assertEquals(0, a[0]);
44
44
assertEquals(0, a[1]);
46
// No-parameter constructor should fail right now.
48
return new ArrayBuffer();
50
assertThrows(abfunc1);
52
// Test derivation from an ArrayBuffer
53
var ab = new ArrayBuffer(12);
54
var derived_uint8 = new Uint8Array(ab);
55
assertEquals(12, derived_uint8.length);
56
var derived_uint32 = new Uint32Array(ab);
57
assertEquals(3, derived_uint32.length);
58
var derived_uint32_2 = new Uint32Array(ab,4);
59
assertEquals(2, derived_uint32_2.length);
60
var derived_uint32_3 = new Uint32Array(ab,4,1);
61
assertEquals(1, derived_uint32_3.length);
63
// If a given byteOffset and length references an area beyond the end of the
64
// ArrayBuffer an exception is raised.
66
new Uint32Array(ab,4,3);
68
assertThrows(abfunc3);
70
new Uint32Array(ab,16);
72
assertThrows(abfunc4);
74
// The given byteOffset must be a multiple of the element size of the specific
75
// type, otherwise an exception is raised.
77
new Uint32Array(ab,5);
79
assertThrows(abfunc5);
81
// If length is not explicitly specified, the length of the ArrayBuffer minus
82
// the byteOffset must be a multiple of the element size of the specific type,
83
// or an exception is raised.
84
var ab2 = new ArrayBuffer(13);
86
new Uint32Array(ab2,4);
88
assertThrows(abfunc6);
46
90
// Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is
47
91
// "constant", but not read-only).
48
92
a = new Int32Array(2);