From 4da5c800a340b899b6e7bcacf51fb6e970f88c09 Mon Sep 17 00:00:00 2001 From: jugglinmike Date: Fri, 25 Jun 2021 13:21:11 -0400 Subject: [PATCH] Resizable ArrayBuffer: ArrayBuffer accessors (#3020) * Add "feature" for "Resizable ArrayBuffer" proposal * Resizable ArrayBuffer: ArrayBuffer accessors * fixup! Resizable ArrayBuffer: ArrayBuffer accessors --- .../maxByteLength/detached-buffer.js | 22 +++++++++ .../maxByteLength/invoked-as-accessor.js | 17 +++++++ .../maxByteLength/invoked-as-func.js | 23 +++++++++ .../prototype/maxByteLength/length.js | 32 +++++++++++++ .../prototype/maxByteLength/name.js | 24 ++++++++++ .../prototype/maxByteLength/prop-desc.js | 25 ++++++++++ .../return-maxbytelength-non-resizable.js | 25 ++++++++++ .../return-maxbytelength-resizable.js | 28 +++++++++++ .../this-has-no-arraybufferdata-internal.js | 39 +++++++++++++++ .../maxByteLength/this-is-not-object.js | 48 +++++++++++++++++++ .../this-is-sharedarraybuffer.js | 33 +++++++++++++ .../prototype/resizable/detached-buffer.js | 34 +++++++++++++ .../resizable/invoked-as-accessor.js | 17 +++++++ .../prototype/resizable/invoked-as-func.js | 23 +++++++++ .../ArrayBuffer/prototype/resizable/length.js | 32 +++++++++++++ .../ArrayBuffer/prototype/resizable/name.js | 24 ++++++++++ .../prototype/resizable/prop-desc.js | 25 ++++++++++ .../prototype/resizable/return-resizable.js | 29 +++++++++++ .../this-has-no-arraybufferdata-internal.js | 39 +++++++++++++++ .../prototype/resizable/this-is-not-object.js | 48 +++++++++++++++++++ .../resizable/this-is-sharedarraybuffer.js | 33 +++++++++++++ 21 files changed, 620 insertions(+) create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/detached-buffer.js create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/invoked-as-accessor.js create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/invoked-as-func.js create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/length.js create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/name.js create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/prop-desc.js create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-non-resizable.js create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-resizable.js create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/this-has-no-arraybufferdata-internal.js create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/this-is-not-object.js create mode 100644 test/built-ins/ArrayBuffer/prototype/maxByteLength/this-is-sharedarraybuffer.js create mode 100644 test/built-ins/ArrayBuffer/prototype/resizable/detached-buffer.js create mode 100644 test/built-ins/ArrayBuffer/prototype/resizable/invoked-as-accessor.js create mode 100644 test/built-ins/ArrayBuffer/prototype/resizable/invoked-as-func.js create mode 100644 test/built-ins/ArrayBuffer/prototype/resizable/length.js create mode 100644 test/built-ins/ArrayBuffer/prototype/resizable/name.js create mode 100644 test/built-ins/ArrayBuffer/prototype/resizable/prop-desc.js create mode 100644 test/built-ins/ArrayBuffer/prototype/resizable/return-resizable.js create mode 100644 test/built-ins/ArrayBuffer/prototype/resizable/this-has-no-arraybufferdata-internal.js create mode 100644 test/built-ins/ArrayBuffer/prototype/resizable/this-is-not-object.js create mode 100644 test/built-ins/ArrayBuffer/prototype/resizable/this-is-sharedarraybuffer.js diff --git a/test/built-ins/ArrayBuffer/prototype/maxByteLength/detached-buffer.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/detached-buffer.js new file mode 100644 index 0000000000..bdfdb916c2 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/detached-buffer.js @@ -0,0 +1,22 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: Returns 0 if the buffer is detached +info: | + get ArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, return +0𝔽. + [...] +includes: [detachArrayBuffer.js] +features: [resizable-arraybuffer] +---*/ + +var ab = new ArrayBuffer(1); + +$DETACHBUFFER(ab); + +assert.sameValue(ab.maxByteLength, 0); diff --git a/test/built-ins/ArrayBuffer/prototype/maxByteLength/invoked-as-accessor.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/invoked-as-accessor.js new file mode 100644 index 0000000000..d1d25488dd --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/invoked-as-accessor.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: Requires this value to have a [[ArrayBufferData]] internal slot +info: | + get ArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [resizable-arraybuffer] +---*/ + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.maxByteLength; +}); diff --git a/test/built-ins/ArrayBuffer/prototype/maxByteLength/invoked-as-func.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/invoked-as-func.js new file mode 100644 index 0000000000..3f16e41d19 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/invoked-as-func.js @@ -0,0 +1,23 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: Throws a TypeError exception when invoked as a function +info: | + get ArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, 'maxByteLength' +).get; + +assert.sameValue(typeof getter, 'function'); + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/built-ins/ArrayBuffer/prototype/maxByteLength/length.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/length.js new file mode 100644 index 0000000000..2b670d4469 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: > + get ArrayBuffer.prototype.maxByteLength.length is 0. +info: | + get ArrayBuffer.prototype.maxByteLength + + 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: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'maxByteLength'); + +verifyProperty(desc.get, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/maxByteLength/name.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/name.js new file mode 100644 index 0000000000..24d839ba60 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/name.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: > + get ArrayBuffer.prototype.maxByteLength + + 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: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'maxByteLength'); + +verifyProperty(desc.get, 'name', { + value: 'get maxByteLength', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/maxByteLength/prop-desc.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/prop-desc.js new file mode 100644 index 0000000000..af6481fca3 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/prop-desc.js @@ -0,0 +1,25 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: > + "maxByteLength" property of ArrayBuffer.prototype +info: | + ArrayBuffer.prototype.maxByteLength 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: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'maxByteLength'); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyProperty(ArrayBuffer.prototype, 'maxByteLength', { + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-non-resizable.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-non-resizable.js new file mode 100644 index 0000000000..1436b149dd --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-non-resizable.js @@ -0,0 +1,25 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: Return value from [[ArrayBufferByteLength]] internal slot +info: | + 24.1.4.1 get ArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, return +0𝔽. + 5. If IsResizableArrayBuffer(O) is true, then + [...] + 6. Else, + a. Let length be O.[[ArrayBufferByteLength]]. + 7. Return 𝔽(length). +features: [resizable-arraybuffer] +---*/ + +var ab1 = new ArrayBuffer(0); +assert.sameValue(ab1.maxByteLength, 0); + +var ab2 = new ArrayBuffer(42); +assert.sameValue(ab2.maxByteLength, 42); diff --git a/test/built-ins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-resizable.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-resizable.js new file mode 100644 index 0000000000..1aeda570db --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-resizable.js @@ -0,0 +1,28 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: Return value from [[ArrayBufferMaxByteLength]] internal slot +info: | + 24.1.4.1 get ArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, return +0𝔽. + 5. If IsResizableArrayBuffer(O) is true, then + a. Let length be O.[[ArrayBufferMaxByteLength]]. + 6. Else, + [...] + 7. Return 𝔽(length). +features: [resizable-arraybuffer] +---*/ + +var ab1 = new ArrayBuffer(0, { maxByteLength: 0 }); +assert.sameValue(ab1.maxByteLength, 0); + +var ab2 = new ArrayBuffer(0, { maxByteLength: 23 }); +assert.sameValue(ab2.maxByteLength, 23); + +var ab3 = new ArrayBuffer(42, { maxByteLength: 42 }); +assert.sameValue(ab3.maxByteLength, 42); diff --git a/test/built-ins/ArrayBuffer/prototype/maxByteLength/this-has-no-arraybufferdata-internal.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/this-has-no-arraybufferdata-internal.js new file mode 100644 index 0000000000..cdce703c65 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/this-has-no-arraybufferdata-internal.js @@ -0,0 +1,39 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: > + Throws a TypeError exception when `this` does not have a [[ArrayBufferData]] + internal slot +info: | + get ArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [DataView, Int8Array, resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, "maxByteLength" +).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/maxByteLength/this-is-not-object.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/this-is-not-object.js new file mode 100644 index 0000000000..7ae2030239 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/this-is-not-object.js @@ -0,0 +1,48 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: Throws a TypeError exception when `this` is not Object +info: | + get ArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [Symbol, resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, "maxByteLength" +).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/maxByteLength/this-is-sharedarraybuffer.js b/test/built-ins/ArrayBuffer/prototype/maxByteLength/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000..689dbf9260 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/maxByteLength/this-is-sharedarraybuffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.maxbytelength +description: Throws a TypeError exception when `this` is a SharedArrayBuffer +info: | + get ArrayBuffer.prototype.maxByteLength + + 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] +---*/ + +var maxByteLength = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, "maxByteLength" +); + +var getter = maxByteLength.get; +var sab = new SharedArrayBuffer(4); + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(sab); +}, "`this` cannot be a SharedArrayBuffer"); + +Object.defineProperties(sab, { maxByteLength: maxByteLength }); + +assert.throws(TypeError, function() { + sab.maxByteLength; +}, "`this` cannot be a SharedArrayBuffer"); diff --git a/test/built-ins/ArrayBuffer/prototype/resizable/detached-buffer.js b/test/built-ins/ArrayBuffer/prototype/resizable/detached-buffer.js new file mode 100644 index 0000000000..85b618a3d2 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/resizable/detached-buffer.js @@ -0,0 +1,34 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.resizable +description: Unaffected by buffer's attachedness +info: | + get ArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. Return IsResizableArrayBuffer(O). + + IsResizableArrayBuffer ( arrayBuffer ) + + 1. Assert: Type(arrayBuffer) is Object and arrayBuffer has an + [[ArrayBufferData]] internal slot. + 2. If buffer has an [[ArrayBufferMaxByteLength]] internal slot, return true. + 3. Return false. +includes: [detachArrayBuffer.js] +features: [resizable-arraybuffer] +---*/ + +var ab1 = new ArrayBuffer(1); + +$DETACHBUFFER(ab1); + +assert.sameValue(ab1.resizable, false); + +var ab2 = new ArrayBuffer(1, {maxByteLength: 1}); + +$DETACHBUFFER(ab2); + +assert.sameValue(ab2.resizable, true); diff --git a/test/built-ins/ArrayBuffer/prototype/resizable/invoked-as-accessor.js b/test/built-ins/ArrayBuffer/prototype/resizable/invoked-as-accessor.js new file mode 100644 index 0000000000..058f52cb5e --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/resizable/invoked-as-accessor.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.resizable +description: Requires this value to have a [[ArrayBufferData]] internal slot +info: | + get ArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [resizable-arraybuffer] +---*/ + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.resizable; +}); diff --git a/test/built-ins/ArrayBuffer/prototype/resizable/invoked-as-func.js b/test/built-ins/ArrayBuffer/prototype/resizable/invoked-as-func.js new file mode 100644 index 0000000000..7107cb4de2 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/resizable/invoked-as-func.js @@ -0,0 +1,23 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.resizable +description: Throws a TypeError exception when invoked as a function +info: | + get ArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, 'resizable' +).get; + +assert.sameValue(typeof getter, 'function'); + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/built-ins/ArrayBuffer/prototype/resizable/length.js b/test/built-ins/ArrayBuffer/prototype/resizable/length.js new file mode 100644 index 0000000000..1792bc3cd5 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/resizable/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.resizable +description: > + get ArrayBuffer.prototype.resizable.length is 0. +info: | + get ArrayBuffer.prototype.resizeable + + 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: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'resizable'); + +verifyProperty(desc.get, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/resizable/name.js b/test/built-ins/ArrayBuffer/prototype/resizable/name.js new file mode 100644 index 0000000000..e46a22768c --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/resizable/name.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.resizable +description: > + get ArrayBuffer.prototype.resizable + + 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: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'resizable'); + +verifyProperty(desc.get, 'name', { + value: 'get resizable', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/resizable/prop-desc.js b/test/built-ins/ArrayBuffer/prototype/resizable/prop-desc.js new file mode 100644 index 0000000000..90d77905c3 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/resizable/prop-desc.js @@ -0,0 +1,25 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.resizable +description: > + "resizable" property of ArrayBuffer.prototype +info: | + ArrayBuffer.prototype.resizable 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: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'resizable'); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyProperty(ArrayBuffer.prototype, 'resizable', { + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/resizable/return-resizable.js b/test/built-ins/ArrayBuffer/prototype/resizable/return-resizable.js new file mode 100644 index 0000000000..3abc5b2a79 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/resizable/return-resizable.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.resizable +description: Return value according to [[ArrayBufferMaxByteLength]] internal slot +info: | + get ArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. Return IsResizableArrayBuffer(O). + + IsResizableArrayBuffer ( arrayBuffer ) + + 1. Assert: Type(arrayBuffer) is Object and arrayBuffer has an + [[ArrayBufferData]] internal slot. + 2. If buffer has an [[ArrayBufferMaxByteLength]] internal slot, return true. + 3. Return false. +features: [resizable-arraybuffer] +---*/ + +var ab1 = new ArrayBuffer(1); + +assert.sameValue(ab1.resizable, false); + +var ab2 = new ArrayBuffer(1, {maxByteLength: 1}); + +assert.sameValue(ab2.resizable, true); diff --git a/test/built-ins/ArrayBuffer/prototype/resizable/this-has-no-arraybufferdata-internal.js b/test/built-ins/ArrayBuffer/prototype/resizable/this-has-no-arraybufferdata-internal.js new file mode 100644 index 0000000000..c388935fbd --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/resizable/this-has-no-arraybufferdata-internal.js @@ -0,0 +1,39 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.resizable +description: > + Throws a TypeError exception when `this` does not have a [[ArrayBufferData]] + internal slot +info: | + get ArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [DataView, Int8Array, resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, "resizable" +).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/resizable/this-is-not-object.js b/test/built-ins/ArrayBuffer/prototype/resizable/this-is-not-object.js new file mode 100644 index 0000000000..2d87dde7ea --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/resizable/this-is-not-object.js @@ -0,0 +1,48 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.resizable +description: Throws a TypeError exception when `this` is not Object +info: | + get ArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [Symbol, resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, "resizable" +).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/resizable/this-is-sharedarraybuffer.js b/test/built-ins/ArrayBuffer/prototype/resizable/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000..449cdc129f --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/resizable/this-is-sharedarraybuffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-arraybuffer.prototype.resizable +description: Throws a TypeError exception when `this` is a SharedArrayBuffer +info: | + get ArrayBuffer.prototype.resizable + + 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] +---*/ + +var resizable = Object.getOwnPropertyDescriptor( + ArrayBuffer.prototype, "resizable" +); + +var getter = resizable.get; +var sab = new SharedArrayBuffer(4); + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(sab); +}, "`this` cannot be a SharedArrayBuffer"); + +Object.defineProperties(sab, { resizable: resizable }); + +assert.throws(TypeError, function() { + sab.resizable; +}, "`this` cannot be a SharedArrayBuffer");