From 7b529f00cbd84f46028905f73e47062beffb5ede Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Tue, 10 May 2016 15:08:58 -0400 Subject: [PATCH] Add tests for DataView.prototype.buffer --- .../prototype/buffer/detached-buffer.js | 21 ++++++++ .../prototype/buffer/invoked-as-accessor.js | 21 ++++++++ .../prototype/buffer/invoked-as-func.js | 24 ++++++++++ .../DataView/prototype/buffer/prop-desc.js | 24 ++++++++++ .../prototype/buffer/return-buffer.js | 20 ++++++++ .../buffer/this-has-no-dataview-internal.js | 40 ++++++++++++++++ .../prototype/buffer/this-is-not-object.js | 48 +++++++++++++++++++ 7 files changed, 198 insertions(+) create mode 100644 test/built-ins/DataView/prototype/buffer/detached-buffer.js create mode 100644 test/built-ins/DataView/prototype/buffer/invoked-as-accessor.js create mode 100644 test/built-ins/DataView/prototype/buffer/invoked-as-func.js create mode 100644 test/built-ins/DataView/prototype/buffer/prop-desc.js create mode 100644 test/built-ins/DataView/prototype/buffer/return-buffer.js create mode 100644 test/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal.js create mode 100644 test/built-ins/DataView/prototype/buffer/this-is-not-object.js diff --git a/test/built-ins/DataView/prototype/buffer/detached-buffer.js b/test/built-ins/DataView/prototype/buffer/detached-buffer.js new file mode 100644 index 0000000000..0e473ee24e --- /dev/null +++ b/test/built-ins/DataView/prototype/buffer/detached-buffer.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.buffer +es6id: 24.2.4.1 +description: The getter method does not throw with a detached buffer +info: | + 24.2.4.1 get DataView.prototype.buffer + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. Return buffer. +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(sample.buffer); +assert.sameValue(sample.buffer, buffer); diff --git a/test/built-ins/DataView/prototype/buffer/invoked-as-accessor.js b/test/built-ins/DataView/prototype/buffer/invoked-as-accessor.js new file mode 100644 index 0000000000..4816f83a6e --- /dev/null +++ b/test/built-ins/DataView/prototype/buffer/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.buffer +es6id: 24.2.4.1 +description: > + Requires this value to have a [[DataView]] internal slot +info: | + 24.2.4.1 get DataView.prototype.buffer + + 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.buffer; +}); diff --git a/test/built-ins/DataView/prototype/buffer/invoked-as-func.js b/test/built-ins/DataView/prototype/buffer/invoked-as-func.js new file mode 100644 index 0000000000..7033049496 --- /dev/null +++ b/test/built-ins/DataView/prototype/buffer/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.buffer +es6id: 24.2.4.1 +description: Throws a TypeError exception when invoked as a function +info: | + 24.2.4.1 get DataView.prototype.buffer + + 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, 'buffer' +).get; + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/built-ins/DataView/prototype/buffer/prop-desc.js b/test/built-ins/DataView/prototype/buffer/prop-desc.js new file mode 100644 index 0000000000..07b6510328 --- /dev/null +++ b/test/built-ins/DataView/prototype/buffer/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.buffer +es6id: 24.2.4.1 +description: > + "buffer" property of DataView.prototype +info: | + DataView.prototype.buffer 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, "buffer"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(DataView.prototype, "buffer"); +verifyConfigurable(DataView.prototype, "buffer"); diff --git a/test/built-ins/DataView/prototype/buffer/return-buffer.js b/test/built-ins/DataView/prototype/buffer/return-buffer.js new file mode 100644 index 0000000000..9d47bf6265 --- /dev/null +++ b/test/built-ins/DataView/prototype/buffer/return-buffer.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-get-dataview.prototype.buffer +es6id: 24.2.4.1 +description: > + Return buffer from [[ViewedArrayBuffer]] internal slot +info: | + 24.2.4.1 get DataView.prototype.buffer + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. Return buffer. +---*/ + +var buffer = new ArrayBuffer(1); +var dv = new DataView(buffer, 0); + +assert.sameValue(dv.buffer, buffer); diff --git a/test/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal.js b/test/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..e9e3bc97e2 --- /dev/null +++ b/test/built-ins/DataView/prototype/buffer/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.buffer +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.1 get DataView.prototype.buffer + + 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, "buffer" +).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/buffer/this-is-not-object.js b/test/built-ins/DataView/prototype/buffer/this-is-not-object.js new file mode 100644 index 0000000000..a5bd770c5e --- /dev/null +++ b/test/built-ins/DataView/prototype/buffer/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.buffer +es6id: 24.2.4.1 +description: Throws a TypeError exception when `this` is not Object +info: | + 24.2.4.1 get DataView.prototype.buffer + + 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, "buffer" +).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");