Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests for TypedArrays, DataView and ArrayBuffer #669

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions test/built-ins/ArrayBuffer/length-is-absent.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// 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.2.1
esid: sec-arraybuffer-length
description: >
The `length` parameter must be a positive, numeric integral value.
info: >
Returns an empty instance if length is absent
info: |
ArrayBuffer( length )

...
2. Let numberLength be ToNumber(length).
3. Let byteLength be ToLength(numberLength).
4. ReturnIfAbrupt(byteLength).
5. If SameValueZero(numberLength, byteLength) is false, throw a RangeError exception.
...
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Return ? AllocateArrayBuffer(NewTarget, byteLength).
---*/

assert.throws(RangeError, function() {
new ArrayBuffer();
}, "`length` parameter absent");
var buffer = new ArrayBuffer();

assert.sameValue(buffer.byteLength, 0);
35 changes: 0 additions & 35 deletions test/built-ins/ArrayBuffer/length-is-not-number.js

This file was deleted.

32 changes: 32 additions & 0 deletions test/built-ins/ArrayBuffer/length-is-too-large-throws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
es6id: 24.1.2.1
esid: sec-arraybuffer-length
description: >
Throws a RangeError if length >= 2 ** 53
info: >
ArrayBuffer( length )

1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).

ToIndex( value )

1. If value is undefined, then
a. Let index be 0.
2. Else,
a. Let integerIndex be ? ToInteger(value).
b. If integerIndex < 0, throw a RangeError exception.
...
---*/

assert.throws(RangeError, function() {
// Math.pow(2, 53) = 9007199254740992
new ArrayBuffer(9007199254740992);
}, "`length` parameter is too large");

assert.throws(RangeError, function() {
new ArrayBuffer(Infinity);
}, "`length` parameter is positive Infinity");
34 changes: 34 additions & 0 deletions test/built-ins/ArrayBuffer/negative-length-throws.js
Original file line number Diff line number Diff line change
@@ -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.

/*---
esid: sec-arraybuffer-length
description: >
Throws a Range Error if length represents an integer < 0
info: |
ArrayBuffer( length )

1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).

ToIndex( value )

1. If value is undefined, then
a. Let index be 0.
2. Else,
a. Let integerIndex be ? ToInteger(value).
b. If integerIndex < 0, throw a RangeError exception.
...
---*/

assert.throws(RangeError, function() {
new ArrayBuffer(-1);
});

assert.throws(RangeError, function() {
new ArrayBuffer(-1.1);
});

assert.throws(RangeError, function() {
new ArrayBuffer(-Infinity);
});
27 changes: 0 additions & 27 deletions test/built-ins/ArrayBuffer/number-conversion.js

This file was deleted.

42 changes: 0 additions & 42 deletions test/built-ins/ArrayBuffer/positive-integer-length.js

This file was deleted.

21 changes: 21 additions & 0 deletions test/built-ins/ArrayBuffer/return-abrupt-from-length-symbol.js
Original file line number Diff line number Diff line change
@@ -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-arraybuffer-length
description: >
Throws a TypeError if length is a symbol
info: |
ArrayBuffer( length )

1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
...
features: [Symbol]
---*/

var s = Symbol();

assert.throws(TypeError, function() {
new ArrayBuffer(s);
}, "`length` parameter is a Symbol");
24 changes: 24 additions & 0 deletions test/built-ins/ArrayBuffer/return-abrupt-from-length.js
Original file line number Diff line number Diff line change
@@ -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-arraybuffer-length
description: >
Return abrupt from ToIndex(length)
info: |
ArrayBuffer( length )

1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
...
---*/

var len = {
valueOf: function() {
throw new Test262Error();
}
};

assert.throws(Test262Error, function() {
new ArrayBuffer(len);
});
87 changes: 87 additions & 0 deletions test/built-ins/ArrayBuffer/toindex-length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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-arraybuffer-length
description: >
The `length` parameter is converted to a value numeric index value.
info: |
ArrayBuffer( length )

1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Return ? AllocateArrayBuffer(NewTarget, byteLength).

ToIndex( value )

1. If value is undefined, then
a. Let index be 0.
2. Else,
a. Let integerIndex be ? ToInteger(value).
b. If integerIndex < 0, throw a RangeError exception.
c. Let index be ! ToLength(integerIndex).
d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception.
3. Return index.
---*/

var obj1 = {
valueOf: function() {
return 42;
}
};

var obj2 = {
toString: function() {
return 42;
}
};

var buffer;

buffer = new ArrayBuffer(obj1);
assert.sameValue(buffer.byteLength, 42, "object's valueOf");

buffer = new ArrayBuffer(obj2);
assert.sameValue(buffer.byteLength, 42, "object's toString");

buffer = new ArrayBuffer("");
assert.sameValue(buffer.byteLength, 0, "the Empty string");

buffer = new ArrayBuffer("0");
assert.sameValue(buffer.byteLength, 0, "string '0'");

buffer = new ArrayBuffer("1");
assert.sameValue(buffer.byteLength, 1, "string '1'");

buffer = new ArrayBuffer(true);
assert.sameValue(buffer.byteLength, 1, "true");

buffer = new ArrayBuffer(false);
assert.sameValue(buffer.byteLength, 0, "false");

buffer = new ArrayBuffer(NaN);
assert.sameValue(buffer.byteLength, 0, "NaN");

buffer = new ArrayBuffer(null);
assert.sameValue(buffer.byteLength, 0, "null");

buffer = new ArrayBuffer(undefined);
assert.sameValue(buffer.byteLength, 0, "undefined");

buffer = new ArrayBuffer(0.1);
assert.sameValue(buffer.byteLength, 0, "0.1");

buffer = new ArrayBuffer(0.9);
assert.sameValue(buffer.byteLength, 0, "0.9");

buffer = new ArrayBuffer(1.1);
assert.sameValue(buffer.byteLength, 1, "1.1");

buffer = new ArrayBuffer(1.9);
assert.sameValue(buffer.byteLength, 1, "1.9");

buffer = new ArrayBuffer(-0.1);
assert.sameValue(buffer.byteLength, 0, "-0.1");

buffer = new ArrayBuffer(-0.99999);
assert.sameValue(buffer.byteLength, 0, "-0.99999");

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ description: >
info: |
24.2.2.1 DataView (buffer, byteOffset, byteLength )

...
8. If byteLength is either not present or undefined, then
a. Let viewByteLength be bufferByteLength - offset.
...
17. Return O.
---*/
Expand Down
Loading