Skip to content

Commit

Permalink
Merge pull request #1316 from cxielarko/setbigint64
Browse files Browse the repository at this point in the history
setBigInt64 tests
  • Loading branch information
rwaldron authored Nov 1, 2017
2 parents 9d7378c + 2f20235 commit bbdf494
Show file tree
Hide file tree
Showing 21 changed files with 639 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Detached buffer is checked after ToBigInt(value)
includes: [detachArrayBuffer.js]
features: [DataView, ArrayBuffer, BigInt]
---*/

var buffer = new ArrayBuffer(8);
var sample = new DataView(buffer, 0);

var v = { valueOf() { throw new Test262Error(); } };

$DETACHBUFFER(buffer);
assert.throws(Test262Error, function() {
sample.setBigInt64(0, v);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Detached buffer is only checked after ToIndex(requestIndex)
includes: [detachArrayBuffer.js]
features: [DataView, ArrayBuffer, BigInt]
---*/

var buffer = new ArrayBuffer(12);
var sample = new DataView(buffer, 0);

$DETACHBUFFER(buffer);

assert.throws(RangeError, function() {
sample.setBigInt64(Infinity, 0);
}, "DataView access at index Infinity should throw");

assert.throws(RangeError, function() {
sample.setBigInt64(-1, 0);
}, "DataView access at index -1 should throw");
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Detached buffer is checked before out of range byteOffset's value
includes: [detachArrayBuffer.js]
features: [DataView, ArrayBuffer, BigInt]
---*/

var sample;
var buffer = new ArrayBuffer(12);

sample = new DataView(buffer, 0);

$DETACHBUFFER(buffer);

assert.throws(TypeError, function() {
sample.setBigInt64(13, 0);
}, "detached DataView access should throw");
18 changes: 18 additions & 0 deletions test/built-ins/DataView/prototype/setBigInt64/detached-buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Throws a TypeError if buffer is detached
includes: [detachArrayBuffer.js]
features: [DataView, ArrayBuffer, BigInt]
---*/

var buffer = new ArrayBuffer(1);
var sample = new DataView(buffer, 0);

$DETACHBUFFER(buffer);
assert.throws(TypeError, function() {
sample.setBigInt64(0, 0n);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
RangeError exception for negative or non-integral index is thrown before
the value conversion.
features: [DataView, ArrayBuffer, BigInt]
---*/

var dataView = new DataView(new ArrayBuffer(8), 0);

var poisoned = {
valueOf() { throw new Test262Error("valueOf called"); }
};

assert.throws(RangeError, function() {
dataView.setBigInt64(-1.5, poisoned);
}, "setBigInt64(-1.5, poisoned)");

assert.throws(RangeError, function() {
dataView.setBigInt64(-1, poisoned);
}, "setBigInt64(-1, poisoned)");

assert.throws(RangeError, function() {
dataView.setBigInt64(-Infinity, poisoned);
}, "setBigInt64(-Infinity, poisoned)");

assert.throws(RangeError, function() {
dataView.setBigInt64(Infinity, poisoned);
}, "setBigInt64(Infinity, poisoned)");
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Throws a RangeError if getIndex + elementSize > viewSize
features: [DataView, ArrayBuffer, BigInt]
---*/

var sample;
var buffer = new ArrayBuffer(12);

sample = new DataView(buffer, 0);

assert.throws(RangeError, function() {
sample.setBigInt64(Infinity, 39n);
}, "getIndex == Infinity");

assert.throws(RangeError, function() {
sample.setBigInt64(13, 39n);
}, "13 + 8 > 12");

assert.throws(RangeError, function() {
sample.setBigInt64(12, 39n);
}, "12 + 8 > 12");

assert.throws(RangeError, function() {
sample.setBigInt64(11, 39n);
}, "11 + 8 > 12");

assert.throws(RangeError, function() {
sample.setBigInt64(10, 39n);
}, "10 + 8 > 12");

assert.throws(RangeError, function() {
sample.setBigInt64(9, 39n);
}, "9 + 8 > 12");

assert.throws(RangeError, function() {
sample.setBigInt64(8, 39n);
}, "8 + 8 > 12");

assert.throws(RangeError, function() {
sample.setBigInt64(7, 39n);
}, "7 + 8 > 12");

assert.throws(RangeError, function() {
sample.setBigInt64(6, 39n);
}, "6 + 8 > 12");

assert.throws(RangeError, function() {
sample.setBigInt64(5, 39n);
}, "5 + 8 > 12");

sample = new DataView(buffer, 8);
assert.throws(RangeError, function() {
sample.setBigInt64(1, 39n);
}, "1 + 8 > 4 (offset)");

sample = new DataView(buffer, 9);
assert.throws(RangeError, function() {
sample.setBigInt64(0, 39n);
}, "0 + 8 > 3 (offset)");

sample = new DataView(buffer, 0, 8);
assert.throws(RangeError, function() {
sample.setBigInt64(1, 39n);
}, "1 + 8 > 8 (length)");

sample = new DataView(buffer, 0, 7);
assert.throws(RangeError, function() {
sample.setBigInt64(0, 39n);
}, "0 + 8 > 7 (length)");

sample = new DataView(buffer, 4, 8);
assert.throws(RangeError, function() {
sample.setBigInt64(1, 39n);
}, "1 + 8 > 8 (offset+length)");

sample = new DataView(buffer, 4, 7);
assert.throws(RangeError, function() {
sample.setBigInt64(0, 39n);
}, "0 + 8 > 7 (offset+length)");

sample = new DataView(buffer, 0);
assert.sameValue(sample.getBigInt64(0), 0n, "[0] no value was set");
assert.sameValue(sample.getBigInt64(4), 0n, "[1] no value was set");
16 changes: 16 additions & 0 deletions test/built-ins/DataView/prototype/setBigInt64/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: DataView.prototype.setBigInt64.length property descriptor
includes: [propertyHelper.js]
features: [DataView, ArrayBuffer, BigInt]
---*/

verifyProperty(DataView.prototype.setBigInt64, "length", {
value: 2,
writable: false,
enumerable: false,
configurable: true
});
16 changes: 16 additions & 0 deletions test/built-ins/DataView/prototype/setBigInt64/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: DataView.prototype.setBigInt64.name property descriptor
includes: [propertyHelper.js]
features: [DataView, ArrayBuffer, BigInt]
---*/

verifyProperty(DataView.prototype.setBigInt64, "name", {
value: "setBigInt64",
writable: false,
enumerable: false,
configurable: true
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Throws a RangeError if getIndex < 0
features: [DataView, ArrayBuffer, BigInt]
---*/

var buffer = new ArrayBuffer(12);
var sample = new DataView(buffer, 0);

assert.throws(RangeError, function() {
sample.setBigInt64(-1, 39n);
}, "DataView access at index -1 should throw");
assert.sameValue(sample.getBigInt64(0), 0n, "-1 - no value was set");

assert.throws(RangeError, function() {
sample.setBigInt64(-Infinity, 39n);
}, "DataView access at index -Infinity should throw");
assert.sameValue(sample.getBigInt64(0), 0n, "-Infinity - no value was set");
14 changes: 14 additions & 0 deletions test/built-ins/DataView/prototype/setBigInt64/no-value-arg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Set value as undefined (cast to 0) when value argument is not present
features: [DataView, ArrayBuffer, BigInt, arrow-function]
---*/

var buffer = new ArrayBuffer(8);
var sample = new DataView(buffer, 0);

assert.throws(TypeError, () => sample.setBigInt64(0));
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Index bounds checks are performed after value conversion.
features: [DataView, ArrayBuffer, BigInt]
---*/

var dataView = new DataView(new ArrayBuffer(8), 0);

var poisoned = { valueOf() { throw new Test262Error(); } };

assert.throws(Test262Error, function() {
dataView.setBigInt64(100, poisoned);
}, "setBigInt64(100, poisoned)");

assert.throws(Test262Error, function() {
dataView.setBigInt64('100', poisoned);
}, "setBigInt64('100', poisoned)");
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Return abrupt from ToBigInt(symbol value)
features: [DataView, ArrayBuffer, Symbol, BigInt]
---*/

var buffer = new ArrayBuffer(8);
var sample = new DataView(buffer, 0);

var s = Symbol("1");

assert.throws(TypeError, function() {
sample.setBigInt64(0, s);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Return abrupt from ToBigInt(value)
features: [DataView, ArrayBuffer, BigInt]
---*/

var buffer = new ArrayBuffer(8);
var sample = new DataView(buffer, 0);

var bo1 = { valueOf() { throw new Test262Error(); } };
var bo2 = { toString() { throw new Test262Error(); } };

assert.throws(Test262Error, function() {
sample.setBigInt64(0, bo1);
}, "valueOf");

assert.throws(Test262Error, function() {
sample.setBigInt64(0, bo2);
}, "toString");
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Return abrupt from ToNumber(symbol byteOffset)
features: [DataView, ArrayBuffer, Symbol, BigInt]
---*/

var buffer = new ArrayBuffer(1);
var sample = new DataView(buffer, 0);

var s = Symbol("1");

assert.throws(TypeError, function() {
sample.setBigInt64(s, 1n);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setbigint64
description: >
Return abrupt from ToNumber(byteOffset)
features: [DataView, ArrayBuffer, BigInt]
---*/

var buffer = new ArrayBuffer(1);
var sample = new DataView(buffer, 0);

var bo1 = { valueOf() { throw new Test262Error(); } };
var bo2 = { toString() { throw new Test262Error(); } };

assert.throws(Test262Error, function() {
sample.setBigInt64(bo1, 1n);
}, "valueOf");

assert.throws(Test262Error, function() {
sample.setBigInt64(bo2, 1n);
}, "toString");
Loading

0 comments on commit bbdf494

Please sign in to comment.