diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/descriptor.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/descriptor.js new file mode 100644 index 0000000000..8c7f8280ed --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/descriptor.js @@ -0,0 +1,23 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: > + ArrayBuffer.prototype.transferToFixedLength has default data property + attributes. +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Every other data property described in clauses 18 through 26 and in + Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +verifyProperty(ArrayBuffer.prototype, 'transferToFixedLength', { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/extensible.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/extensible.js new file mode 100644 index 0000000000..4930f26d0f --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/extensible.js @@ -0,0 +1,15 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: ArrayBuffer.prototype.transferToFixedLength is extensible. +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Unless specified otherwise, the [[Extensible]] internal slot + of a built-in object initially has the value true. +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +assert(Object.isExtensible(ArrayBuffer.prototype.transferToFixedLength)); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger.js new file mode 100644 index 0000000000..ceee25fe11 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger.js @@ -0,0 +1,34 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: Transfering from a fixed-size ArrayBuffer into a larger ArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new ArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(5); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 5, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 5, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); +assert.sameValue(destArray[4], 0, 'destArray[4]'); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same.js new file mode 100644 index 0000000000..f1dae842b3 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same.js @@ -0,0 +1,35 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: | + Transfering from a fixed-size ArrayBuffer into an ArrayBuffer with the same + byte length +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new ArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 4, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 4, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller.js new file mode 100644 index 0000000000..b31e95f059 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller.js @@ -0,0 +1,32 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: Transfering from a fixed-size ArrayBuffer into a smaller ArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new ArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(3); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 3, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 3, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero.js new file mode 100644 index 0000000000..3840da776b --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero.js @@ -0,0 +1,26 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: Transfering from a fixed-size ArrayBuffer into a zero-length ArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new ArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(0); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 0, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 0, 'dest.maxByteLength'); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-larger.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-larger.js new file mode 100644 index 0000000000..4d485c5546 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-larger.js @@ -0,0 +1,34 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: Transfering from a resizable ArrayBuffer into a larger ArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new ArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(5); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 5, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 5, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); +assert.sameValue(destArray[4], 0, 'destArray[4]'); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-same.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-same.js new file mode 100644 index 0000000000..a484d6c64b --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-same.js @@ -0,0 +1,35 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: | + Transfering from a resizable ArrayBuffer into an ArrayBuffer with the same + byte length +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new ArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 4, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 4, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-smaller.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-smaller.js new file mode 100644 index 0000000000..2e03667f20 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-smaller.js @@ -0,0 +1,32 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: Transfering from a resizable ArrayBuffer into a smaller ArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new ArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(3); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 3, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 3, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-zero.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-zero.js new file mode 100644 index 0000000000..94a19ad2d7 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-zero.js @@ -0,0 +1,26 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: Transfering from a resizable ArrayBuffer into a zero-length ArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new ArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(0); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 0, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 0, 'dest.maxByteLength'); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/length.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/length.js new file mode 100644 index 0000000000..eeccce37fb --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: > + ArrayBuffer.prototype.transferToFixedLength.length is 0. +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 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, arraybuffer-transfer] +---*/ + +verifyProperty(ArrayBuffer.prototype.transferToFixedLength, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/name.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/name.js new file mode 100644 index 0000000000..4603eff9e1 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/name.js @@ -0,0 +1,27 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: > + ArrayBuffer.prototype.transferToFixedLength.name is "transfer". +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +features: [resizable-arraybuffer, arraybuffer-transfer] +includes: [propertyHelper.js] +---*/ + +verifyProperty(ArrayBuffer.prototype.transferToFixedLength, 'name', { + value: 'transferToFixedLength', + enumerable: false, + wrtiable: false, + configurable: true +}); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/new-length-excessive.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/new-length-excessive.js new file mode 100644 index 0000000000..a221bb7a74 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/new-length-excessive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: > + Throws a RangeError the newLength value is too large to create a new + ArrayBuffer. +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 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, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[ArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »). + [...] +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var ab = new ArrayBuffer(0); + +assert.throws(RangeError, function() { + // Math.pow(2, 53) = 9007199254740992 + ab.transferToFixedLength(9007199254740992); +}); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/new-length-non-number.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/new-length-non-number.js new file mode 100644 index 0000000000..cdd3cf1616 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/new-length-non-number.js @@ -0,0 +1,39 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: Throws a TypeError if provided length cannot be coerced to a number +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 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, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[ArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + [...] +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var log = []; +var newLength = { + toString: function() { + log.push('toString'); + return {}; + }, + valueOf: function() { + log.push('valueOf'); + return {}; + } +}; +var ab = new ArrayBuffer(0); + +assert.throws(TypeError, function() { + ab.transferToFixedLength(newLength); +}); + +assert.sameValue(log.length, 2); +assert.sameValue(log[0], 'valueOf'); +assert.sameValue(log[1], 'toString'); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/nonconstructor.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/nonconstructor.js new file mode 100644 index 0000000000..8314c54ba9 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/nonconstructor.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-arraybuffer.prototype.transfertofixedlength +description: > + ArrayBuffer.prototype.transferToFixedLength is not a constructor function. +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified + in the description of a particular function. +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +assert.sameValue( + Object.prototype.hasOwnProperty.call(ArrayBuffer.prototype.transferToFixedLength, 'prototype'), + false +); + +var arrayBuffer = new ArrayBuffer(8); +assert.throws(TypeError, function() { + new arrayBuffer.transfer(); +}); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-detached.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-detached.js new file mode 100644 index 0000000000..0c93a2e785 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-detached.js @@ -0,0 +1,27 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: > + Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot. +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 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, throw a TypeError exception. + [...] +includes: [detachArrayBuffer.js] +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +assert.sameValue(typeof ArrayBuffer.prototype.transferToFixedLength, 'function'); + +var ab = new ArrayBuffer(1); + +$DETACHBUFFER(ab); + +assert.throws(TypeError, function() { + ab.transferToFixedLength(); +}); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-arraybuffer-object.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-arraybuffer-object.js new file mode 100644 index 0000000000..aefd761e97 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-arraybuffer-object.js @@ -0,0 +1,28 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: > + Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot. +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +assert.sameValue(typeof ArrayBuffer.prototype.transferToFixedLength, 'function'); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength(); +}, '`this` value is the ArrayBuffer prototype'); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength.call({}); +}, '`this` value is an object'); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength.call([]); +}, '`this` value is an array'); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-object.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-object.js new file mode 100644 index 0000000000..37b73fecd4 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-object.js @@ -0,0 +1,44 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: Throws a TypeError if `this` valueis not an object. +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). + [...] +features: [resizable-arraybuffer, Symbol, BigInt] +---*/ + +assert.sameValue(typeof ArrayBuffer.prototype.transferToFixedLength, "function"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength.call(undefined); +}, "`this` value is undefined"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength.call(null); +}, "`this` value is null"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength.call(true); +}, "`this` value is Boolean"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength.call(""); +}, "`this` value is String"); + +var symbol = Symbol(); +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength.call(symbol); +}, "`this` value is Symbol"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength.call(1); +}, "`this` value is Number"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength.call(1n); +}, "`this` value is bigint"); diff --git a/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-sharedarraybuffer.js b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000..e822e82fb3 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-sharedarraybuffer.js @@ -0,0 +1,20 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-arraybuffer.prototype.transfertofixedlength +description: Throws a TypeError if `this` value is a SharedArrayBuffer +info: | + ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 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 sab = new SharedArrayBuffer(0); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.transferToFixedLength.call(sab); +}, '`this` value cannot be a SharedArrayBuffer');