Skip to content

Commit

Permalink
Add tests for ArrayBuffer.prototype.byteLength
Browse files Browse the repository at this point in the history
  • Loading branch information
leobalter authored and jugglinmike committed May 12, 2016
1 parent a0cd3b0 commit 3af3af3
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/built-ins/ArrayBuffer/prototype/byteLength/detached-buffer.js
Original file line number Diff line number Diff line change
@@ -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;
});
Original file line number Diff line number Diff line change
@@ -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;
});
23 changes: 23 additions & 0 deletions test/built-ins/ArrayBuffer/prototype/byteLength/invoked-as-func.js
Original file line number Diff line number Diff line change
@@ -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();
});
23 changes: 23 additions & 0 deletions test/built-ins/ArrayBuffer/prototype/byteLength/prop-desc.js
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
@@ -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");

0 comments on commit 3af3af3

Please sign in to comment.