Debian Codegraph @

js/src/tests/test262/built-ins/DataView/defined-byteoffset-undefined-bytelength.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 byteoffset and undefined bytelength
8 info: |
9 24.2.2.1 DataView (buffer, byteOffset, byteLength )
10
11 ...
12 8. If byteLength is either not present or undefined, then
13 a. Let viewByteLength be bufferByteLength - offset.
14 ...
15 17. Return O.
16 ---*/
17
18 var sample;
19 var buffer = new ArrayBuffer(4);
20
21 sample = new DataView(buffer, 0, undefined);
22 assert.sameValue(sample.byteLength, 4, "sample.byteLength");
23 assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
24 assert.sameValue(sample.buffer, buffer);
25 assert.sameValue(sample.constructor, DataView);
26 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
27
28 sample = new DataView(buffer, 1, undefined);
29 assert.sameValue(sample.byteLength, 3, "sample.byteLength");
30 assert.sameValue(sample.byteOffset, 1, "sample.byteOffset");
31 assert.sameValue(sample.buffer, buffer);
32 assert.sameValue(sample.constructor, DataView);
33 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
34
35 sample = new DataView(buffer, 2, undefined);
36 assert.sameValue(sample.byteLength, 2, "sample.byteLength");
37 assert.sameValue(sample.byteOffset, 2, "sample.byteOffset");
38 assert.sameValue(sample.buffer, buffer);
39 assert.sameValue(sample.constructor, DataView);
40 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
41
42 sample = new DataView(buffer, 3, undefined);
43 assert.sameValue(sample.byteLength, 1, "sample.byteLength");
44 assert.sameValue(sample.byteOffset, 3, "sample.byteOffset");
45 assert.sameValue(sample.buffer, buffer);
46 assert.sameValue(sample.constructor, DataView);
47 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
48
49 sample = new DataView(buffer, 4, undefined);
50 assert.sameValue(sample.byteLength, 0, "sample.byteLength");
51 assert.sameValue(sample.byteOffset, 4, "sample.byteOffset");
52 assert.sameValue(sample.buffer, buffer);
53 assert.sameValue(sample.constructor, DataView);
54 assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
55
56 reportCompare(0, 0);