-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for ArrayBuffer.prototype.byteLength
- Loading branch information
1 parent
a0cd3b0
commit 3af3af3
Showing
7 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
test/built-ins/ArrayBuffer/prototype/byteLength/detached-buffer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
19 changes: 19 additions & 0 deletions
19
test/built-ins/ArrayBuffer/prototype/byteLength/invoked-as-accessor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
test/built-ins/ArrayBuffer/prototype/byteLength/invoked-as-func.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
test/built-ins/ArrayBuffer/prototype/byteLength/prop-desc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
19 changes: 19 additions & 0 deletions
19
test/built-ins/ArrayBuffer/prototype/byteLength/return-bytelength.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
40 changes: 40 additions & 0 deletions
40
test/built-ins/ArrayBuffer/prototype/byteLength/this-has-no-typedarrayname-internal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
47 changes: 47 additions & 0 deletions
47
test/built-ins/ArrayBuffer/prototype/byteLength/this-is-not-object.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |