| 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 |
es6id: 24.2.2.1 |
| 6 |
esid: sec-dataview-buffer-byteoffset-bytelength |
| 7 |
description: > |
| 8 |
Return new instance from defined length and offset |
| 9 |
info: | |
| 10 |
24.2.2.1 DataView (buffer, byteOffset, byteLength ) |
| 11 |
|
| 12 |
... |
| 13 |
17. Return O. |
| 14 |
---*/ |
| 15 |
|
| 16 |
var sample; |
| 17 |
var buffer = new ArrayBuffer(3); |
| 18 |
|
| 19 |
sample = new DataView(buffer, 1, 2); |
| 20 |
assert.sameValue(sample.byteLength, 2, "sample.byteLength"); |
| 21 |
assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); |
| 22 |
assert.sameValue(sample.buffer, buffer, "sample.buffer"); |
| 23 |
assert.sameValue(sample.constructor, DataView); |
| 24 |
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); |
| 25 |
|
| 26 |
sample = new DataView(buffer, 1, 0); |
| 27 |
assert.sameValue(sample.byteLength, 0, "sample.byteLength"); |
| 28 |
assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); |
| 29 |
assert.sameValue(sample.buffer, buffer, "sample.buffer"); |
| 30 |
assert.sameValue(sample.constructor, DataView); |
| 31 |
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); |
| 32 |
|
| 33 |
sample = new DataView(buffer, 0, 3); |
| 34 |
assert.sameValue(sample.byteLength, 3, "sample.byteLength"); |
| 35 |
assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); |
| 36 |
assert.sameValue(sample.buffer, buffer, "sample.buffer"); |
| 37 |
assert.sameValue(sample.constructor, DataView); |
| 38 |
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); |
| 39 |
|
| 40 |
sample = new DataView(buffer, 3, 0); |
| 41 |
assert.sameValue(sample.byteLength, 0, "sample.byteLength"); |
| 42 |
assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); |
| 43 |
assert.sameValue(sample.buffer, buffer, "sample.buffer"); |
| 44 |
assert.sameValue(sample.constructor, DataView); |
| 45 |
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); |
| 46 |
|
| 47 |
sample = new DataView(buffer, 0, 1); |
| 48 |
assert.sameValue(sample.byteLength, 1, "sample.byteLength"); |
| 49 |
assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); |
| 50 |
assert.sameValue(sample.buffer, buffer, "sample.buffer"); |
| 51 |
assert.sameValue(sample.constructor, DataView); |
| 52 |
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); |
| 53 |
|
| 54 |
sample = new DataView(buffer, 0, 2); |
| 55 |
assert.sameValue(sample.byteLength, 2, "sample.byteLength"); |
| 56 |
assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); |
| 57 |
assert.sameValue(sample.buffer, buffer, "sample.buffer"); |
| 58 |
assert.sameValue(sample.constructor, DataView); |
| 59 |
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); |