From 408ecd0987a1b065637164ccd6c1305f6864fcdf Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 18 Jan 2023 13:11:36 -0800 Subject: [PATCH] ArrayBuffer.prototype.detached tests See https://tc39.es/proposal-arraybuffer-transfer/ --- .../detached/detached-buffer-resizable.js | 36 ++++++++++++++ .../prototype/detached/detached-buffer.js | 24 ++++++++++ .../prototype/detached/invoked-as-accessor.js | 19 ++++++++ .../prototype/detached/invoked-as-func.js | 24 ++++++++++ .../ArrayBuffer/prototype/detached/length.js | 33 +++++++++++++ .../ArrayBuffer/prototype/detached/name.js | 24 ++++++++++ .../prototype/detached/prop-desc.js | 25 ++++++++++ .../this-has-no-arraybufferdata-internal.js | 39 +++++++++++++++ .../prototype/detached/this-is-not-object.js | 48 +++++++++++++++++++ .../this-is-sharedarraybuffer-resizable.js | 27 +++++++++++ .../detached/this-is-sharedarraybuffer.js | 27 +++++++++++ 11 files changed, 326 insertions(+) create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/detached-buffer-resizable.js create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/detached-buffer.js create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/invoked-as-accessor.js create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/invoked-as-func.js create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/length.js create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/name.js create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/prop-desc.js create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/this-has-no-arraybufferdata-internal.js create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/this-is-not-object.js create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer-resizable.js create mode 100644 test/built-ins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer.js diff --git a/test/built-ins/ArrayBuffer/prototype/detached/detached-buffer-resizable.js b/test/built-ins/ArrayBuffer/prototype/detached/detached-buffer-resizable.js new file mode 100644 index 0000000000..1d311d8fb4 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/detached-buffer-resizable.js @@ -0,0 +1,36 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: Return a boolean indicating if the ArrayBuffer is detached +info: | + get ArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. Return IsDetachedBuffer(O). +includes: [detachArrayBuffer.js] +features: [ArrayBuffer, arraybuffer-transfer, resizable-arraybuffer] +---*/ + +var ab1 = new ArrayBuffer(0, { maxByteLength: 0 }); +assert.sameValue(ab1.detached, false, 'Resizable ArrayBuffer with maxByteLength of 0 is not detached'); + +$DETACHBUFFER(ab1); + +assert.sameValue(ab1.detached, true, 'Resizable ArrayBuffer with maxByteLength of 0 is now detached'); + +var ab2 = new ArrayBuffer(0, { maxByteLength: 23 }); +assert.sameValue(ab2.detached, false, 'Resizable ArrayBuffer with maxByteLength of 23 is not detached'); + +$DETACHBUFFER(ab2); + +assert.sameValue(ab2.detached, true, 'Resizable ArrayBuffer with maxByteLength of 23 is now detached'); + +var ab3 = new ArrayBuffer(42, { maxByteLength: 42 }); +assert.sameValue(ab3.detached, false, 'Resizable ArrayBuffer with maxByteLength of 42 is not detached'); + +$DETACHBUFFER(ab3); + +assert.sameValue(ab3.detached, true, 'Resizable ArrayBuffer with maxByteLength of 42 is now detached'); diff --git a/test/built-ins/ArrayBuffer/prototype/detached/detached-buffer.js b/test/built-ins/ArrayBuffer/prototype/detached/detached-buffer.js new file mode 100644 index 0000000000..415f50610d --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/detached-buffer.js @@ -0,0 +1,24 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: Returns true if the buffer is detached, else false +info: | + get ArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. Return IsDetachedBuffer(O). + +includes: [detachArrayBuffer.js] +features: [ArrayBuffer, arraybuffer-transfer] +---*/ + +var ab = new ArrayBuffer(1); + +assert.sameValue(ab.detached, false); + +$DETACHBUFFER(ab); + +assert.sameValue(ab.detached, true); diff --git a/test/built-ins/ArrayBuffer/prototype/detached/invoked-as-accessor.js b/test/built-ins/ArrayBuffer/prototype/detached/invoked-as-accessor.js new file mode 100644 index 0000000000..d1bd0c87b0 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/invoked-as-accessor.js @@ -0,0 +1,19 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: Returns true if the buffer is detached, else false +info: | + get ArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. Return IsDetachedBuffer(O). + +features: [ArrayBuffer, arraybuffer-transfer] +---*/ + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.detached; +}); diff --git a/test/built-ins/ArrayBuffer/prototype/detached/invoked-as-func.js b/test/built-ins/ArrayBuffer/prototype/detached/invoked-as-func.js new file mode 100644 index 0000000000..c83dd2637e --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/invoked-as-func.js @@ -0,0 +1,24 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: Returns true if the buffer is detached, else false +info: | + get ArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] + +features: [ArrayBuffer, arraybuffer-transfer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, 'detached' +).get; + +assert.sameValue(typeof getter, 'function'); + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/built-ins/ArrayBuffer/prototype/detached/length.js b/test/built-ins/ArrayBuffer/prototype/detached/length.js new file mode 100644 index 0000000000..8b9a1eb6f1 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: > + get ArrayBuffer.prototype.detached.length is 0. +info: | + get ArrayBuffer.prototype.detached + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. + +includes: [propertyHelper.js] +features: [ArrayBuffer, arraybuffer-transfer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'detached'); + +verifyProperty(desc.get, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/detached/name.js b/test/built-ins/ArrayBuffer/prototype/detached/name.js new file mode 100644 index 0000000000..5149a8cd62 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/name.js @@ -0,0 +1,24 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: > + get ArrayBuffer.prototype.detached + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +features: [ArrayBuffer, arraybuffer-transfer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'detached'); + +verifyProperty(desc.get, 'name', { + value: 'get detached', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/detached/prop-desc.js b/test/built-ins/ArrayBuffer/prototype/detached/prop-desc.js new file mode 100644 index 0000000000..441f558743 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/prop-desc.js @@ -0,0 +1,25 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: > + "detached" property of ArrayBuffer.prototype +info: | + ArrayBuffer.prototype.detached 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] +features: [ArrayBuffer, arraybuffer-transfer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'detached'); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyProperty(ArrayBuffer.prototype, 'detached', { + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/detached/this-has-no-arraybufferdata-internal.js b/test/built-ins/ArrayBuffer/prototype/detached/this-has-no-arraybufferdata-internal.js new file mode 100644 index 0000000000..75d93307a6 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/this-has-no-arraybufferdata-internal.js @@ -0,0 +1,39 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: > + Throws a TypeError exception when `this` does not have a [[ArrayBufferData]] + internal slot +info: | + get ArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [DataView, Int8Array, ArrayBuffer, arraybuffer-transfer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, "detached" +).get; + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ta = new Int8Array(8); +assert.throws(TypeError, function() { + getter.call(ta); +}); + +var dv = new DataView(new ArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/built-ins/ArrayBuffer/prototype/detached/this-is-not-object.js b/test/built-ins/ArrayBuffer/prototype/detached/this-is-not-object.js new file mode 100644 index 0000000000..9d288e0fd6 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/this-is-not-object.js @@ -0,0 +1,48 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: Throws a TypeError exception when `this` is not Object +info: | + get ArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [Symbol, ArrayBuffer, arraybuffer-transfer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, "detached" +).get; + +assert.sameValue(typeof getter, "function"); + +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"); diff --git a/test/built-ins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer-resizable.js b/test/built-ins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer-resizable.js new file mode 100644 index 0000000000..a332fb36fc --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer-resizable.js @@ -0,0 +1,27 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: Throws a TypeError exception when `this` is a resizable SharedArrayBuffer +info: | + get ArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + [...] +features: [SharedArrayBuffer, resizable-arraybuffer, ArrayBuffer, arraybuffer-transfer] +---*/ + +var detached = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, "detached" +); + +var getter = detached.get; +var sab = new SharedArrayBuffer(4); + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(sab); +}, "`this` cannot be a SharedArrayBuffer"); diff --git a/test/built-ins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer.js b/test/built-ins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000..e0bc5602db --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer.js @@ -0,0 +1,27 @@ +// Copyright (C) 2023 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.detached +description: Throws a TypeError exception when `this` is a SharedArrayBuffer +info: | + get ArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + [...] +features: [SharedArrayBuffer, ArrayBuffer, arraybuffer-transfer] +---*/ + +var detached = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, "detached" +); + +var getter = detached.get; +var sab = new SharedArrayBuffer(4); + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(sab); +}, "`this` cannot be a SharedArrayBuffer");