Add tests for ArrayBuffer.prototype.byteLength

This commit is contained in:
Leonardo Balter 2016-05-04 14:20:14 -04:00 committed by Mike Pennisi
parent a0cd3b07fc
commit 3af3af3d40
7 changed files with 194 additions and 0 deletions

View File

@ -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.1.4.1
esid: sec-get-arraybuffer.prototype.bytelength
description: Returns 0 if the buffer is detached
info: >
24.1.4.1 get ArrayBuffer.prototype.byteLength
1. Let O be the this value.
...
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
...
includes: [detachArrayBuffer.js]
---*/
var ab = new ArrayBuffer(1);
$DETACHBUFFER(ab);
assert.throws(TypeError, function() {
ab.byteLength;
});

View File

@ -0,0 +1,19 @@
// 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.1.4.1
esid: sec-get-arraybuffer.prototype.bytelength
description: Requires this value to have a [[ArrayBufferData]] internal slot
info: >
24.1.4.1 get ArrayBuffer.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 an [[ArrayBufferData]] internal slot, throw a TypeError
exception.
...
---*/
assert.throws(TypeError, function() {
ArrayBuffer.prototype.byteLength;
});

View File

@ -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.1.4.1
esid: sec-get-arraybuffer.prototype.bytelength
description: Throws a TypeError exception when invoked as a function
info: >
24.1.4.1 get ArrayBuffer.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 an [[ArrayBufferData]] internal slot, throw a TypeError
exception.
...
---*/
var getter = Object.getOwnPropertyDescriptor(
ArrayBuffer.prototype, "byteLength"
).get;
assert.throws(TypeError, function() {
getter();
});

View File

@ -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.1.4.1
esid: sec-get-arraybuffer.prototype.bytelength
description: >
"byteLength" property of ArrayBuffer.prototype
info: >
ArrayBuffer.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(ArrayBuffer.prototype, "byteLength");
assert.sameValue(desc.set, undefined);
assert.sameValue(typeof desc.get, "function");
verifyNotEnumerable(ArrayBuffer.prototype, "byteLength");
verifyConfigurable(ArrayBuffer.prototype, "byteLength");

View File

@ -0,0 +1,19 @@
// 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.1.4.1
esid: sec-get-arraybuffer.prototype.bytelength
description: Return value from [[ByteLength]] internal slot
info: >
24.1.4.1 get ArrayBuffer.prototype.byteLength
...
5. Let length be the value of O's [[ArrayBufferByteLength]] internal slot.
6. Return length.
---*/
var ab1 = new ArrayBuffer(0);
assert.sameValue(ab1.byteLength, 0);
var ab2 = new ArrayBuffer(42);
assert.sameValue(ab2.byteLength, 42);

View 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.1.4.1
esid: sec-get-arraybuffer.prototype.bytelength
description: >
Throws a TypeError exception when `this` does not have a [[ArrayBufferData]]
internal slot
info: >
24.1.4.1 get ArrayBuffer.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 an [[ArrayBufferData]] internal slot, throw a TypeError
exception.
...
features: [DataView, Int8Array]
---*/
var getter = Object.getOwnPropertyDescriptor(
ArrayBuffer.prototype, "byteLength"
).get;
assert.throws(TypeError, function() {
getter.call({});
});
assert.throws(TypeError, function() {
getter.call([]);
});
var ta = new Int8Array(8);
assert.throws(TypeError, function() {
getter.call(ta);
});
var dv = new DataView(new ArrayBuffer(8), 0);
assert.throws(TypeError, function() {
getter.call(dv);
});

View 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.1.4.1
esid: sec-get-arraybuffer.prototype.bytelength
description: Throws a TypeError exception when `this` is not Object
info: >
24.1.4.1 get ArrayBuffer.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(
ArrayBuffer.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");