mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
Add tests for DataView.prototype.byteLength
This commit is contained in:
parent
7b529f00cb
commit
339a3527c9
24
test/built-ins/DataView/prototype/byteLength/detached-buffer.js
vendored
Normal file
24
test/built-ins/DataView/prototype/byteLength/detached-buffer.js
vendored
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.
|
||||
|
||||
/*---
|
||||
esid: sec-get-dataview.prototype.bytelength
|
||||
es6id: 24.2.4.2
|
||||
description: Throws a TypeError if the instance has a detached buffer
|
||||
info: |
|
||||
24.2.4.2 get DataView.prototype.byteLength
|
||||
...
|
||||
5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
|
||||
6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
...
|
||||
includes: [detachArrayBuffer.js]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(1);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
$DETACHBUFFER(buffer);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.byteLength;
|
||||
});
|
21
test/built-ins/DataView/prototype/byteLength/invoked-as-accessor.js
vendored
Normal file
21
test/built-ins/DataView/prototype/byteLength/invoked-as-accessor.js
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// 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-get-dataview.prototype.bytelength
|
||||
es6id: 24.2.4.2
|
||||
description: >
|
||||
Requires this value to have a [[DataView]] internal slot
|
||||
info: |
|
||||
24.2.4.2 get DataView.prototype.byteLength
|
||||
|
||||
1. Let O be the this value.
|
||||
2. If Type(O) is not Object, throw a TypeError exception.
|
||||
3. If O does not have a [[DataView]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
DataView.prototype.byteLength;
|
||||
});
|
24
test/built-ins/DataView/prototype/byteLength/invoked-as-func.js
vendored
Normal file
24
test/built-ins/DataView/prototype/byteLength/invoked-as-func.js
vendored
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.
|
||||
|
||||
/*---
|
||||
esid: sec-get-dataview.prototype.bytelength
|
||||
es6id: 24.2.4.2
|
||||
description: Throws a TypeError exception when invoked as a function
|
||||
info: |
|
||||
24.2.4.2 get DataView.prototype.byteLength
|
||||
|
||||
1. Let O be the this value.
|
||||
2. If Type(O) is not Object, throw a TypeError exception.
|
||||
3. If O does not have a [[DataView]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var getter = Object.getOwnPropertyDescriptor(
|
||||
DataView.prototype, 'byteLength'
|
||||
).get;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getter();
|
||||
});
|
26
test/built-ins/DataView/prototype/byteLength/prop-desc.js
vendored
Normal file
26
test/built-ins/DataView/prototype/byteLength/prop-desc.js
vendored
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.
|
||||
|
||||
/*---
|
||||
esid: sec-get-dataview.prototype.bytelength
|
||||
es6id: 24.2.4.2
|
||||
description: >
|
||||
"byteLength" property of DataView.prototype
|
||||
info: |
|
||||
24.2.4.2 get DataView.prototype.byteLength
|
||||
|
||||
DataView.prototype.byteLength is an accessor property whose set accessor
|
||||
function is undefined.
|
||||
|
||||
Section 17: Every accessor property described in clauses 18 through 26 and in
|
||||
Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true }
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(DataView.prototype, "byteLength");
|
||||
|
||||
assert.sameValue(desc.set, undefined);
|
||||
assert.sameValue(typeof desc.get, "function");
|
||||
|
||||
verifyNotEnumerable(DataView.prototype, "byteLength");
|
||||
verifyConfigurable(DataView.prototype, "byteLength");
|
27
test/built-ins/DataView/prototype/byteLength/return-bytelength.js
vendored
Normal file
27
test/built-ins/DataView/prototype/byteLength/return-bytelength.js
vendored
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.
|
||||
|
||||
/*---
|
||||
esid: sec-get-dataview.prototype.bytelength
|
||||
es6id: 24.2.4.2
|
||||
description: >
|
||||
Return value from [[ByteLength]] internal slot
|
||||
info: |
|
||||
24.2.4.2 get DataView.prototype.byteLength
|
||||
|
||||
...
|
||||
7. Let size be the value of O's [[ByteLength]] internal slot.
|
||||
8. Return size.
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(12);
|
||||
|
||||
var sample1 = new DataView(buffer, 0);
|
||||
var sample2 = new DataView(buffer, 4);
|
||||
var sample3 = new DataView(buffer, 6, 4);
|
||||
var sample4 = new DataView(buffer, 12);
|
||||
|
||||
assert.sameValue(sample1.byteLength, 12);
|
||||
assert.sameValue(sample2.byteLength, 8);
|
||||
assert.sameValue(sample3.byteLength, 4);
|
||||
assert.sameValue(sample4.byteLength, 0);
|
40
test/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal.js
vendored
Normal file
40
test/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal.js
vendored
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.
|
||||
|
||||
/*---
|
||||
esid: sec-get-dataview.prototype.bytelength
|
||||
description: >
|
||||
Throws a TypeError exception when `this` does not have a [[DataView]] internal
|
||||
slot
|
||||
info: |
|
||||
24.2.4.2 get DataView.prototype.byteLength
|
||||
|
||||
1. Let O be the this value.
|
||||
2. If Type(O) is not Object, throw a TypeError exception.
|
||||
3. If O does not have a [[DataView]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
features: [Int8Array]
|
||||
---*/
|
||||
|
||||
var getter = Object.getOwnPropertyDescriptor(
|
||||
DataView.prototype, "byteLength"
|
||||
).get;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call({});
|
||||
}, "{}");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call([]);
|
||||
}, "[]");
|
||||
|
||||
var ab = new ArrayBuffer(8);
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call(ab);
|
||||
}, "ArrayBuffer");
|
||||
|
||||
var ta = new Int8Array();
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call(ta);
|
||||
}, "TypedArray");
|
48
test/built-ins/DataView/prototype/byteLength/this-is-not-object.js
vendored
Normal file
48
test/built-ins/DataView/prototype/byteLength/this-is-not-object.js
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
// 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-get-dataview.prototype.bytelength
|
||||
es6id: 24.2.4.2
|
||||
description: Throws a TypeError exception when `this` is not Object
|
||||
info: |
|
||||
24.2.4.2 get DataView.prototype.byteLength
|
||||
|
||||
1. Let O be the this value.
|
||||
2. If Type(O) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var getter = Object.getOwnPropertyDescriptor(
|
||||
DataView.prototype, "byteLength"
|
||||
).get;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call(undefined);
|
||||
}, "this is undefined");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call(null);
|
||||
}, "this is null");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call(42);
|
||||
}, "this is 42");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call("1");
|
||||
}, "this is a string");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call(true);
|
||||
}, "this is true");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call(false);
|
||||
}, "this is false");
|
||||
|
||||
var s = Symbol("s");
|
||||
assert.throws(TypeError, function() {
|
||||
getter.call(s);
|
||||
}, "this is a Symbol");
|
Loading…
x
Reference in New Issue
Block a user