mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Add tests for the DataView constructor
This commit is contained in:
parent
3af3af3d40
commit
ee5356b86a
@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Throws a TypeError if buffer does not have [[ArrayBufferData]]
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
2. If Type(buffer) is not Object, throw a TypeError exception.
|
||||
3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a
|
||||
TypeError exception.
|
||||
...
|
||||
features: [Int8Array]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error("buffer should be verified before byteOffset");
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView({}, obj);
|
||||
}, "{}");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView([], obj);
|
||||
}, "[]");
|
||||
|
||||
var ta = new Int8Array();
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(ta, obj);
|
||||
}, "typedArray instance");
|
||||
|
||||
var other = new DataView(new ArrayBuffer(1), 0);
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(other, obj);
|
||||
}, "dataView instance");
|
54
test/built-ins/DataView/buffer-not-object-throws.js
Normal file
54
test/built-ins/DataView/buffer-not-object-throws.js
Normal file
@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Throws a TypeError if buffer is not Object
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
2. If Type(buffer) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error("buffer should be verified before byteOffset");
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(0, obj);
|
||||
}, "0");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(1, obj);
|
||||
}, "1");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView("", obj);
|
||||
}, "the empty string");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView("buffer", obj);
|
||||
}, "string");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(false, obj);
|
||||
}, "false");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(true, obj);
|
||||
}, "true");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(NaN, obj);
|
||||
}, "NaN");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(Symbol("1"), obj);
|
||||
}, "symbol");
|
24
test/built-ins/DataView/buffer-reference.js
Normal file
24
test/built-ins/DataView/buffer-reference.js
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Reuse buffer argument instead of making a new clone
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
14. Set O's [[ViewedArrayBuffer]] internal slot to buffer.
|
||||
...
|
||||
17. Return O.
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(8);
|
||||
|
||||
var dv1 = new DataView(buffer, 0);
|
||||
var dv2 = new DataView(buffer, 0);
|
||||
|
||||
assert.sameValue(dv1.buffer, buffer);
|
||||
assert.sameValue(dv2.buffer, buffer);
|
27
test/built-ins/DataView/byteoffset-is-negative-throws.js
Normal file
27
test/built-ins/DataView/byteoffset-is-negative-throws.js
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Throws a RangeError if ToInteger(byteOffset) < 0
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
4. Let numberOffset be ? ToNumber(byteOffset).
|
||||
5. Let offset be ToInteger(numberOffset).
|
||||
6. If numberOffset ≠ offset or offset < 0, throw a RangeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var ab = new ArrayBuffer(42);
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(ab, -1);
|
||||
}, "-1");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(ab, -Infinity);
|
||||
}, "-Infinity");
|
@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Throws a RangeError if ToNumber(byteOffset) diffs ToInteger(byteOffset)
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
4. Let numberOffset be ? ToNumber(byteOffset).
|
||||
5. Let offset be ToInteger(numberOffset).
|
||||
6. If numberOffset ≠ offset or offset < 0, throw a RangeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var ab = new ArrayBuffer(42);
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(ab, 1.1);
|
||||
}, "1.1");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(ab, 0.0000001);
|
||||
}, "0.0000001");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(ab, NaN);
|
||||
}, "NaN");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(ab, -1.1);
|
||||
}, "-1.1");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(ab, undefined);
|
||||
}, "undefined");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(ab);
|
||||
}, "no byteOffset arg");
|
12
test/built-ins/DataView/constructor.js
Normal file
12
test/built-ins/DataView/constructor.js
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview-constructor
|
||||
es6id: 24.2.2
|
||||
description: >
|
||||
The DataView constructor is the %DataView% intrinsic object and the initial
|
||||
value of the DataView property of the global object.
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof DataView, "function", "`typeof DataView` is `'function'`");
|
45
test/built-ins/DataView/custom-proto-access-throws.js
Normal file
45
test/built-ins/DataView/custom-proto-access-throws.js
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Return abrupt from newTarget's custom constructor prototype
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%",
|
||||
« [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »).
|
||||
...
|
||||
17. Return O.
|
||||
|
||||
9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ ,
|
||||
internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor,
|
||||
intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
...
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
...
|
||||
features: [Reflect.construct]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(8);
|
||||
|
||||
var newTarget = function() {}.bind(null);
|
||||
Object.defineProperty(newTarget, "prototype", {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Reflect.construct(DataView, [buffer, 0], newTarget);
|
||||
});
|
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Use DataView.prototype if newTarget's prototype is not an Object
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%",
|
||||
« [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »).
|
||||
...
|
||||
17. Return O.
|
||||
|
||||
9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ ,
|
||||
internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor,
|
||||
intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
...
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
...
|
||||
features: [Reflect.construct]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(8);
|
||||
|
||||
function newTarget() {}
|
||||
newTarget.prototype = null;
|
||||
|
||||
var sample = Reflect.construct(DataView, [buffer, 0], newTarget);
|
||||
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
47
test/built-ins/DataView/custom-proto-if-object-is-used.js
Normal file
47
test/built-ins/DataView/custom-proto-if-object-is-used.js
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Use newTarget's custom constructor prototype if Object
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%",
|
||||
« [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »).
|
||||
...
|
||||
17. Return O.
|
||||
|
||||
9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ ,
|
||||
internalSlotsList ] )
|
||||
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor,
|
||||
intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
|
||||
...
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
...
|
||||
features: [Reflect.construct]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(8);
|
||||
|
||||
function newTarget() {}
|
||||
var proto = {};
|
||||
newTarget.prototype = proto;
|
||||
|
||||
var sample = Reflect.construct(DataView, [buffer, 0], newTarget);
|
||||
|
||||
assert.sameValue(sample.constructor, Object);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), proto);
|
14
test/built-ins/DataView/dataview.js
Normal file
14
test/built-ins/DataView/dataview.js
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview-constructor
|
||||
es6id: 24.2.2
|
||||
description: >
|
||||
The DataView Constructor
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
verifyNotEnumerable(this, "DataView");
|
||||
verifyWritable(this, "DataView");
|
||||
verifyConfigurable(this, "DataView");
|
59
test/built-ins/DataView/defined-bytelength-and-byteoffset.js
Normal file
59
test/built-ins/DataView/defined-bytelength-and-byteoffset.js
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Return new instance from defined length and offset
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
17. Return O.
|
||||
---*/
|
||||
|
||||
var sample;
|
||||
var buffer = new ArrayBuffer(3);
|
||||
|
||||
sample = new DataView(buffer, 1, 2);
|
||||
assert.sameValue(sample.byteLength, 2, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 1, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer, "sample.buffer");
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 1, 0);
|
||||
assert.sameValue(sample.byteLength, 0, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 1, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer, "sample.buffer");
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 0, 3);
|
||||
assert.sameValue(sample.byteLength, 3, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer, "sample.buffer");
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 3, 0);
|
||||
assert.sameValue(sample.byteLength, 0, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 3, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer, "sample.buffer");
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 0, 1);
|
||||
assert.sameValue(sample.byteLength, 1, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer, "sample.buffer");
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 0, 2);
|
||||
assert.sameValue(sample.byteLength, 2, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer, "sample.buffer");
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Return new instance from defined byteoffset and undefined bytelength
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
17. Return O.
|
||||
---*/
|
||||
|
||||
var sample;
|
||||
var buffer = new ArrayBuffer(4);
|
||||
|
||||
sample = new DataView(buffer, 0, undefined);
|
||||
assert.sameValue(sample.byteLength, 4, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 1, undefined);
|
||||
assert.sameValue(sample.byteLength, 3, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 1, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 2, undefined);
|
||||
assert.sameValue(sample.byteLength, 2, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 2, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 3, undefined);
|
||||
assert.sameValue(sample.byteLength, 1, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 3, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 4, undefined);
|
||||
assert.sameValue(sample.byteLength, 0, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 4, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
52
test/built-ins/DataView/defined-byteoffset.js
Normal file
52
test/built-ins/DataView/defined-byteoffset.js
Normal file
@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Return new instance from defined offset
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
17. Return O.
|
||||
---*/
|
||||
|
||||
var sample;
|
||||
var buffer = new ArrayBuffer(4);
|
||||
|
||||
sample = new DataView(buffer, 0);
|
||||
assert.sameValue(sample.byteLength, 4, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 1);
|
||||
assert.sameValue(sample.byteLength, 3, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 1, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 2);
|
||||
assert.sameValue(sample.byteLength, 2, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 2, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 3);
|
||||
assert.sameValue(sample.byteLength, 1, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 3, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 4);
|
||||
assert.sameValue(sample.byteLength, 0, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 4, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
45
test/built-ins/DataView/defined-negative-bytelength.js
Normal file
45
test/built-ins/DataView/defined-negative-bytelength.js
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Return new instance from negative lengths
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
17. Return O.
|
||||
---*/
|
||||
|
||||
var sample;
|
||||
var buffer = new ArrayBuffer(2);
|
||||
|
||||
sample = new DataView(buffer, 0, -1);
|
||||
assert.sameValue(sample.byteLength, 0, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 0, -Infinity);
|
||||
assert.sameValue(sample.byteLength, 0, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 0, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 1, -1);
|
||||
assert.sameValue(sample.byteLength, 0, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 1, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
sample = new DataView(buffer, 2, -Infinity);
|
||||
assert.sameValue(sample.byteLength, 0, "sample.byteLength");
|
||||
assert.sameValue(sample.byteOffset, 2, "sample.byteOffset");
|
||||
assert.sameValue(sample.buffer, buffer);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
35
test/built-ins/DataView/detached-buffer.js
Normal file
35
test/built-ins/DataView/detached-buffer.js
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Throws a TypeError if buffer is detached
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
4. Let numberOffset be ? ToNumber(byteOffset).
|
||||
...
|
||||
7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
...
|
||||
includes: [detachArrayBuffer.js]
|
||||
---*/
|
||||
|
||||
var toNumberOffset = 0;
|
||||
var obj = {
|
||||
valueOf: function() {
|
||||
toNumberOffset += 1;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
var ab = new ArrayBuffer(42);
|
||||
$DETACHBUFFER(ab);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(ab, obj);
|
||||
}, "throws if buffer is detached");
|
||||
|
||||
assert.sameValue(toNumberOffset, 1, "ToNumber(byteOffset) runs before");
|
54
test/built-ins/DataView/excessive-bytelength-throws.js
Normal file
54
test/built-ins/DataView/excessive-bytelength-throws.js
Normal file
@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Throws RangeError if offset + viewByteLength > bufferByteLength
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
10. If byteLength is undefined, then
|
||||
...
|
||||
11. Else,
|
||||
a. Let viewByteLength be ? ToLength(byteLength).
|
||||
b. If offset+viewByteLength > bufferByteLength, throw a RangeError
|
||||
exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(3);
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(buffer, 0, 4);
|
||||
}, "offset: 0, length 4");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(buffer, 1, 3);
|
||||
}, "offset: 1, length: 3");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(buffer, 2, 2);
|
||||
}, "offset: 2, length: 2");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(buffer, 3, 1);
|
||||
}, "offset: 3, length: 1");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(buffer, 4, 0);
|
||||
}, "offset: 4, length: 0");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(buffer, 4, -1);
|
||||
}, "offset: 4, length: -1");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(buffer, 4, -Infinity);
|
||||
}, "offset: 4, length: -Infinity");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(buffer, 0, Infinity);
|
||||
}, "offset: 0, length: Infinity");
|
27
test/built-ins/DataView/excessive-byteoffset-throws.js
Normal file
27
test/built-ins/DataView/excessive-byteoffset-throws.js
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Throws a RangeError if offset > bufferByteLength
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
8. Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]]
|
||||
internal slot.
|
||||
9. If offset > bufferByteLength, throw a RangeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var ab = new ArrayBuffer(1);
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(ab, 2);
|
||||
}, "2");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
new DataView(ab, Infinity);
|
||||
}, "Infinity");
|
16
test/built-ins/DataView/extensibility.js
Normal file
16
test/built-ins/DataView/extensibility.js
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview-constructor
|
||||
es6id: 24.2.2
|
||||
description: >
|
||||
The DataView constructor is extensible
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
Unless specified otherwise, the [[Extensible]] internal slot of a built-in
|
||||
object initially has the value true.
|
||||
---*/
|
||||
|
||||
assert.sameValue(Object.isExtensible(DataView), true);
|
34
test/built-ins/DataView/instance-extensibility.js
Normal file
34
test/built-ins/DataView/instance-extensibility.js
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
The new instance is extensible
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%",
|
||||
« [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »).
|
||||
...
|
||||
17. Return O.
|
||||
|
||||
9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ ,
|
||||
internalSlotsList ] )
|
||||
|
||||
...
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
|
||||
9.1.12 ObjectCreate (proto [ , internalSlotsList ])
|
||||
|
||||
...
|
||||
5. Set the [[Extensible]] internal slot of obj to true.
|
||||
...
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(8);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
assert(Object.isExtensible(sample));
|
16
test/built-ins/DataView/length.js
Normal file
16
test/built-ins/DataView/length.js
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview-constructor
|
||||
es6id: 24.2.2
|
||||
description: >
|
||||
The length property of DataView is 3
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(DataView.length, 3, "The value of `DataView.length` is `3`");
|
||||
|
||||
verifyNotEnumerable(DataView, "length");
|
||||
verifyNotWritable(DataView, "length");
|
||||
verifyConfigurable(DataView, "length");
|
16
test/built-ins/DataView/name.js
Normal file
16
test/built-ins/DataView/name.js
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview-constructor
|
||||
es6id: 24.2.2
|
||||
description: >
|
||||
The name property of DataView is "DataView"
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(DataView.name, "DataView", "The value of `DataView.name` is `'DataView'`");
|
||||
|
||||
verifyNotEnumerable(DataView, "name");
|
||||
verifyNotWritable(DataView, "name");
|
||||
verifyConfigurable(DataView, "name");
|
26
test/built-ins/DataView/newtarget-undefined-throws.js
Normal file
26
test/built-ins/DataView/newtarget-undefined-throws.js
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Throws a TypeError if NewTarget is undefined.
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error("NewTarget should be verified before byteOffset");
|
||||
}
|
||||
};
|
||||
|
||||
var buffer = new ArrayBuffer(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
DataView(buffer, obj);
|
||||
});
|
14
test/built-ins/DataView/proto.js
Normal file
14
test/built-ins/DataView/proto.js
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-properties-of-the-dataview-constructor
|
||||
es6id: 24.2.3
|
||||
description: >
|
||||
The prototype of DataView is Function.prototype
|
||||
info: >
|
||||
The value of the [[Prototype]] internal slot of the DataView constructor is
|
||||
the intrinsic object %FunctionPrototype%.
|
||||
---*/
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(DataView), Function.prototype);
|
20
test/built-ins/DataView/prototype.js
vendored
Normal file
20
test/built-ins/DataView/prototype.js
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype
|
||||
es6id: 24.2.3.1
|
||||
description: >
|
||||
The initial value of DataView.prototype is the DataView prototype object.
|
||||
info: >
|
||||
The initial value of DataView.prototype is the intrinsic object
|
||||
%DataViewPrototype%.
|
||||
|
||||
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||
[[Configurable]]: false }.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
verifyNotEnumerable(DataView, "prototype");
|
||||
verifyNotWritable(DataView, "prototype");
|
||||
verifyNotConfigurable(DataView, "prototype");
|
@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Return abrupt from ToLength(symbol byteLength)
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
10. If byteLength is undefined, then
|
||||
a. Let viewByteLength be bufferByteLength - offset.
|
||||
11. Else,
|
||||
a. Let viewByteLength be ? ToLength(byteLength).
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(8);
|
||||
var length = Symbol("1");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(buffer, 0, length);
|
||||
});
|
40
test/built-ins/DataView/return-abrupt-tonumber-bytelength.js
Normal file
40
test/built-ins/DataView/return-abrupt-tonumber-bytelength.js
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Return abrupt from ToLength(byteLength)
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
10. If byteLength is undefined, then
|
||||
a. Let viewByteLength be bufferByteLength - offset.
|
||||
11. Else,
|
||||
a. Let viewByteLength be ? ToLength(byteLength).
|
||||
...
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(8);
|
||||
|
||||
var obj1 = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
var obj2 = {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new DataView(buffer, 0, obj1);
|
||||
}, "valueOf");
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new DataView(buffer, 0, obj2);
|
||||
}, "toString");
|
@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Return abrupt from ToNumber(symbol byteOffset)
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
4. Let numberOffset be ? ToNumber(byteOffset).
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol("1");
|
||||
var ab = new ArrayBuffer(0);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new DataView(ab, s);
|
||||
});
|
27
test/built-ins/DataView/return-abrupt-tonumber-byteoffset.js
Normal file
27
test/built-ins/DataView/return-abrupt-tonumber-byteoffset.js
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Return abrupt from ToNumber(byteOffset)
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
4. Let numberOffset be ? ToNumber(byteOffset).
|
||||
...
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
var ab = new ArrayBuffer(0);
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new DataView(ab, obj);
|
||||
});
|
29
test/built-ins/DataView/return-instance.js
Normal file
29
test/built-ins/DataView/return-instance.js
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
Returns new instance
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%",
|
||||
« [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »).
|
||||
...
|
||||
17. Return O.
|
||||
---*/
|
||||
|
||||
var ab, sample;
|
||||
|
||||
ab = new ArrayBuffer(1);
|
||||
sample = new DataView(ab, 0);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
||||
|
||||
ab = new ArrayBuffer(1);
|
||||
sample = new DataView(ab, 1);
|
||||
assert.sameValue(sample.constructor, DataView);
|
||||
assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype);
|
41
test/built-ins/DataView/tolength-bytelength.js
Normal file
41
test/built-ins/DataView/tolength-bytelength.js
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 24.2.2.1
|
||||
esid: sec-dataview-buffer-byteoffset-bytelength
|
||||
description: >
|
||||
ToLength(byteLength) conversions
|
||||
info: |
|
||||
24.2.2.1 DataView (buffer, byteOffset, byteLength )
|
||||
|
||||
...
|
||||
17. Return O.
|
||||
---*/
|
||||
|
||||
var sample;
|
||||
var buffer = new ArrayBuffer(2);
|
||||
|
||||
sample = new DataView(buffer, 0, true);
|
||||
assert.sameValue(sample.byteLength, 1, "true");
|
||||
|
||||
sample = new DataView(buffer, 0, false);
|
||||
assert.sameValue(sample.byteLength, 0, "false");
|
||||
|
||||
sample = new DataView(buffer, 0, "1");
|
||||
assert.sameValue(sample.byteLength, 1, "string 1");
|
||||
|
||||
sample = new DataView(buffer, 0, "");
|
||||
assert.sameValue(sample.byteLength, 0, "the empty string");
|
||||
|
||||
sample = new DataView(buffer, 0, [1]);
|
||||
assert.sameValue(sample.byteLength, 1, "[1]");
|
||||
|
||||
sample = new DataView(buffer, 0, []);
|
||||
assert.sameValue(sample.byteLength, 0, "[]");
|
||||
|
||||
sample = new DataView(buffer, 0, NaN);
|
||||
assert.sameValue(sample.byteLength, 0, "NaN");
|
||||
|
||||
sample = new DataView(buffer, 0, null);
|
||||
assert.sameValue(sample.byteLength, 0, "null");
|
Loading…
x
Reference in New Issue
Block a user