diff --git a/test/built-ins/DataView/prototype/getFloat64/byteoffset-is-different-integer-throws.js b/test/built-ins/DataView/prototype/getFloat64/byteoffset-is-different-integer-throws.js new file mode 100644 index 0000000000..7f786beceb --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/byteoffset-is-different-integer-throws.js @@ -0,0 +1,54 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Throws a RangeError if numberIndex ≠ getIndex +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + 5. Let getIndex be ToInteger(numberIndex). + 6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception. + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getFloat64(); +}, "no args"); + +assert.throws(RangeError, function() { + sample.getFloat64(undefined); +}, "undefined"); + +assert.throws(RangeError, function() { + sample.getFloat64(1.1); +}, "floating number"); + +assert.throws(RangeError, function() { + sample.getFloat64(0.1); +}, "0.1"); + +assert.throws(RangeError, function() { + sample.getFloat64(NaN); +}, "NaN"); + +assert.throws(RangeError, function() { + sample.getFloat64(-0.1); +}, "-0.1"); + +assert.throws(RangeError, function() { + sample.getFloat64(-1.1); +}, "-1.1"); diff --git a/test/built-ins/DataView/prototype/getFloat64/byteoffset-is-negative-throws.js b/test/built-ins/DataView/prototype/getFloat64/byteoffset-is-negative-throws.js new file mode 100644 index 0000000000..0abb4d512f --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/byteoffset-is-negative-throws.js @@ -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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + 5. Let getIndex be ToInteger(numberIndex). + 6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception. + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getFloat64(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getFloat64(-Infinity); +}, "-Infinity"); diff --git a/test/built-ins/DataView/prototype/getFloat64/detached-buffer-after-integer-byteoffset.js b/test/built-ins/DataView/prototype/getFloat64/detached-buffer-after-integer-byteoffset.js new file mode 100644 index 0000000000..0cd537b058 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/detached-buffer-after-integer-byteoffset.js @@ -0,0 +1,38 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Detached buffer is checked after checking If numberIndex ≠ getIndex or + getIndex < 0, +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception. + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(10); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(RangeError, function() { + sample.getFloat64(1.1); +}); + +assert.throws(RangeError, function() { + sample.getFloat64(-1); +}); diff --git a/test/built-ins/DataView/prototype/getFloat64/detached-buffer-before-outofrange-byteoffset.js b/test/built-ins/DataView/prototype/getFloat64/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..81d349941b --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/detached-buffer-before-outofrange-byteoffset.js @@ -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. + +/*--- +esid: sec-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.getFloat64(Infinity); +}, "Infinity"); + +assert.throws(TypeError, function() { + sample.getFloat64(13); +}, "13"); diff --git a/test/built-ins/DataView/prototype/getFloat64/detached-buffer.js b/test/built-ins/DataView/prototype/getFloat64/detached-buffer.js new file mode 100644 index 0000000000..7320ba3f80 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/detached-buffer.js @@ -0,0 +1,31 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.getFloat64(0); +}); diff --git a/test/built-ins/DataView/prototype/getFloat64/index-is-out-of-range.js b/test/built-ins/DataView/prototype/getFloat64/index-is-out-of-range.js new file mode 100644 index 0000000000..594dc60e7d --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/index-is-out-of-range.js @@ -0,0 +1,100 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getFloat64(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getFloat64(13); +}, "13 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(12); +}, "12 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(11); +}, "11 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(10); +}, "10 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(9); +}, "9 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(8); +}, "8 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(7); +}, "7 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(6); +}, "6 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(5); +}, "5 + 8 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.getFloat64(1); +}, "1 + 8 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.getFloat64(0); +}, "0 + 8 > 3 (offset)"); + +sample = new DataView(buffer, 0, 8); +assert.throws(RangeError, function() { + sample.getFloat64(1); +}, "1 + 8 > 8 (length)"); + +sample = new DataView(buffer, 0, 7); +assert.throws(RangeError, function() { + sample.getFloat64(0); +}, "0 + 8 > 7 (length)"); + +sample = new DataView(buffer, 4, 8); +assert.throws(RangeError, function() { + sample.getFloat64(1); +}, "1 + 8 > 8 (offset+length)"); + +sample = new DataView(buffer, 4, 7); +assert.throws(RangeError, function() { + sample.getFloat64(0); +}, "0 + 8 > 7 (offset+length)"); diff --git a/test/built-ins/DataView/prototype/getFloat64/minus-zero.js b/test/built-ins/DataView/prototype/getFloat64/minus-zero.js new file mode 100644 index 0000000000..281867a98b --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/minus-zero.js @@ -0,0 +1,45 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Return -0 +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 128); +sample.setUint8(1, 0); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); + +var result = sample.getFloat64(0); +assert.sameValue(result, -0); diff --git a/test/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset-symbol.js b/test/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..73f33b8f51 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset-symbol.js @@ -0,0 +1,31 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getFloat64(s); +}); diff --git a/test/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset.js b/test/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..ce76ae7b78 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getFloat64(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getFloat64(bo2); +}, "toString"); diff --git a/test/built-ins/DataView/prototype/getFloat64/return-infinity.js b/test/built-ins/DataView/prototype/getFloat64/return-infinity.js new file mode 100644 index 0000000000..f81292a9b9 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/return-infinity.js @@ -0,0 +1,53 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Return Infinity values +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 240); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), Infinity); + +sample.setUint8(0, 255); +sample.setUint8(1, 240); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), -Infinity); diff --git a/test/built-ins/DataView/prototype/getFloat64/return-nan.js b/test/built-ins/DataView/prototype/getFloat64/return-nan.js new file mode 100644 index 0000000000..4184437bfb --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/return-nan.js @@ -0,0 +1,73 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Return NaN values +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 248); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), NaN, "127, 248, 0, ..."); + +sample.setUint8(0, 127); +sample.setUint8(1, 249); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), NaN, "127, 249, 0, ..."); + +sample.setUint8(0, 127); +sample.setUint8(1, 250); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), NaN, "127, 250, 0, ..."); + +sample.setUint8(0, 127); +sample.setUint8(1, 251); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), NaN, "127, 251, 0, ..."); diff --git a/test/built-ins/DataView/prototype/getFloat64/return-value-clean-arraybuffer.js b/test/built-ins/DataView/prototype/getFloat64/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..1249a2b6eb --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/return-value-clean-arraybuffer.js @@ -0,0 +1,43 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getFloat64(0, true), 0, "sample.getFloat64(0, true)"); +assert.sameValue(sample.getFloat64(1, true), 0, "sample.getFloat64(1, true)"); +assert.sameValue(sample.getFloat64(2, true), 0, "sample.getFloat64(2, true)"); +assert.sameValue(sample.getFloat64(3, true), 0, "sample.getFloat64(3, true)"); +assert.sameValue(sample.getFloat64(4, true), 0, "sample.getFloat64(4, true)"); +assert.sameValue(sample.getFloat64(0, false), 0, "sample.getFloat64(0, false)"); +assert.sameValue(sample.getFloat64(1, false), 0, "sample.getFloat64(1, false)"); +assert.sameValue(sample.getFloat64(2, false), 0, "sample.getFloat64(2, false)"); +assert.sameValue(sample.getFloat64(3, false), 0, "sample.getFloat64(3, false)"); +assert.sameValue(sample.getFloat64(4, false), 0, "sample.getFloat64(4, false)"); diff --git a/test/built-ins/DataView/prototype/getFloat64/return-values-coerced-byteoffset.js b/test/built-ins/DataView/prototype/getFloat64/return-values-coerced-byteoffset.js new file mode 100644 index 0000000000..31e95caad0 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/return-values-coerced-byteoffset.js @@ -0,0 +1,77 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Return values using coerced ToInteger byteOffset values +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(9); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 67); +sample.setUint8(1, 67); +sample.setUint8(2, 68); +sample.setUint8(3, 68); +sample.setUint8(4, 67); +sample.setUint8(5, 67); +sample.setUint8(6, 68); +sample.setUint8(7, 68); +sample.setUint8(8, 67); + +assert.sameValue(sample.getFloat64("", false), 10846169068898440, "'', false"); +assert.sameValue(sample.getFloat64("", true), 747563348316297500000, "'', true"); + +assert.sameValue(sample.getFloat64("0", false), 10846169068898440, "'0', false"); +assert.sameValue(sample.getFloat64("0", true), 747563348316297500000, "'0', true"); + +assert.sameValue(sample.getFloat64("1", false), 11409110432516230, "'1', false"); +assert.sameValue(sample.getFloat64("1", true), 11409110432516230, "'1', true"); + +var obj1 = { + valueOf: function() { + return 1; + } +}; +assert.sameValue(sample.getFloat64(obj1, false), 11409110432516230, "{}.valueOf, false"); +assert.sameValue(sample.getFloat64(obj1, true), 11409110432516230, "{}.valueOf, true"); + +var obj2 = { + toString: function() { + return 1; + } +}; +assert.sameValue(sample.getFloat64(obj2, false), 11409110432516230, "{}.toString, false"); +assert.sameValue(sample.getFloat64(obj2, true), 11409110432516230, "{}.toString, true"); + +assert.sameValue(sample.getFloat64(true, false), 11409110432516230, "true, false"); +assert.sameValue(sample.getFloat64(true, true), 11409110432516230, "true, true"); + +assert.sameValue(sample.getFloat64(false, false), 10846169068898440, "false, false"); +assert.sameValue(sample.getFloat64(false, true), 747563348316297500000, "false, true"); + +assert.sameValue(sample.getFloat64(null, false), 10846169068898440, "null, false"); +assert.sameValue(sample.getFloat64(null, true), 747563348316297500000, "null, true"); diff --git a/test/built-ins/DataView/prototype/getFloat64/return-values-custom-offset.js b/test/built-ins/DataView/prototype/getFloat64/return-values-custom-offset.js new file mode 100644 index 0000000000..884cf89ad2 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/return-values-custom-offset.js @@ -0,0 +1,60 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(16); +var sample = new DataView(buffer, 0); + +sample.setUint8(4, 67); +sample.setUint8(5, 67); +sample.setUint8(6, 68); +sample.setUint8(7, 68); +sample.setUint8(8, 67); +sample.setUint8(9, 67); +sample.setUint8(10, 68); +sample.setUint8(11, 68); +sample.setUint8(12, 67); +sample.setUint8(13, 67); +sample.setUint8(14, 68); +sample.setUint8(15, 68); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getFloat64(0, false), 10846169068898440, "0"); +assert.sameValue(sample.getFloat64(1, false), 11409110432516230, "1"); +assert.sameValue(sample.getFloat64(2, false), 747563348316297500000, "2"); +assert.sameValue(sample.getFloat64(3, false), 710670423110242000000, "3"); +assert.sameValue(sample.getFloat64(4, false), 10846169068898440, "4"); + +assert.sameValue(sample.getFloat64(0, true), 747563348316297500000, "0, true"); +assert.sameValue(sample.getFloat64(1, true), 11409110432516230, "1, true"); +assert.sameValue(sample.getFloat64(2, true), 10846169068898440, "2, true"); +assert.sameValue(sample.getFloat64(3, true), 710670423110242000000, "3, true"); +assert.sameValue(sample.getFloat64(4, true), 747563348316297500000, "4, true"); diff --git a/test/built-ins/DataView/prototype/getFloat64/return-values.js b/test/built-ins/DataView/prototype/getFloat64/return-values.js new file mode 100644 index 0000000000..b278e17144 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/return-values.js @@ -0,0 +1,70 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Return values from Buffer +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(16); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 67); +sample.setUint8(1, 67); +sample.setUint8(2, 68); +sample.setUint8(3, 68); +sample.setUint8(4, 67); +sample.setUint8(5, 67); +sample.setUint8(6, 68); +sample.setUint8(7, 68); +sample.setUint8(8, 67); +sample.setUint8(9, 67); +sample.setUint8(10, 68); +sample.setUint8(11, 68); +sample.setUint8(12, 0); +sample.setUint8(13, 0); +sample.setUint8(14, 0); +sample.setUint8(15, 0); + +assert.sameValue(sample.getFloat64(0, false), 10846169068898440, "0, false"); +assert.sameValue(sample.getFloat64(1, false), 11409110432516230, "1, false"); +assert.sameValue(sample.getFloat64(2, false), 747563348316297500000, "2, false"); +assert.sameValue(sample.getFloat64(3, false), 710670423110242000000, "3, false"); +assert.sameValue(sample.getFloat64(4, false), 10846169068898440, "4, false"); +assert.sameValue(sample.getFloat64(5, false), 11409110432516096, "5, false"); +assert.sameValue(sample.getFloat64(6, false), 747563348314040600000, "6, false"); +assert.sameValue(sample.getFloat64(7, false), 710670422532459300000, "7, false"); +assert.sameValue(sample.getFloat64(8, false), 10846166811934720, "8, false"); + +assert.sameValue(sample.getFloat64(0, true), 747563348316297500000, "0, true"); +assert.sameValue(sample.getFloat64(1, true), 11409110432516230, "1, true"); +assert.sameValue(sample.getFloat64(2, true), 10846169068898440, "2, true"); +assert.sameValue(sample.getFloat64(3, true), 710670423110242000000, "3, true"); +assert.sameValue(sample.getFloat64(4, true), 747563348316297500000, "4, true"); +assert.sameValue(sample.getFloat64(5, true), 2.254739805726094e-307, "5, true"); +assert.sameValue(sample.getFloat64(6, true), 3.7084555987028e-310, "6, true"); +assert.sameValue(sample.getFloat64(7, true), 1.44861546824e-312, "7, true"); +assert.sameValue(sample.getFloat64(8, true), 5.65865417e-315, "8, true"); diff --git a/test/built-ins/DataView/prototype/getFloat64/this-has-no-dataview-internal.js b/test/built-ins/DataView/prototype/getFloat64/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..5233c3e5e0 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/this-has-no-dataview-internal.js @@ -0,0 +1,43 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getFloat64 = DataView.prototype.getFloat64; + +assert.throws(TypeError, function() { + getFloat64.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getFloat64.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + getFloat64.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getFloat64.call(ta); +}, "TypedArray"); diff --git a/test/built-ins/DataView/prototype/getFloat64/this-is-not-object.js b/test/built-ins/DataView/prototype/getFloat64/this-is-not-object.js new file mode 100644 index 0000000000..d2dac02374 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/this-is-not-object.js @@ -0,0 +1,51 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getFloat64 = DataView.prototype.getFloat64; + +assert.throws(TypeError, function() { + getFloat64.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getFloat64.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getFloat64.call(1); +}, "1"); + +assert.throws(TypeError, function() { + getFloat64.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + getFloat64.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getFloat64.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + getFloat64.call(s); +}, "symbol"); diff --git a/test/built-ins/DataView/prototype/getFloat64/to-boolean-littleendian.js b/test/built-ins/DataView/prototype/getFloat64/to-boolean-littleendian.js new file mode 100644 index 0000000000..c06154d7d6 --- /dev/null +++ b/test/built-ins/DataView/prototype/getFloat64/to-boolean-littleendian.js @@ -0,0 +1,55 @@ +// 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-dataview.prototype.getfloat64 +es6id: 24.2.4.6 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 67); +sample.setUint8(1, 17); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 20); +sample.setUint8(7, 68); + +// False +assert.sameValue(sample.getFloat64(0), 1196268651021585, "no arg"); +assert.sameValue(sample.getFloat64(0, undefined), 1196268651021585, "undefined"); +assert.sameValue(sample.getFloat64(0, null), 1196268651021585, "null"); +assert.sameValue(sample.getFloat64(0, 0), 1196268651021585, "0"); +assert.sameValue(sample.getFloat64(0, ""), 1196268651021585, "the empty string"); + +// True +assert.sameValue(sample.getFloat64(0, {}), 92233720368620160000, "{}"); +assert.sameValue(sample.getFloat64(0, Symbol("1")), 92233720368620160000, "symbol"); +assert.sameValue(sample.getFloat64(0, 1), 92233720368620160000, "1"); +assert.sameValue(sample.getFloat64(0, "string"), 92233720368620160000, "string");