Debian Codegraph @

js/src/tests/test262/built-ins/DataView/defined-bytelength-and-byteoffset.js

raw
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-dataview-buffer-byteoffset-bytelength
6 description: >
7 Return new instance from defined length and offset
8 info: |
9 24.2.2.1 DataView (buffer, byteOffset, byteLength )
10
11 ...
12 17. Return O.
13 ---*/
14
15 var sample;
16 var buffer = new ArrayBuffer(3);
17
18 sample = new DataView(buffer, 1, 2);
19 assert.sameValue(sample.byteLength, 2, "sample.byteLength");
20 assert.sameValue(sample.byteOffset, 1, "sample.byteOffset");
21 assert.sameValue(sample.buffer, buffer, "sample.buffer");
22 assert.sameValue(sample.constructor, DataView);
23 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
24
25 sample = new DataView(buffer, 1, 0);
26 assert.sameValue(sample.byteLength, 0, "sample.byteLength");
27 assert.sameValue(sample.byteOffset, 1, "sample.byteOffset");
28 assert.sameValue(sample.buffer, buffer, "sample.buffer");
29 assert.sameValue(sample.constructor, DataView);
30 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
31
32 sample = new DataView(buffer, 0, 3);
33 assert.sameValue(sample.byteLength, 3, "sample.byteLength");
34 assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
35 assert.sameValue(sample.buffer, buffer, "sample.buffer");
36 assert.sameValue(sample.constructor, DataView);
37 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
38
39 sample = new DataView(buffer, 3, 0);
40 assert.sameValue(sample.byteLength, 0, "sample.byteLength");
41 assert.sameValue(sample.byteOffset, 3, "sample.byteOffset");
42 assert.sameValue(sample.buffer, buffer, "sample.buffer");
43 assert.sameValue(sample.constructor, DataView);
44 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
45
46 sample = new DataView(buffer, 0, 1);
47 assert.sameValue(sample.byteLength, 1, "sample.byteLength");
48 assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
49 assert.sameValue(sample.buffer, buffer, "sample.buffer");
50 assert.sameValue(sample.constructor, DataView);
51 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
52
53 sample = new DataView(buffer, 0, 2);
54 assert.sameValue(sample.byteLength, 2, "sample.byteLength");
55 assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
56 assert.sameValue(sample.buffer, buffer, "sample.buffer");
57 assert.sameValue(sample.constructor, DataView);
58 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
59
60 reportCompare(0, 0);