-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tests for TypedArrays, DataView and ArrayBuffer
Ref tc39/ecma262#410
- Loading branch information
1 parent
dee1526
commit cfc77c8
Showing
117 changed files
with
2,179 additions
and
2,969 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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); |
This file was deleted.
Oops, something went wrong.
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,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"); |
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,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); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
test/built-ins/ArrayBuffer/return-abrupt-from-length-symbol.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,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"); |
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,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); | ||
}); |
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,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"); |
File renamed without changes.
43 changes: 0 additions & 43 deletions
43
test/built-ins/DataView/byteoffset-tonumber-diffs-tointeger-throws.js
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.