diff --git a/test/built-ins/DataView/prototype/byteOffset/detached-buffer.js b/test/built-ins/DataView/prototype/byteOffset/detached-buffer.js new file mode 100644 index 0000000000..c61dd51fb0 --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/detached-buffer.js @@ -0,0 +1,25 @@ +// 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-get-dataview.prototype.byteoffset +es6id: 24.2.4.3 +description: Throws a TypeError if the instance has a detached buffer +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. 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.byteOffset; +}); diff --git a/test/built-ins/DataView/prototype/byteOffset/invoked-as-accessor.js b/test/built-ins/DataView/prototype/byteOffset/invoked-as-accessor.js new file mode 100644 index 0000000000..890277096c --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/invoked-as-accessor.js @@ -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-get-dataview.prototype.byteoffset +es6id: 24.2.4.3 +description: > + Requires this value to have a [[DataView]] internal slot +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + DataView.prototype.byteOffset; +}); diff --git a/test/built-ins/DataView/prototype/byteOffset/invoked-as-func.js b/test/built-ins/DataView/prototype/byteOffset/invoked-as-func.js new file mode 100644 index 0000000000..c95f62525e --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/invoked-as-func.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. + +/*--- +esid: sec-get-dataview.prototype.byteoffset +es6id: 24.2.4.3 +description: Throws a TypeError exception when invoked as a function +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, 'byteOffset' +).get; + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/built-ins/DataView/prototype/byteOffset/prop-desc.js b/test/built-ins/DataView/prototype/byteOffset/prop-desc.js new file mode 100644 index 0000000000..d86cce071b --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/prop-desc.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. + +/*--- +esid: sec-get-dataview.prototype.byteoffset +es6id: 24.2.4.3 +description: > + "byteOffset" property of DataView.prototype +info: | + DataView.prototype.byteOffset is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(DataView.prototype, "byteOffset"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(DataView.prototype, "byteOffset"); +verifyConfigurable(DataView.prototype, "byteOffset"); diff --git a/test/built-ins/DataView/prototype/byteOffset/return-byteoffset.js b/test/built-ins/DataView/prototype/byteOffset/return-byteoffset.js new file mode 100644 index 0000000000..d743a8d920 --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/return-byteoffset.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. + +/*--- +esid: sec-get-dataview.prototype.byteoffset +es6id: 24.2.4.3 +description: > + Return value from [[ByteOffset]] internal slot +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + ... + 7. Let offset be the value of O's [[ByteOffset]] internal slot. + 8. Return offset. +---*/ + +var buffer = new ArrayBuffer(12); + +var sample1 = new DataView(buffer, 0); +var sample2 = new DataView(buffer, 4); +var sample3 = new DataView(buffer, 6, 4); +var sample4 = new DataView(buffer, 12); +var sample5 = new DataView(buffer, 0, 2); + +assert.sameValue(sample1.byteOffset, 0); +assert.sameValue(sample2.byteOffset, 4); +assert.sameValue(sample3.byteOffset, 6); +assert.sameValue(sample4.byteOffset, 12); +assert.sameValue(sample5.byteOffset, 0); diff --git a/test/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal.js b/test/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..e2d410bf3c --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal.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-get-dataview.prototype.byteoffset +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "byteOffset" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getter.call([]); +}, "[]"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getter.call(ta); +}, "TypedArray"); diff --git a/test/built-ins/DataView/prototype/byteOffset/this-is-not-object.js b/test/built-ins/DataView/prototype/byteOffset/this-is-not-object.js new file mode 100644 index 0000000000..7e2038254c --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/this-is-not-object.js @@ -0,0 +1,48 @@ +// 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-get-dataview.prototype.byteoffset +es6id: 24.2.4.3 +description: Throws a TypeError exception when `this` is not Object +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "byteOffset" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol");