mirror of https://github.com/tc39/test262.git
Add tests for ArrayBuffer.prototype.transferToFixedLength
See https://tc39.es/proposal-arraybuffer-transfer/
This commit is contained in:
parent
9964fa962a
commit
6fecc44859
|
@ -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
|
||||
});
|
|
@ -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));
|
34
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger.js
vendored
Normal file
34
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger.js
vendored
Normal file
|
@ -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]');
|
35
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same.js
vendored
Normal file
35
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same.js
vendored
Normal file
|
@ -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]');
|
32
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller.js
vendored
Normal file
32
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller.js
vendored
Normal file
|
@ -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]');
|
26
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero.js
vendored
Normal file
26
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero.js
vendored
Normal file
|
@ -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');
|
34
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-larger.js
vendored
Normal file
34
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-larger.js
vendored
Normal file
|
@ -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]');
|
35
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-same.js
vendored
Normal file
35
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-same.js
vendored
Normal file
|
@ -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]');
|
32
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-smaller.js
vendored
Normal file
32
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-smaller.js
vendored
Normal file
|
@ -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]');
|
26
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-zero.js
vendored
Normal file
26
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-zero.js
vendored
Normal file
|
@ -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');
|
|
@ -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
|
||||
});
|
|
@ -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
|
||||
});
|
28
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/new-length-excessive.js
vendored
Normal file
28
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/new-length-excessive.js
vendored
Normal file
|
@ -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);
|
||||
});
|
39
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/new-length-non-number.js
vendored
Normal file
39
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/new-length-non-number.js
vendored
Normal file
|
@ -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');
|
25
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/nonconstructor.js
vendored
Normal file
25
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/nonconstructor.js
vendored
Normal file
|
@ -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();
|
||||
});
|
27
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-detached.js
vendored
Normal file
27
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-detached.js
vendored
Normal file
|
@ -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();
|
||||
});
|
28
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-arraybuffer-object.js
vendored
Normal file
28
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-arraybuffer-object.js
vendored
Normal file
|
@ -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');
|
44
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-object.js
vendored
Normal file
44
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-object.js
vendored
Normal file
|
@ -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");
|
20
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-sharedarraybuffer.js
vendored
Normal file
20
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-sharedarraybuffer.js
vendored
Normal file
|
@ -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');
|
Loading…
Reference in New Issue