diff --git a/test/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws.js b/test/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws.js new file mode 100644 index 0000000000..a36e1c65c7 --- /dev/null +++ b/test/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws.js @@ -0,0 +1,42 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if buffer does not have [[ArrayBufferData]] +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 2. If Type(buffer) is not Object, throw a TypeError exception. + 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a + TypeError exception. + ... +features: [Int8Array] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error("buffer should be verified before byteOffset"); + } +}; + +assert.throws(TypeError, function() { + new DataView({}, obj); +}, "{}"); + +assert.throws(TypeError, function() { + new DataView([], obj); +}, "[]"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + new DataView(ta, obj); +}, "typedArray instance"); + +var other = new DataView(new ArrayBuffer(1), 0); +assert.throws(TypeError, function() { + new DataView(other, obj); +}, "dataView instance"); diff --git a/test/built-ins/DataView/buffer-not-object-throws.js b/test/built-ins/DataView/buffer-not-object-throws.js new file mode 100644 index 0000000000..5725787ead --- /dev/null +++ b/test/built-ins/DataView/buffer-not-object-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. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if buffer is not Object +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. If Type(buffer) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error("buffer should be verified before byteOffset"); + } +}; + +assert.throws(TypeError, function() { + new DataView(0, obj); +}, "0"); + +assert.throws(TypeError, function() { + new DataView(1, obj); +}, "1"); + +assert.throws(TypeError, function() { + new DataView("", obj); +}, "the empty string"); + +assert.throws(TypeError, function() { + new DataView("buffer", obj); +}, "string"); + +assert.throws(TypeError, function() { + new DataView(false, obj); +}, "false"); + +assert.throws(TypeError, function() { + new DataView(true, obj); +}, "true"); + +assert.throws(TypeError, function() { + new DataView(NaN, obj); +}, "NaN"); + +assert.throws(TypeError, function() { + new DataView(Symbol("1"), obj); +}, "symbol"); diff --git a/test/built-ins/DataView/buffer-reference.js b/test/built-ins/DataView/buffer-reference.js new file mode 100644 index 0000000000..c370e8d119 --- /dev/null +++ b/test/built-ins/DataView/buffer-reference.js @@ -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. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Reuse buffer argument instead of making a new clone +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 14. Set O's [[ViewedArrayBuffer]] internal slot to buffer. + ... + 17. Return O. +---*/ + +var buffer = new ArrayBuffer(8); + +var dv1 = new DataView(buffer, 0); +var dv2 = new DataView(buffer, 0); + +assert.sameValue(dv1.buffer, buffer); +assert.sameValue(dv2.buffer, buffer); diff --git a/test/built-ins/DataView/byteoffset-is-negative-throws.js b/test/built-ins/DataView/byteoffset-is-negative-throws.js new file mode 100644 index 0000000000..0ba90b42d9 --- /dev/null +++ b/test/built-ins/DataView/byteoffset-is-negative-throws.js @@ -0,0 +1,27 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToInteger(byteOffset) < 0 +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + 5. Let offset be ToInteger(numberOffset). + 6. If numberOffset ≠ offset or offset < 0, throw a RangeError exception. + ... +---*/ + +var ab = new ArrayBuffer(42); + +assert.throws(RangeError, function() { + new DataView(ab, -1); +}, "-1"); + +assert.throws(RangeError, function() { + new DataView(ab, -Infinity); +}, "-Infinity"); diff --git a/test/built-ins/DataView/byteoffset-tonumber-diffs-tointeger-throws.js b/test/built-ins/DataView/byteoffset-tonumber-diffs-tointeger-throws.js new file mode 100644 index 0000000000..58d63d8192 --- /dev/null +++ b/test/built-ins/DataView/byteoffset-tonumber-diffs-tointeger-throws.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. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToNumber(byteOffset) diffs ToInteger(byteOffset) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + 5. Let offset be ToInteger(numberOffset). + 6. If numberOffset ≠ offset or offset < 0, throw a RangeError exception. + ... +---*/ + +var ab = new ArrayBuffer(42); + +assert.throws(RangeError, function() { + new DataView(ab, 1.1); +}, "1.1"); + +assert.throws(RangeError, function() { + new DataView(ab, 0.0000001); +}, "0.0000001"); + +assert.throws(RangeError, function() { + new DataView(ab, NaN); +}, "NaN"); + +assert.throws(RangeError, function() { + new DataView(ab, -1.1); +}, "-1.1"); + +assert.throws(RangeError, function() { + new DataView(ab, undefined); +}, "undefined"); + +assert.throws(RangeError, function() { + new DataView(ab); +}, "no byteOffset arg"); diff --git a/test/built-ins/DataView/constructor.js b/test/built-ins/DataView/constructor.js new file mode 100644 index 0000000000..5d52c3b0bd --- /dev/null +++ b/test/built-ins/DataView/constructor.js @@ -0,0 +1,12 @@ +// 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-constructor +es6id: 24.2.2 +description: > + The DataView constructor is the %DataView% intrinsic object and the initial + value of the DataView property of the global object. +---*/ + +assert.sameValue(typeof DataView, "function", "`typeof DataView` is `'function'`"); diff --git a/test/built-ins/DataView/custom-proto-access-throws.js b/test/built-ins/DataView/custom-proto-access-throws.js new file mode 100644 index 0000000000..15b480a688 --- /dev/null +++ b/test/built-ins/DataView/custom-proto-access-throws.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. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from newTarget's custom constructor prototype +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +features: [Reflect.construct] +---*/ + +var buffer = new ArrayBuffer(8); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.construct(DataView, [buffer, 0], newTarget); +}); diff --git a/test/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype.js b/test/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype.js new file mode 100644 index 0000000000..09b7aaf856 --- /dev/null +++ b/test/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype.js @@ -0,0 +1,46 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Use DataView.prototype if newTarget's prototype is not an Object +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + ... +features: [Reflect.construct] +---*/ + +var buffer = new ArrayBuffer(8); + +function newTarget() {} +newTarget.prototype = null; + +var sample = Reflect.construct(DataView, [buffer, 0], newTarget); + +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/custom-proto-if-object-is-used.js b/test/built-ins/DataView/custom-proto-if-object-is-used.js new file mode 100644 index 0000000000..fa20c9c792 --- /dev/null +++ b/test/built-ins/DataView/custom-proto-if-object-is-used.js @@ -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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Use newTarget's custom constructor prototype if Object +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + ... +features: [Reflect.construct] +---*/ + +var buffer = new ArrayBuffer(8); + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +var sample = Reflect.construct(DataView, [buffer, 0], newTarget); + +assert.sameValue(sample.constructor, Object); +assert.sameValue(Object.getPrototypeOf(sample), proto); diff --git a/test/built-ins/DataView/dataview.js b/test/built-ins/DataView/dataview.js new file mode 100644 index 0000000000..1b554183af --- /dev/null +++ b/test/built-ins/DataView/dataview.js @@ -0,0 +1,14 @@ +// 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-constructor +es6id: 24.2.2 +description: > + The DataView Constructor +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(this, "DataView"); +verifyWritable(this, "DataView"); +verifyConfigurable(this, "DataView"); diff --git a/test/built-ins/DataView/defined-bytelength-and-byteoffset.js b/test/built-ins/DataView/defined-bytelength-and-byteoffset.js new file mode 100644 index 0000000000..679634af62 --- /dev/null +++ b/test/built-ins/DataView/defined-bytelength-and-byteoffset.js @@ -0,0 +1,59 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined length and offset +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +---*/ + +var sample; +var buffer = new ArrayBuffer(3); + +sample = new DataView(buffer, 1, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1, 0); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 3); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3, 0); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 1); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/defined-byteoffset-undefined-bytelength.js b/test/built-ins/DataView/defined-byteoffset-undefined-bytelength.js new file mode 100644 index 0000000000..6430e4df37 --- /dev/null +++ b/test/built-ins/DataView/defined-byteoffset-undefined-bytelength.js @@ -0,0 +1,52 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined byteoffset and undefined bytelength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +---*/ + +var sample; +var buffer = new ArrayBuffer(4); + +sample = new DataView(buffer, 0, undefined); +assert.sameValue(sample.byteLength, 4, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1, undefined); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 2, undefined); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 2, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3, undefined); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 4, undefined); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 4, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/defined-byteoffset.js b/test/built-ins/DataView/defined-byteoffset.js new file mode 100644 index 0000000000..dd842ab2c2 --- /dev/null +++ b/test/built-ins/DataView/defined-byteoffset.js @@ -0,0 +1,52 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined offset +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +---*/ + +var sample; +var buffer = new ArrayBuffer(4); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.byteLength, 4, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 2, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 4); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 4, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/defined-negative-bytelength.js b/test/built-ins/DataView/defined-negative-bytelength.js new file mode 100644 index 0000000000..808435659d --- /dev/null +++ b/test/built-ins/DataView/defined-negative-bytelength.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. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from negative lengths +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +---*/ + +var sample; +var buffer = new ArrayBuffer(2); + +sample = new DataView(buffer, 0, -1); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, -Infinity); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1, -1); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 2, -Infinity); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 2, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/detached-buffer.js b/test/built-ins/DataView/detached-buffer.js new file mode 100644 index 0000000000..edcb68e526 --- /dev/null +++ b/test/built-ins/DataView/detached-buffer.js @@ -0,0 +1,35 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + ... + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var toNumberOffset = 0; +var obj = { + valueOf: function() { + toNumberOffset += 1; + return 0; + } +}; + +var ab = new ArrayBuffer(42); +$DETACHBUFFER(ab); + +assert.throws(TypeError, function() { + new DataView(ab, obj); +}, "throws if buffer is detached"); + +assert.sameValue(toNumberOffset, 1, "ToNumber(byteOffset) runs before"); diff --git a/test/built-ins/DataView/excessive-bytelength-throws.js b/test/built-ins/DataView/excessive-bytelength-throws.js new file mode 100644 index 0000000000..374836415f --- /dev/null +++ b/test/built-ins/DataView/excessive-bytelength-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. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws RangeError if offset + viewByteLength > bufferByteLength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + ... + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + b. If offset+viewByteLength > bufferByteLength, throw a RangeError + exception. + ... +---*/ + +var buffer = new ArrayBuffer(3); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, 4); +}, "offset: 0, length 4"); + +assert.throws(RangeError, function() { + new DataView(buffer, 1, 3); +}, "offset: 1, length: 3"); + +assert.throws(RangeError, function() { + new DataView(buffer, 2, 2); +}, "offset: 2, length: 2"); + +assert.throws(RangeError, function() { + new DataView(buffer, 3, 1); +}, "offset: 3, length: 1"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, 0); +}, "offset: 4, length: 0"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, -1); +}, "offset: 4, length: -1"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, -Infinity); +}, "offset: 4, length: -Infinity"); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, Infinity); +}, "offset: 0, length: Infinity"); diff --git a/test/built-ins/DataView/excessive-byteoffset-throws.js b/test/built-ins/DataView/excessive-byteoffset-throws.js new file mode 100644 index 0000000000..b97d507a9b --- /dev/null +++ b/test/built-ins/DataView/excessive-byteoffset-throws.js @@ -0,0 +1,27 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if offset > bufferByteLength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 8. Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]] + internal slot. + 9. If offset > bufferByteLength, throw a RangeError exception. + ... +---*/ + +var ab = new ArrayBuffer(1); + +assert.throws(RangeError, function() { + new DataView(ab, 2); +}, "2"); + +assert.throws(RangeError, function() { + new DataView(ab, Infinity); +}, "Infinity"); diff --git a/test/built-ins/DataView/extensibility.js b/test/built-ins/DataView/extensibility.js new file mode 100644 index 0000000000..a0dbee8bdd --- /dev/null +++ b/test/built-ins/DataView/extensibility.js @@ -0,0 +1,16 @@ +// 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-constructor +es6id: 24.2.2 +description: > + The DataView constructor is extensible +info: | + 17 ECMAScript Standard Built-in Objects + + Unless specified otherwise, the [[Extensible]] internal slot of a built-in + object initially has the value true. +---*/ + +assert.sameValue(Object.isExtensible(DataView), true); diff --git a/test/built-ins/DataView/instance-extensibility.js b/test/built-ins/DataView/instance-extensibility.js new file mode 100644 index 0000000000..deb5e7f197 --- /dev/null +++ b/test/built-ins/DataView/instance-extensibility.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. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + The new instance is extensible +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.12 ObjectCreate (proto [ , internalSlotsList ]) + + ... + 5. Set the [[Extensible]] internal slot of obj to true. + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert(Object.isExtensible(sample)); diff --git a/test/built-ins/DataView/length.js b/test/built-ins/DataView/length.js new file mode 100644 index 0000000000..236e76b28b --- /dev/null +++ b/test/built-ins/DataView/length.js @@ -0,0 +1,16 @@ +// 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-constructor +es6id: 24.2.2 +description: > + The length property of DataView is 3 +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.length, 3, "The value of `DataView.length` is `3`"); + +verifyNotEnumerable(DataView, "length"); +verifyNotWritable(DataView, "length"); +verifyConfigurable(DataView, "length"); diff --git a/test/built-ins/DataView/name.js b/test/built-ins/DataView/name.js new file mode 100644 index 0000000000..bbe6740ddd --- /dev/null +++ b/test/built-ins/DataView/name.js @@ -0,0 +1,16 @@ +// 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-constructor +es6id: 24.2.2 +description: > + The name property of DataView is "DataView" +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.name, "DataView", "The value of `DataView.name` is `'DataView'`"); + +verifyNotEnumerable(DataView, "name"); +verifyNotWritable(DataView, "name"); +verifyConfigurable(DataView, "name"); diff --git a/test/built-ins/DataView/newtarget-undefined-throws.js b/test/built-ins/DataView/newtarget-undefined-throws.js new file mode 100644 index 0000000000..b3529e1f46 --- /dev/null +++ b/test/built-ins/DataView/newtarget-undefined-throws.js @@ -0,0 +1,26 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error("NewTarget should be verified before byteOffset"); + } +}; + +var buffer = new ArrayBuffer(1); + +assert.throws(TypeError, function() { + DataView(buffer, obj); +}); diff --git a/test/built-ins/DataView/proto.js b/test/built-ins/DataView/proto.js new file mode 100644 index 0000000000..513e215df9 --- /dev/null +++ b/test/built-ins/DataView/proto.js @@ -0,0 +1,14 @@ +// 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-properties-of-the-dataview-constructor +es6id: 24.2.3 +description: > + The prototype of DataView is Function.prototype +info: > + The value of the [[Prototype]] internal slot of the DataView constructor is + the intrinsic object %FunctionPrototype%. +---*/ + +assert.sameValue(Object.getPrototypeOf(DataView), Function.prototype); diff --git a/test/built-ins/DataView/prototype.js b/test/built-ins/DataView/prototype.js new file mode 100644 index 0000000000..0b3144c007 --- /dev/null +++ b/test/built-ins/DataView/prototype.js @@ -0,0 +1,20 @@ +// 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 +es6id: 24.2.3.1 +description: > + The initial value of DataView.prototype is the DataView prototype object. +info: > + The initial value of DataView.prototype is the intrinsic object + %DataViewPrototype%. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: false }. +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(DataView, "prototype"); +verifyNotWritable(DataView, "prototype"); +verifyNotConfigurable(DataView, "prototype"); diff --git a/test/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol.js b/test/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol.js new file mode 100644 index 0000000000..c9b5ba86cc --- /dev/null +++ b/test/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol.js @@ -0,0 +1,26 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToLength(symbol byteLength) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var length = Symbol("1"); + +assert.throws(TypeError, function() { + new DataView(buffer, 0, length); +}); diff --git a/test/built-ins/DataView/return-abrupt-tonumber-bytelength.js b/test/built-ins/DataView/return-abrupt-tonumber-bytelength.js new file mode 100644 index 0000000000..328cb21d54 --- /dev/null +++ b/test/built-ins/DataView/return-abrupt-tonumber-bytelength.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. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToLength(byteLength) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + ... +---*/ + +var buffer = new ArrayBuffer(8); + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + new DataView(buffer, 0, obj1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + new DataView(buffer, 0, obj2); +}, "toString"); diff --git a/test/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol.js b/test/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..53d484e841 --- /dev/null +++ b/test/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol.js @@ -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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + ... +features: [Symbol] +---*/ + +var s = Symbol("1"); +var ab = new ArrayBuffer(0); + +assert.throws(TypeError, function() { + new DataView(ab, s); +}); diff --git a/test/built-ins/DataView/return-abrupt-tonumber-byteoffset.js b/test/built-ins/DataView/return-abrupt-tonumber-byteoffset.js new file mode 100644 index 0000000000..af5e48261d --- /dev/null +++ b/test/built-ins/DataView/return-abrupt-tonumber-byteoffset.js @@ -0,0 +1,27 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + ... +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var ab = new ArrayBuffer(0); + +assert.throws(Test262Error, function() { + new DataView(ab, obj); +}); diff --git a/test/built-ins/DataView/return-instance.js b/test/built-ins/DataView/return-instance.js new file mode 100644 index 0000000000..2628419107 --- /dev/null +++ b/test/built-ins/DataView/return-instance.js @@ -0,0 +1,29 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Returns new instance +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. +---*/ + +var ab, sample; + +ab = new ArrayBuffer(1); +sample = new DataView(ab, 0); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +ab = new ArrayBuffer(1); +sample = new DataView(ab, 1); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/tolength-bytelength.js b/test/built-ins/DataView/tolength-bytelength.js new file mode 100644 index 0000000000..34d58c3f7d --- /dev/null +++ b/test/built-ins/DataView/tolength-bytelength.js @@ -0,0 +1,41 @@ +// 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.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + ToLength(byteLength) conversions +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +---*/ + +var sample; +var buffer = new ArrayBuffer(2); + +sample = new DataView(buffer, 0, true); +assert.sameValue(sample.byteLength, 1, "true"); + +sample = new DataView(buffer, 0, false); +assert.sameValue(sample.byteLength, 0, "false"); + +sample = new DataView(buffer, 0, "1"); +assert.sameValue(sample.byteLength, 1, "string 1"); + +sample = new DataView(buffer, 0, ""); +assert.sameValue(sample.byteLength, 0, "the empty string"); + +sample = new DataView(buffer, 0, [1]); +assert.sameValue(sample.byteLength, 1, "[1]"); + +sample = new DataView(buffer, 0, []); +assert.sameValue(sample.byteLength, 0, "[]"); + +sample = new DataView(buffer, 0, NaN); +assert.sameValue(sample.byteLength, 0, "NaN"); + +sample = new DataView(buffer, 0, null); +assert.sameValue(sample.byteLength, 0, "null");