The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / test / mjsunit / harmony / typedarrays.js @ f230a1cf

History | View | Annotate | Download (17.6 KB)

1
// Copyright 2013 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
//     * Redistributions of source code must retain the above copyright
7
//       notice, this list of conditions and the following disclaimer.
8
//     * Redistributions in binary form must reproduce the above
9
//       copyright notice, this list of conditions and the following
10
//       disclaimer in the documentation and/or other materials provided
11
//       with the distribution.
12
//     * Neither the name of Google Inc. nor the names of its
13
//       contributors may be used to endorse or promote products derived
14
//       from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27

    
28
// ArrayBuffer
29

    
30
function TestByteLength(param, expectedByteLength) {
31
  var ab = new ArrayBuffer(param);
32
  assertSame(expectedByteLength, ab.byteLength);
33
}
34

    
35
function TestArrayBufferCreation() {
36
  TestByteLength(1, 1);
37
  TestByteLength(256, 256);
38
  TestByteLength(2.567, 2);
39

    
40
  TestByteLength("abc", 0);
41

    
42
  TestByteLength(0, 0);
43

    
44
  assertThrows(function() { new ArrayBuffer(-10); }, RangeError);
45
  assertThrows(function() { new ArrayBuffer(-2.567); }, RangeError);
46

    
47
/* TODO[dslomov]: Reenable the test
48
  assertThrows(function() {
49
    var ab1 = new ArrayBuffer(0xFFFFFFFFFFFF)
50
  }, RangeError);
51
*/
52

    
53
  var ab = new ArrayBuffer();
54
  assertSame(0, ab.byteLength);
55
}
56

    
57
TestArrayBufferCreation();
58

    
59
function TestByteLengthNotWritable() {
60
  var ab = new ArrayBuffer(1024);
61
  assertSame(1024, ab.byteLength);
62

    
63
  assertThrows(function() { "use strict"; ab.byteLength = 42; }, TypeError);
64
}
65

    
66
TestByteLengthNotWritable();
67

    
68
function TestSlice(expectedResultLen, initialLen, start, end) {
69
  var ab = new ArrayBuffer(initialLen);
70
  var a1 = new Uint8Array(ab);
71
  for (var i = 0; i < a1.length; i++) {
72
    a1[i] = 0xCA;
73
  }
74
  var slice = ab.slice(start, end);
75
  assertSame(expectedResultLen, slice.byteLength);
76
  var a2 = new Uint8Array(slice);
77
  for (var i = 0; i < a2.length; i++) {
78
    assertSame(0xCA, a2[i]);
79
  }
80
}
81

    
82
function TestArrayBufferSlice() {
83
  var ab = new ArrayBuffer(1024);
84
  var ab1 = ab.slice(512, 1024);
85
  assertSame(512, ab1.byteLength);
86

    
87
  TestSlice(512, 1024, 512, 1024);
88
  TestSlice(512, 1024, 512);
89

    
90
  TestSlice(0, 0, 1, 20);
91
  TestSlice(100, 100, 0, 100);
92
  TestSlice(100, 100, 0, 1000);
93

    
94
  TestSlice(0, 100, 5, 1);
95

    
96
  TestSlice(1, 100, -11, -10);
97
  TestSlice(9, 100, -10, 99);
98
  TestSlice(0, 100, -10, 80);
99
  TestSlice(10, 100, 80, -10);
100

    
101
  TestSlice(10, 100, 90, "100");
102
  TestSlice(10, 100, "90", "100");
103

    
104
  TestSlice(0,  100, 90, "abc");
105
  TestSlice(10, 100, "abc", 10);
106

    
107
  TestSlice(10, 100, 0.96, 10.96);
108
  TestSlice(10, 100, 0.96, 10.01);
109
  TestSlice(10, 100, 0.01, 10.01);
110
  TestSlice(10, 100, 0.01, 10.96);
111

    
112
  TestSlice(10, 100, 90);
113
  TestSlice(10, 100, -10);
114
}
115

    
116
TestArrayBufferSlice();
117

    
118
// Typed arrays
119

    
120
function TestTypedArray(constr, elementSize, typicalElement) {
121
  assertSame(elementSize, constr.BYTES_PER_ELEMENT);
122

    
123
  var ab = new ArrayBuffer(256*elementSize);
124

    
125
  var a0 = new constr(30);
126
  assertTrue(ArrayBuffer.isView(a0));
127
  assertSame(elementSize, a0.BYTES_PER_ELEMENT);
128
  assertSame(30, a0.length);
129
  assertSame(30*elementSize, a0.byteLength);
130
  assertSame(0, a0.byteOffset);
131
  assertSame(30*elementSize, a0.buffer.byteLength);
132

    
133
  var aLen0 = new constr(0);
134
  assertSame(elementSize, aLen0.BYTES_PER_ELEMENT);
135
  assertSame(0, aLen0.length);
136
  assertSame(0, aLen0.byteLength);
137
  assertSame(0, aLen0.byteOffset);
138
  assertSame(0, aLen0.buffer.byteLength);
139

    
140
  var aOverBufferLen0 = new constr(ab, 128*elementSize, 0);
141
  assertSame(ab, aOverBufferLen0.buffer);
142
  assertSame(elementSize, aOverBufferLen0.BYTES_PER_ELEMENT);
143
  assertSame(0, aOverBufferLen0.length);
144
  assertSame(0, aOverBufferLen0.byteLength);
145
  assertSame(128*elementSize, aOverBufferLen0.byteOffset);
146

    
147
  var a1 = new constr(ab, 128*elementSize, 128);
148
  assertSame(ab, a1.buffer);
149
  assertSame(elementSize, a1.BYTES_PER_ELEMENT);
150
  assertSame(128, a1.length);
151
  assertSame(128*elementSize, a1.byteLength);
152
  assertSame(128*elementSize, a1.byteOffset);
153

    
154

    
155
  var a2 = new constr(ab, 64*elementSize, 128);
156
  assertSame(ab, a2.buffer);
157
  assertSame(elementSize, a2.BYTES_PER_ELEMENT);
158
  assertSame(128, a2.length);
159
  assertSame(128*elementSize, a2.byteLength);
160
  assertSame(64*elementSize, a2.byteOffset);
161

    
162
  var a3 = new constr(ab, 192*elementSize);
163
  assertSame(ab, a3.buffer);
164
  assertSame(64, a3.length);
165
  assertSame(64*elementSize, a3.byteLength);
166
  assertSame(192*elementSize, a3.byteOffset);
167

    
168
  var a4 = new constr(ab);
169
  assertSame(ab, a4.buffer);
170
  assertSame(256, a4.length);
171
  assertSame(256*elementSize, a4.byteLength);
172
  assertSame(0, a4.byteOffset);
173

    
174

    
175
  var i;
176
  for (i = 0; i < 128; i++) {
177
    a1[i] = typicalElement;
178
  }
179

    
180
  for (i = 0; i < 128; i++) {
181
    assertSame(typicalElement, a1[i]);
182
  }
183

    
184
  for (i = 0; i < 64; i++) {
185
    assertSame(0, a2[i]);
186
  }
187

    
188
  for (i = 64; i < 128; i++) {
189
    assertSame(typicalElement, a2[i]);
190
  }
191

    
192
  for (i = 0; i < 64; i++) {
193
    assertSame(typicalElement, a3[i]);
194
  }
195

    
196
  for (i = 0; i < 128; i++) {
197
    assertSame(0, a4[i]);
198
  }
199

    
200
  for (i = 128; i < 256; i++) {
201
    assertSame(typicalElement, a4[i]);
202
  }
203

    
204
  var aAtTheEnd = new constr(ab, 256*elementSize);
205
  assertSame(elementSize, aAtTheEnd.BYTES_PER_ELEMENT);
206
  assertSame(0, aAtTheEnd.length);
207
  assertSame(0, aAtTheEnd.byteLength);
208
  assertSame(256*elementSize, aAtTheEnd.byteOffset);
209

    
210
  assertThrows(function () { new constr(ab, 257*elementSize); }, RangeError);
211
  assertThrows(
212
      function () { new constr(ab, 128*elementSize, 192); },
213
      RangeError);
214

    
215
  if (elementSize !== 1) {
216
    assertThrows(function() { new constr(ab, 128*elementSize - 1, 10); },
217
                 RangeError);
218
    var unalignedArrayBuffer = new ArrayBuffer(10*elementSize + 1);
219
    var goodArray = new constr(unalignedArrayBuffer, 0, 10);
220
    assertSame(10, goodArray.length);
221
    assertSame(10*elementSize, goodArray.byteLength);
222
    assertThrows(function() { new constr(unalignedArrayBuffer)}, RangeError);
223
    assertThrows(function() { new constr(unalignedArrayBuffer, 5*elementSize)},
224
                 RangeError);
225
  }
226

    
227
  var aFromString = new constr("30");
228
  assertSame(elementSize, aFromString.BYTES_PER_ELEMENT);
229
  assertSame(30, aFromString.length);
230
  assertSame(30*elementSize, aFromString.byteLength);
231
  assertSame(0, aFromString.byteOffset);
232
  assertSame(30*elementSize, aFromString.buffer.byteLength);
233

    
234
  var jsArray = [];
235
  for (i = 0; i < 30; i++) {
236
    jsArray.push(typicalElement);
237
  }
238
  var aFromArray = new constr(jsArray);
239
  assertSame(elementSize, aFromArray.BYTES_PER_ELEMENT);
240
  assertSame(30, aFromArray.length);
241
  assertSame(30*elementSize, aFromArray.byteLength);
242
  assertSame(0, aFromArray.byteOffset);
243
  assertSame(30*elementSize, aFromArray.buffer.byteLength);
244
  for (i = 0; i < 30; i++) {
245
    assertSame(typicalElement, aFromArray[i]);
246
  }
247

    
248
  var abLen0 = new ArrayBuffer(0);
249
  var aOverAbLen0 = new constr(abLen0);
250
  assertSame(abLen0, aOverAbLen0.buffer);
251
  assertSame(elementSize, aOverAbLen0.BYTES_PER_ELEMENT);
252
  assertSame(0, aOverAbLen0.length);
253
  assertSame(0, aOverAbLen0.byteLength);
254
  assertSame(0, aOverAbLen0.byteOffset);
255

    
256
  var aNoParam = new constr();
257
  assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT);
258
  assertSame(0, aNoParam.length);
259
  assertSame(0, aNoParam.byteLength);
260
  assertSame(0, aNoParam.byteOffset);
261
}
262

    
263
TestTypedArray(Uint8Array, 1, 0xFF);
264
TestTypedArray(Int8Array, 1, -0x7F);
265
TestTypedArray(Uint16Array, 2, 0xFFFF);
266
TestTypedArray(Int16Array, 2, -0x7FFF);
267
TestTypedArray(Uint32Array, 4, 0xFFFFFFFF);
268
TestTypedArray(Int32Array, 4, -0x7FFFFFFF);
269
TestTypedArray(Float32Array, 4, 0.5);
270
TestTypedArray(Float64Array, 8, 0.5);
271
TestTypedArray(Uint8ClampedArray, 1, 0xFF);
272

    
273
function SubarrayTestCase(constructor, item, expectedResultLen, expectedStartIndex,
274
                          initialLen, start, end) {
275
  var a = new constructor(initialLen);
276
  var s = a.subarray(start, end);
277
  assertSame(constructor, s.constructor);
278
  assertSame(expectedResultLen, s.length);
279
  if (s.length > 0) {
280
    s[0] = item;
281
    assertSame(item, a[expectedStartIndex]);
282
  }
283
}
284

    
285
function TestSubArray(constructor, item) {
286
  SubarrayTestCase(constructor, item, 512, 512, 1024, 512, 1024);
287
  SubarrayTestCase(constructor, item, 512, 512, 1024, 512);
288

    
289
  SubarrayTestCase(constructor, item, 0, undefined, 0, 1, 20);
290
  SubarrayTestCase(constructor, item, 100, 0,       100, 0, 100);
291
  SubarrayTestCase(constructor, item, 100, 0,       100,  0, 1000);
292
  SubarrayTestCase(constructor, item, 0, undefined, 100, 5, 1);
293

    
294
  SubarrayTestCase(constructor, item, 1, 89,        100, -11, -10);
295
  SubarrayTestCase(constructor, item, 9, 90,        100, -10, 99);
296
  SubarrayTestCase(constructor, item, 0, undefined, 100, -10, 80);
297
  SubarrayTestCase(constructor, item, 10,80,        100, 80, -10);
298

    
299
  SubarrayTestCase(constructor, item, 10,90,        100, 90, "100");
300
  SubarrayTestCase(constructor, item, 10,90,        100, "90", "100");
301

    
302
  SubarrayTestCase(constructor, item, 0, undefined, 100, 90, "abc");
303
  SubarrayTestCase(constructor, item, 10,0,         100, "abc", 10);
304

    
305
  SubarrayTestCase(constructor, item, 10,0,         100, 0.96, 10.96);
306
  SubarrayTestCase(constructor, item, 10,0,         100, 0.96, 10.01);
307
  SubarrayTestCase(constructor, item, 10,0,         100, 0.01, 10.01);
308
  SubarrayTestCase(constructor, item, 10,0,         100, 0.01, 10.96);
309

    
310

    
311
  SubarrayTestCase(constructor, item, 10,90,        100, 90);
312
  SubarrayTestCase(constructor, item, 10,90,        100, -10);
313
}
314

    
315
TestSubArray(Uint8Array, 0xFF);
316
TestSubArray(Int8Array, -0x7F);
317
TestSubArray(Uint16Array, 0xFFFF);
318
TestSubArray(Int16Array, -0x7FFF);
319
TestSubArray(Uint32Array, 0xFFFFFFFF);
320
TestSubArray(Int32Array, -0x7FFFFFFF);
321
TestSubArray(Float32Array, 0.5);
322
TestSubArray(Float64Array, 0.5);
323
TestSubArray(Uint8ClampedArray, 0xFF);
324

    
325
function TestTypedArrayOutOfRange(constructor, value, result) {
326
  var a = new constructor(1);
327
  a[0] = value;
328
  assertSame(result, a[0]);
329
}
330

    
331
TestTypedArrayOutOfRange(Uint8Array, 0x1FA, 0xFA);
332
TestTypedArrayOutOfRange(Uint8Array, -1, 0xFF);
333

    
334
TestTypedArrayOutOfRange(Int8Array, 0x1FA, 0x7A - 0x80);
335

    
336
TestTypedArrayOutOfRange(Uint16Array, 0x1FFFA, 0xFFFA);
337
TestTypedArrayOutOfRange(Uint16Array, -1, 0xFFFF);
338
TestTypedArrayOutOfRange(Int16Array, 0x1FFFA, 0x7FFA - 0x8000);
339

    
340
TestTypedArrayOutOfRange(Uint32Array, 0x1FFFFFFFA, 0xFFFFFFFA);
341
TestTypedArrayOutOfRange(Uint32Array, -1, 0xFFFFFFFF);
342
TestTypedArrayOutOfRange(Int32Array, 0x1FFFFFFFA, 0x7FFFFFFA - 0x80000000);
343

    
344
TestTypedArrayOutOfRange(Uint8ClampedArray, 0x1FA, 0xFF);
345
TestTypedArrayOutOfRange(Uint8ClampedArray, -1, 0);
346

    
347
var typedArrayConstructors = [
348
  Uint8Array,
349
  Int8Array,
350
  Uint16Array,
351
  Int16Array,
352
  Uint32Array,
353
  Int32Array,
354
  Uint8ClampedArray,
355
  Float32Array,
356
  Float64Array];
357

    
358
function TestPropertyTypeChecks(constructor) {
359
  var a = new constructor();
360
  function CheckProperty(name) {
361
    var d = Object.getOwnPropertyDescriptor(constructor.prototype, name);
362
    var o = {}
363
    assertThrows(function() {d.get.call(o);}, TypeError);
364
    d.get.call(a); // shouldn't throw
365
    for (var i = 0 ; i < typedArrayConstructors.length; i++) {
366
      d.get.call(new typedArrayConstructors[i](10));
367
    }
368
  }
369

    
370
  CheckProperty("buffer");
371
  CheckProperty("byteOffset");
372
  CheckProperty("byteLength");
373
  CheckProperty("length");
374
}
375

    
376
for(i = 0; i < typedArrayConstructors.lenght; i++) {
377
  TestPropertyTypeChecks(typedArrayConstructors[i]);
378
}
379

    
380

    
381
function TestTypedArraySet() {
382
  // Test array.set in different combinations.
383

    
384
  function assertArrayPrefix(expected, array) {
385
    for (var i = 0; i < expected.length; ++i) {
386
      assertEquals(expected[i], array[i]);
387
    }
388
  }
389

    
390
  var a11 = new Int16Array([1, 2, 3, 4, 0, -1])
391
  var a12 = new Uint16Array(15)
392
  a12.set(a11, 3)
393
  assertArrayPrefix([0, 0, 0, 1, 2, 3, 4, 0, 0xffff, 0, 0], a12)
394
  assertThrows(function(){ a11.set(a12) })
395

    
396
  var a21 = [1, undefined, 10, NaN, 0, -1, {valueOf: function() {return 3}}]
397
  var a22 = new Int32Array(12)
398
  a22.set(a21, 2)
399
  assertArrayPrefix([0, 0, 1, 0, 10, 0, 0, -1, 3, 0], a22)
400

    
401
  var a31 = new Float32Array([2, 4, 6, 8, 11, NaN, 1/0, -3])
402
  var a32 = a31.subarray(2, 6)
403
  a31.set(a32, 4)
404
  assertArrayPrefix([2, 4, 6, 8, 6, 8, 11, NaN], a31)
405
  assertArrayPrefix([6, 8, 6, 8], a32)
406

    
407
  var a4 = new Uint8ClampedArray([3,2,5,6])
408
  a4.set(a4)
409
  assertArrayPrefix([3, 2, 5, 6], a4)
410

    
411
  // Cases with overlapping backing store but different element sizes.
412
  var b = new ArrayBuffer(4)
413
  var a5 = new Int16Array(b)
414
  var a50 = new Int8Array(b)
415
  var a51 = new Int8Array(b, 0, 2)
416
  var a52 = new Int8Array(b, 1, 2)
417
  var a53 = new Int8Array(b, 2, 2)
418

    
419
  a5.set([0x5050, 0x0a0a])
420
  assertArrayPrefix([0x50, 0x50, 0x0a, 0x0a], a50)
421
  assertArrayPrefix([0x50, 0x50], a51)
422
  assertArrayPrefix([0x50, 0x0a], a52)
423
  assertArrayPrefix([0x0a, 0x0a], a53)
424

    
425
  a50.set([0x50, 0x50, 0x0a, 0x0a])
426
  a51.set(a5)
427
  assertArrayPrefix([0x50, 0x0a, 0x0a, 0x0a], a50)
428

    
429
  a50.set([0x50, 0x50, 0x0a, 0x0a])
430
  a52.set(a5)
431
  assertArrayPrefix([0x50, 0x50, 0x0a, 0x0a], a50)
432

    
433
  a50.set([0x50, 0x50, 0x0a, 0x0a])
434
  a53.set(a5)
435
  assertArrayPrefix([0x50, 0x50, 0x50, 0x0a], a50)
436

    
437
  a50.set([0x50, 0x51, 0x0a, 0x0b])
438
  a5.set(a51)
439
  assertArrayPrefix([0x0050, 0x0051], a5)
440

    
441
  a50.set([0x50, 0x51, 0x0a, 0x0b])
442
  a5.set(a52)
443
  assertArrayPrefix([0x0051, 0x000a], a5)
444

    
445
  a50.set([0x50, 0x51, 0x0a, 0x0b])
446
  a5.set(a53)
447
  assertArrayPrefix([0x000a, 0x000b], a5)
448

    
449
  // Mixed types of same size.
450
  var a61 = new Float32Array([1.2, 12.3])
451
  var a62 = new Int32Array(2)
452
  a62.set(a61)
453
  assertArrayPrefix([1, 12], a62)
454
  a61.set(a62)
455
  assertArrayPrefix([1, 12], a61)
456

    
457
  // Invalid source
458
  var a = new Uint16Array(50);
459
  var expected = [];
460
  for (i = 0; i < 50; i++) {
461
    a[i] = i;
462
    expected.push(i);
463
  }
464
  a.set({});
465
  assertArrayPrefix(expected, a);
466
  assertThrows(function() { a.set.call({}) }, TypeError);
467
  assertThrows(function() { a.set.call([]) }, TypeError);
468

    
469
  assertThrows(function() { a.set(0); }, TypeError);
470
  assertThrows(function() { a.set(0, 1); }, TypeError);
471
}
472

    
473
TestTypedArraySet();
474

    
475
// DataView
476
function TestDataViewConstructor() {
477
  var ab = new ArrayBuffer(256);
478

    
479
  var d1 = new DataView(ab, 1, 255);
480
  assertTrue(ArrayBuffer.isView(d1));
481
  assertSame(ab, d1.buffer);
482
  assertSame(1, d1.byteOffset);
483
  assertSame(255, d1.byteLength);
484

    
485
  var d2 = new DataView(ab, 2);
486
  assertSame(ab, d2.buffer);
487
  assertSame(2, d2.byteOffset);
488
  assertSame(254, d2.byteLength);
489

    
490
  var d3 = new DataView(ab);
491
  assertSame(ab, d3.buffer);
492
  assertSame(0, d3.byteOffset);
493
  assertSame(256, d3.byteLength);
494

    
495
  var d3a = new DataView(ab, 1, 0);
496
  assertSame(ab, d3a.buffer);
497
  assertSame(1, d3a.byteOffset);
498
  assertSame(0, d3a.byteLength);
499

    
500
  var d3b = new DataView(ab, 256, 0);
501
  assertSame(ab, d3b.buffer);
502
  assertSame(256, d3b.byteOffset);
503
  assertSame(0, d3b.byteLength);
504

    
505
  var d3c = new DataView(ab, 256);
506
  assertSame(ab, d3c.buffer);
507
  assertSame(256, d3c.byteOffset);
508
  assertSame(0, d3c.byteLength);
509

    
510
  var d4 = new DataView(ab, 1, 3.1415926);
511
  assertSame(ab, d4.buffer);
512
  assertSame(1, d4.byteOffset);
513
  assertSame(3, d4.byteLength);
514

    
515

    
516
  // error cases
517
  assertThrows(function() { new DataView(ab, -1); }, RangeError);
518
  assertThrows(function() { new DataView(ab, 1, -1); }, RangeError);
519
  assertThrows(function() { new DataView(); }, TypeError);
520
  assertThrows(function() { new DataView([]); }, TypeError);
521
  assertThrows(function() { new DataView(ab, 257); }, RangeError);
522
  assertThrows(function() { new DataView(ab, 1, 1024); }, RangeError);
523
}
524

    
525
TestDataViewConstructor();
526

    
527
function TestDataViewPropertyTypeChecks() {
528
  var a = new DataView(new ArrayBuffer(10));
529
  function CheckProperty(name) {
530
    var d = Object.getOwnPropertyDescriptor(DataView.prototype, name);
531
    var o = {}
532
    assertThrows(function() {d.get.call(o);}, TypeError);
533
    d.get.call(a); // shouldn't throw
534
  }
535

    
536
  CheckProperty("buffer");
537
  CheckProperty("byteOffset");
538
  CheckProperty("byteLength");
539
}
540

    
541

    
542
TestDataViewPropertyTypeChecks();
543

    
544
// General tests for properties
545

    
546
// Test property attribute [[Enumerable]]
547
function TestEnumerable(func, obj) {
548
  function props(x) {
549
    var array = [];
550
    for (var p in x) array.push(p);
551
    return array.sort();
552
  }
553
  assertArrayEquals([], props(func));
554
  assertArrayEquals([], props(func.prototype));
555
  if (obj)
556
    assertArrayEquals([], props(obj));
557
}
558
TestEnumerable(ArrayBuffer, new ArrayBuffer());
559
for(i = 0; i < typedArrayConstructors.lenght; i++) {
560
  TestEnumerable(typedArrayConstructors[i]);
561
}
562
TestEnumerable(DataView, new DataView(new ArrayBuffer()));
563

    
564
// Test arbitrary properties on ArrayBuffer
565
function TestArbitrary(m) {
566
  function TestProperty(map, property, value) {
567
    map[property] = value;
568
    assertEquals(value, map[property]);
569
  }
570
  for (var i = 0; i < 20; i++) {
571
    TestProperty(m, i, 'val' + i);
572
    TestProperty(m, 'foo' + i, 'bar' + i);
573
  }
574
}
575
TestArbitrary(new ArrayBuffer(256));
576
for(i = 0; i < typedArrayConstructors.lenght; i++) {
577
  TestArbitary(new typedArrayConstructors[i](10));
578
}
579
TestArbitrary(new DataView(new ArrayBuffer(256)));
580

    
581

    
582
// Test direct constructor call
583
assertThrows(function() { ArrayBuffer(); }, TypeError);
584
assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError);