Resizable ArrayBuffer: ArrayBuffer methods (#3019)

* Add "feature" for "Resizable ArrayBuffer" proposal

* Resizable ArrayBuffer: ArrayBuffer methods

* fixup! Resizable ArrayBuffer: ArrayBuffer methods
This commit is contained in:
jugglinmike 2021-06-25 13:19:33 -04:00 committed by GitHub
parent b3c2d3a88e
commit 93ad86b859
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 1630 additions and 0 deletions

View File

@ -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-arraybuffer.prototype.resize
description: >
ArrayBuffer.prototype.resize has default data property attributes.
info: |
ArrayBuffer.prototype.resize ( 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]
---*/
verifyProperty(ArrayBuffer.prototype, 'resize', {
enumerable: false,
writable: true,
configurable: true
});

View File

@ -0,0 +1,15 @@
// 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.resize
description: ArrayBuffer.prototype.resize is extensible.
info: |
ArrayBuffer.prototype.resize ( 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]
---*/
assert(Object.isExtensible(ArrayBuffer.prototype.resize));

View File

@ -0,0 +1,30 @@
// 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.resize
description: >
ArrayBuffer.prototype.resize.length is 1.
info: |
ArrayBuffer.prototype.resize ( 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]
---*/
verifyProperty(ArrayBuffer.prototype.resize, 'length', {
value: 1,
enumerable: false,
writable: false,
configurable: true
});

View File

@ -0,0 +1,27 @@
// 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.resize
description: >
ArrayBuffer.prototype.resize.name is "resize".
info: |
ArrayBuffer.prototype.resize ( 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]
includes: [propertyHelper.js]
---*/
verifyProperty(ArrayBuffer.prototype.resize, 'name', {
value: 'resize',
enumerable: false,
wrtiable: false,
configurable: true
});

View 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.resize
description: >
Throws a RangeError the newLength value is larger than the max byte length
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
throw a RangeError exception.
[...]
features: [resizable-arraybuffer]
---*/
var ab = new ArrayBuffer(4, {maxByteLength: 4});
assert.throws(RangeError, function() {
ab.resize(5);
});

View 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.resize
description: >
Throws a RangeError the newLength value is less than zero
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
throw a RangeError exception.
[...]
features: [resizable-arraybuffer]
---*/
var ab = new ArrayBuffer(4, {maxByteLength: 4});
assert.throws(RangeError, function() {
ab.resize(-1);
});

View File

@ -0,0 +1,37 @@
// 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.resize
description: Throws a TypeError if provided length cannot be coerced to a number
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
[...]
features: [resizable-arraybuffer]
---*/
var log = [];
var newLength = {
toString: function() {
log.push('toString');
return {};
},
valueOf: function() {
log.push('valueOf');
return {};
}
};
var ab = new ArrayBuffer(0, {maxByteLength: 4});
assert.throws(TypeError, function() {
ab.resize(newLength);
});
assert.sameValue(log.length, 2);
assert.sameValue(log[0], 'valueOf');
assert.sameValue(log[1], 'toString');

View File

@ -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-arraybuffer.prototype.resize
description: >
ArrayBuffer.prototype.resize is not a constructor function.
info: |
ArrayBuffer.prototype.resize ( 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.
---*/
assert.sameValue(
Object.prototype.hasOwnProperty.call(ArrayBuffer.prototype.resize, 'prototype'),
false
);
var arrayBuffer = new ArrayBuffer(8);
assert.throws(TypeError, function() {
new arrayBuffer.resize();
});

View File

@ -0,0 +1,77 @@
// 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.resize
description: Behavior when attempting to grow a resizable array buffer
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
throw a RangeError exception.
7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
[...]
HostResizeArrayBuffer ( buffer, newByteLength )
The implementation of HostResizeArrayBuffer must conform to the following
requirements:
- The abstract operation does not detach buffer.
- The abstract operation may complete normally or abruptly.
- If the abstract operation completes normally with handled,
buffer.[[ArrayBufferByteLength]] is newByteLength.
- The return value is either handled or unhandled.
features: [resizable-arraybuffer]
---*/
var ab = new ArrayBuffer(4, {maxByteLength: 5});
var caught = false;
var result;
// If the host chooses to throw as allowed by the specification, the observed
// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
// has not been implemented. The following assertion prevents this test from
// passing in runtimes which have not implemented the method.
assert.sameValue(typeof ab.resize, 'function');
try {
result = ab.resize(5);
} catch (_) {
caught = true;
}
try {
ab.slice();
} catch (_) {
throw new Test262Error('The ArrayBuffer under test was detached');
}
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation and conforms to the
// invarient regarding [[ArrayBufferByteLength]]
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method updates [[ArrayBufferByteLength]]
//
// The final two conditions are indistinguishable.
assert(caught || ab.byteLength === 5, 'byteLength');
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation, and the `resize`
// method returns early
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method executes its final steps
//
// All three conditions have the same effect on the value of `result`.
assert.sameValue(result, undefined, 'normal completion value');
// The contents of the ArrayBuffer are not guaranteed by the host-defined
// abstract operation, so they are not asserted in this test.

View File

@ -0,0 +1,78 @@
// 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.resize
description: >
Behavior when attempting to reset the size of a resizable array buffer to zero explicitly
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
throw a RangeError exception.
7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
[...]
HostResizeArrayBuffer ( buffer, newByteLength )
The implementation of HostResizeArrayBuffer must conform to the following
requirements:
- The abstract operation does not detach buffer.
- The abstract operation may complete normally or abruptly.
- If the abstract operation completes normally with handled,
buffer.[[ArrayBufferByteLength]] is newByteLength.
- The return value is either handled or unhandled.
features: [resizable-arraybuffer]
---*/
var ab = new ArrayBuffer(0, {maxByteLength: 0});
var caught = false;
var result;
// If the host chooses to throw as allowed by the specification, the observed
// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
// has not been implemented. The following assertion prevents this test from
// passing in runtimes which have not implemented the method.
assert.sameValue(typeof ab.resize, 'function');
try {
result = ab.resize(0);
} catch (_) {
caught = true;
}
try {
ab.slice();
} catch (_) {
throw new Test262Error('The ArrayBuffer under test was detached');
}
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation and conforms to the
// invarient regarding [[ArrayBufferByteLength]]
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method updates [[ArrayBufferByteLength]]
//
// The final two conditions are indistinguishable.
assert(caught || ab.byteLength === 0, 'byteLength');
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation, and the `resize`
// method returns early
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method executes its final steps
//
// All three conditions have the same effect on the value of `result`.
assert.sameValue(result, undefined, 'normal completion value');
// The contents of the ArrayBuffer are not guaranteed by the host-defined
// abstract operation, so they are not asserted in this test.

View File

@ -0,0 +1,78 @@
// 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.resize
description: >
Behavior when attempting to reset the size of a resizable array buffer to zero explicitly
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
throw a RangeError exception.
7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
[...]
HostResizeArrayBuffer ( buffer, newByteLength )
The implementation of HostResizeArrayBuffer must conform to the following
requirements:
- The abstract operation does not detach buffer.
- The abstract operation may complete normally or abruptly.
- If the abstract operation completes normally with handled,
buffer.[[ArrayBufferByteLength]] is newByteLength.
- The return value is either handled or unhandled.
features: [resizable-arraybuffer]
---*/
var ab = new ArrayBuffer(0, {maxByteLength: 0});
var caught = false;
var result;
// If the host chooses to throw as allowed by the specification, the observed
// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
// has not been implemented. The following assertion prevents this test from
// passing in runtimes which have not implemented the method.
assert.sameValue(typeof ab.resize, 'function');
try {
result = ab.resize();
} catch (_) {
caught = true;
}
try {
ab.slice();
} catch (_) {
throw new Test262Error('The ArrayBuffer under test was detached');
}
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation and conforms to the
// invarient regarding [[ArrayBufferByteLength]]
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method updates [[ArrayBufferByteLength]]
//
// The final two conditions are indistinguishable.
assert(caught || ab.byteLength === 0, 'byteLength');
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation, and the `resize`
// method returns early
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method executes its final steps
//
// All three conditions have the same effect on the value of `result`.
assert.sameValue(result, undefined, 'normal completion value');
// The contents of the ArrayBuffer are not guaranteed by the host-defined
// abstract operation, so they are not asserted in this test.

View File

@ -0,0 +1,78 @@
// 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.resize
description: >
Behavior when attempting to reset the size of a resizable array buffer
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
throw a RangeError exception.
7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
[...]
HostResizeArrayBuffer ( buffer, newByteLength )
The implementation of HostResizeArrayBuffer must conform to the following
requirements:
- The abstract operation does not detach buffer.
- The abstract operation may complete normally or abruptly.
- If the abstract operation completes normally with handled,
buffer.[[ArrayBufferByteLength]] is newByteLength.
- The return value is either handled or unhandled.
features: [resizable-arraybuffer]
---*/
var ab = new ArrayBuffer(4, {maxByteLength: 4});
var caught = false;
var result;
// If the host chooses to throw as allowed by the specification, the observed
// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
// has not been implemented. The following assertion prevents this test from
// passing in runtimes which have not implemented the method.
assert.sameValue(typeof ab.resize, 'function');
try {
result = ab.resize(4);
} catch (_) {
caught = true;
}
try {
ab.slice();
} catch (_) {
throw new Test262Error('The ArrayBuffer under test was detached');
}
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation and conforms to the
// invarient regarding [[ArrayBufferByteLength]]
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method updates [[ArrayBufferByteLength]]
//
// The final two conditions are indistinguishable.
assert(caught || ab.byteLength === 4, 'byteLength');
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation, and the `resize`
// method returns early
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method executes its final steps
//
// All three conditions have the same effect on the value of `result`.
assert.sameValue(result, undefined, 'normal completion value');
// The contents of the ArrayBuffer are not guaranteed by the host-defined
// abstract operation, so they are not asserted in this test.

View File

@ -0,0 +1,77 @@
// 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.resize
description: Behavior when attempting to shrink a resizable array buffer to zero explicitly
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
throw a RangeError exception.
7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
[...]
HostResizeArrayBuffer ( buffer, newByteLength )
The implementation of HostResizeArrayBuffer must conform to the following
requirements:
- The abstract operation does not detach buffer.
- The abstract operation may complete normally or abruptly.
- If the abstract operation completes normally with handled,
buffer.[[ArrayBufferByteLength]] is newByteLength.
- The return value is either handled or unhandled.
features: [resizable-arraybuffer]
---*/
var ab = new ArrayBuffer(4, {maxByteLength: 4});
var caught = false;
var result;
// If the host chooses to throw as allowed by the specification, the observed
// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
// has not been implemented. The following assertion prevents this test from
// passing in runtimes which have not implemented the method.
assert.sameValue(typeof ab.resize, 'function');
try {
result = ab.resize(0);
} catch (_) {
caught = true;
}
try {
ab.slice();
} catch (_) {
throw new Test262Error('The ArrayBuffer under test was detached');
}
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation and conforms to the
// invarient regarding [[ArrayBufferByteLength]]
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method updates [[ArrayBufferByteLength]]
//
// The final two conditions are indistinguishable.
assert(caught || ab.byteLength === 0, 'byteLength');
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation, and the `resize`
// method returns early
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method executes its final steps
//
// All three conditions have the same effect on the value of `result`.
assert.sameValue(result, undefined, 'normal completion value');
// The contents of the ArrayBuffer are not guaranteed by the host-defined
// abstract operation, so they are not asserted in this test.

View File

@ -0,0 +1,77 @@
// 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.resize
description: Behavior when attempting to shrink a resizable array buffer to zero implicitly
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
throw a RangeError exception.
7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
[...]
HostResizeArrayBuffer ( buffer, newByteLength )
The implementation of HostResizeArrayBuffer must conform to the following
requirements:
- The abstract operation does not detach buffer.
- The abstract operation may complete normally or abruptly.
- If the abstract operation completes normally with handled,
buffer.[[ArrayBufferByteLength]] is newByteLength.
- The return value is either handled or unhandled.
features: [resizable-arraybuffer]
---*/
var ab = new ArrayBuffer(4, {maxByteLength: 4});
var caught = false;
var result;
// If the host chooses to throw as allowed by the specification, the observed
// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
// has not been implemented. The following assertion prevents this test from
// passing in runtimes which have not implemented the method.
assert.sameValue(typeof ab.resize, 'function');
try {
result = ab.resize();
} catch (_) {
caught = true;
}
try {
ab.slice();
} catch (_) {
throw new Test262Error('The ArrayBuffer under test was detached');
}
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation and conforms to the
// invarient regarding [[ArrayBufferByteLength]]
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method updates [[ArrayBufferByteLength]]
//
// The final two conditions are indistinguishable.
assert(caught || ab.byteLength === 0, 'byteLength');
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation, and the `resize`
// method returns early
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method executes its final steps
//
// All three conditions have the same effect on the value of `result`.
assert.sameValue(result, undefined, 'normal completion value');
// The contents of the ArrayBuffer are not guaranteed by the host-defined
// abstract operation, so they are not asserted in this test.

View File

@ -0,0 +1,77 @@
// 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.resize
description: Behavior when attempting to shrink a resizable array buffer
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
throw a RangeError exception.
7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
[...]
HostResizeArrayBuffer ( buffer, newByteLength )
The implementation of HostResizeArrayBuffer must conform to the following
requirements:
- The abstract operation does not detach buffer.
- The abstract operation may complete normally or abruptly.
- If the abstract operation completes normally with handled,
buffer.[[ArrayBufferByteLength]] is newByteLength.
- The return value is either handled or unhandled.
features: [resizable-arraybuffer]
---*/
var ab = new ArrayBuffer(4, {maxByteLength: 4});
var caught = false;
var result;
// If the host chooses to throw as allowed by the specification, the observed
// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
// has not been implemented. The following assertion prevents this test from
// passing in runtimes which have not implemented the method.
assert.sameValue(typeof ab.resize, 'function');
try {
result = ab.resize(3);
} catch (_) {
caught = true;
}
try {
ab.slice();
} catch (_) {
throw new Test262Error('The ArrayBuffer under test was detached');
}
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation and conforms to the
// invarient regarding [[ArrayBufferByteLength]]
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method updates [[ArrayBufferByteLength]]
//
// The final two conditions are indistinguishable.
assert(caught || ab.byteLength === 3, 'byteLength');
// One of the following three conditions must be met:
//
// - HostResizeArrayBuffer returns an abrupt completion
// - HostResizeArrayBuffer handles the resize operation, and the `resize`
// method returns early
// - HostResizeArrayBuffer does not handle the resize operation, and the
// `resize` method executes its final steps
//
// All three conditions have the same effect on the value of `result`.
assert.sameValue(result, undefined, 'normal completion value');
// The contents of the ArrayBuffer are not guaranteed by the host-defined
// abstract operation, so they are not asserted in this test.

View File

@ -0,0 +1,27 @@
// 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.resize
description: >
Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot.
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
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]
---*/
assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
var ab = new ArrayBuffer(1);
$DETACHBUFFER(ab);
assert.throws(TypeError, function() {
ab.resize();
});

View File

@ -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-arraybuffer.prototype.resize
description: >
Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot.
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
[...]
features: [resizable-arraybuffer]
---*/
assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
assert.throws(TypeError, function() {
ArrayBuffer.prototype.resize();
}, '`this` value is the ArrayBuffer prototype');
assert.throws(TypeError, function() {
ArrayBuffer.prototype.resize.call({});
}, '`this` value is an object');
assert.throws(TypeError, function() {
ArrayBuffer.prototype.resize.call([]);
}, '`this` value is an array');

View File

@ -0,0 +1,44 @@
// 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.resize
description: Throws a TypeError if `this` valueis not an object.
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
[...]
features: [resizable-arraybuffer, Symbol, BigInt]
---*/
assert.sameValue(typeof ArrayBuffer.prototype.resize, "function");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.resize.call(undefined);
}, "`this` value is undefined");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.resize.call(null);
}, "`this` value is null");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.resize.call(true);
}, "`this` value is Boolean");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.resize.call("");
}, "`this` value is String");
var symbol = Symbol();
assert.throws(TypeError, function() {
ArrayBuffer.prototype.resize.call(symbol);
}, "`this` value is Symbol");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.resize.call(1);
}, "`this` value is Number");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.resize.call(1n);
}, "`this` value is bigint");

View File

@ -0,0 +1,38 @@
// 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.resize
description: >
Throws a TypeError if `this` does not have an [[ArrayBufferMaxByteLength]] internal slot.
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
[...]
features: [resizable-arraybuffer]
---*/
var ab;
assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
ab = new ArrayBuffer(4);
assert.throws(TypeError, function() {
ab.resize(0);
}, 'zero byte length');
ab = new ArrayBuffer(4);
assert.throws(TypeError, function() {
ab.resize(3);
}, 'smaller byte length');
ab = new ArrayBuffer(4);
assert.throws(TypeError, function() {
ab.resize(4);
}, 'same byte length');
ab = new ArrayBuffer(4);
assert.throws(TypeError, function() {
ab.resize(5);
}, 'larger byte length');

View File

@ -0,0 +1,20 @@
// 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.resize
description: Throws a TypeError if `this` value is a SharedArrayBuffer
info: |
ArrayBuffer.prototype.resize ( newLength )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
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.resize.call(sab);
}, '`this` value cannot be a SharedArrayBuffer');

View File

@ -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-arraybuffer.prototype.transfer
description: >
ArrayBuffer.prototype.transfer has default data property attributes.
info: |
ArrayBuffer.prototype.transfer ( [ 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]
---*/
verifyProperty(ArrayBuffer.prototype, 'transfer', {
enumerable: false,
writable: true,
configurable: true
});

View File

@ -0,0 +1,15 @@
// 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.transfer
description: ArrayBuffer.prototype.transfer is extensible.
info: |
ArrayBuffer.prototype.transfer ( [ 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]
---*/
assert(Object.isExtensible(ArrayBuffer.prototype.transfer));

View File

@ -0,0 +1,55 @@
// 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.transfer
description: Transfering from a fixed-size ArrayBuffer into a larger ArrayBuffer
info: |
ArrayBuffer.prototype.transfer ( [ 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) »).
8. NOTE: This method returns a fixed-length ArrayBuffer.
9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
10. Let fromBlock be O.[[ArrayBufferData]].
11. Let toBlock be new.[[ArrayBufferData]].
12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
13. NOTE: Neither creation of the new Data Block nor copying from the old
Data Block are observable. Implementations reserve the right to implement
this method as a zero-copy move or a realloc.
14. Perform ! DetachArrayBuffer(O).
15. Return new.
features: [resizable-arraybuffer]
---*/
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.transfer(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]');

View File

@ -0,0 +1,56 @@
// 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.transfer
description: |
Transfering from a fixed-size ArrayBuffer into an ArrayBuffer with the same
byte length
info: |
ArrayBuffer.prototype.transfer ( [ 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) »).
8. NOTE: This method returns a fixed-length ArrayBuffer.
9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
10. Let fromBlock be O.[[ArrayBufferData]].
11. Let toBlock be new.[[ArrayBufferData]].
12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
13. NOTE: Neither creation of the new Data Block nor copying from the old
Data Block are observable. Implementations reserve the right to implement
this method as a zero-copy move or a realloc.
14. Perform ! DetachArrayBuffer(O).
15. Return new.
features: [resizable-arraybuffer]
---*/
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.transfer();
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]');

View File

@ -0,0 +1,53 @@
// 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.transfer
description: Transfering from a fixed-size ArrayBuffer into a smaller ArrayBuffer
info: |
ArrayBuffer.prototype.transfer ( [ 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) »).
8. NOTE: This method returns a fixed-length ArrayBuffer.
9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
10. Let fromBlock be O.[[ArrayBufferData]].
11. Let toBlock be new.[[ArrayBufferData]].
12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
13. NOTE: Neither creation of the new Data Block nor copying from the old
Data Block are observable. Implementations reserve the right to implement
this method as a zero-copy move or a realloc.
14. Perform ! DetachArrayBuffer(O).
15. Return new.
features: [resizable-arraybuffer]
---*/
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.transfer(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]');

View File

@ -0,0 +1,47 @@
// 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.transfer
description: Transfering from a fixed-size ArrayBuffer into a zero-length ArrayBuffer
info: |
ArrayBuffer.prototype.transfer ( [ 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) »).
8. NOTE: This method returns a fixed-length ArrayBuffer.
9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
10. Let fromBlock be O.[[ArrayBufferData]].
11. Let toBlock be new.[[ArrayBufferData]].
12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
13. NOTE: Neither creation of the new Data Block nor copying from the old
Data Block are observable. Implementations reserve the right to implement
this method as a zero-copy move or a realloc.
14. Perform ! DetachArrayBuffer(O).
15. Return new.
features: [resizable-arraybuffer]
---*/
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.transfer(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');

View File

@ -0,0 +1,55 @@
// 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.transfer
description: Transfering from a resizable ArrayBuffer into a larger ArrayBuffer
info: |
ArrayBuffer.prototype.transfer ( [ 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) »).
8. NOTE: This method returns a fixed-length ArrayBuffer.
9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
10. Let fromBlock be O.[[ArrayBufferData]].
11. Let toBlock be new.[[ArrayBufferData]].
12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
13. NOTE: Neither creation of the new Data Block nor copying from the old
Data Block are observable. Implementations reserve the right to implement
this method as a zero-copy move or a realloc.
14. Perform ! DetachArrayBuffer(O).
15. Return new.
features: [resizable-arraybuffer]
---*/
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.transfer(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]');

View File

@ -0,0 +1,56 @@
// 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.transfer
description: |
Transfering from a resizable ArrayBuffer into an ArrayBuffer with the same
byte length
info: |
ArrayBuffer.prototype.transfer ( [ 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) »).
8. NOTE: This method returns a fixed-length ArrayBuffer.
9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
10. Let fromBlock be O.[[ArrayBufferData]].
11. Let toBlock be new.[[ArrayBufferData]].
12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
13. NOTE: Neither creation of the new Data Block nor copying from the old
Data Block are observable. Implementations reserve the right to implement
this method as a zero-copy move or a realloc.
14. Perform ! DetachArrayBuffer(O).
15. Return new.
features: [resizable-arraybuffer]
---*/
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.transfer();
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]');

View File

@ -0,0 +1,53 @@
// 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.transfer
description: Transfering from a resizable ArrayBuffer into a smaller ArrayBuffer
info: |
ArrayBuffer.prototype.transfer ( [ 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) »).
8. NOTE: This method returns a fixed-length ArrayBuffer.
9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
10. Let fromBlock be O.[[ArrayBufferData]].
11. Let toBlock be new.[[ArrayBufferData]].
12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
13. NOTE: Neither creation of the new Data Block nor copying from the old
Data Block are observable. Implementations reserve the right to implement
this method as a zero-copy move or a realloc.
14. Perform ! DetachArrayBuffer(O).
15. Return new.
features: [resizable-arraybuffer]
---*/
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.transfer(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]');

View File

@ -0,0 +1,47 @@
// 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.transfer
description: Transfering from a resizable ArrayBuffer into a zero-length ArrayBuffer
info: |
ArrayBuffer.prototype.transfer ( [ 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) »).
8. NOTE: This method returns a fixed-length ArrayBuffer.
9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
10. Let fromBlock be O.[[ArrayBufferData]].
11. Let toBlock be new.[[ArrayBufferData]].
12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
13. NOTE: Neither creation of the new Data Block nor copying from the old
Data Block are observable. Implementations reserve the right to implement
this method as a zero-copy move or a realloc.
14. Perform ! DetachArrayBuffer(O).
15. Return new.
features: [resizable-arraybuffer]
---*/
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.transfer(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');

View File

@ -0,0 +1,30 @@
// 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.transfer
description: >
ArrayBuffer.prototype.transfer.length is 0.
info: |
ArrayBuffer.prototype.transfer ( [ 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]
---*/
verifyProperty(ArrayBuffer.prototype.transfer, 'length', {
value: 0,
enumerable: false,
writable: false,
configurable: true
});

View File

@ -0,0 +1,27 @@
// 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.transfer
description: >
ArrayBuffer.prototype.transfer.name is "transfer".
info: |
ArrayBuffer.prototype.transfer ( [ 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]
includes: [propertyHelper.js]
---*/
verifyProperty(ArrayBuffer.prototype.transfer, 'name', {
value: 'transfer',
enumerable: false,
wrtiable: false,
configurable: true
});

View File

@ -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-arraybuffer.prototype.transfer
description: >
Throws a RangeError the newLength value is too large to create a new
ArrayBuffer.
info: |
ArrayBuffer.prototype.transfer ( [ 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]
---*/
var ab = new ArrayBuffer(0);
assert.throws(RangeError, function() {
// Math.pow(2, 53) = 9007199254740992
ab.transfer(9007199254740992);
});

View File

@ -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-arraybuffer.prototype.transfer
description: Throws a TypeError if provided length cannot be coerced to a number
info: |
ArrayBuffer.prototype.transfer ( [ 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]
---*/
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.transfer(newLength);
});
assert.sameValue(log.length, 2);
assert.sameValue(log[0], 'valueOf');
assert.sameValue(log[1], 'toString');

View File

@ -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-arraybuffer.prototype.transfer
description: >
ArrayBuffer.prototype.transfer is not a constructor function.
info: |
ArrayBuffer.prototype.transfer ( [ 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.
---*/
assert.sameValue(
Object.prototype.hasOwnProperty.call(ArrayBuffer.prototype.transfer, 'prototype'),
false
);
var arrayBuffer = new ArrayBuffer(8);
assert.throws(TypeError, function() {
new arrayBuffer.transfer();
});

View File

@ -0,0 +1,27 @@
// 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.transfer
description: >
Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot.
info: |
ArrayBuffer.prototype.transfer ( [ 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]
---*/
assert.sameValue(typeof ArrayBuffer.prototype.transfer, 'function');
var ab = new ArrayBuffer(1);
$DETACHBUFFER(ab);
assert.throws(TypeError, function() {
ab.transfer();
});

View File

@ -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-arraybuffer.prototype.transfer
description: >
Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot.
info: |
ArrayBuffer.prototype.transfer ( [ newLength ] )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
[...]
features: [resizable-arraybuffer]
---*/
assert.sameValue(typeof ArrayBuffer.prototype.transfer, 'function');
assert.throws(TypeError, function() {
ArrayBuffer.prototype.transfer();
}, '`this` value is the ArrayBuffer prototype');
assert.throws(TypeError, function() {
ArrayBuffer.prototype.transfer.call({});
}, '`this` value is an object');
assert.throws(TypeError, function() {
ArrayBuffer.prototype.transfer.call([]);
}, '`this` value is an array');

View File

@ -0,0 +1,44 @@
// 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.transfer
description: Throws a TypeError if `this` valueis not an object.
info: |
ArrayBuffer.prototype.transfer ( [ newLength ] )
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
[...]
features: [resizable-arraybuffer, Symbol, BigInt]
---*/
assert.sameValue(typeof ArrayBuffer.prototype.transfer, "function");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.transfer.call(undefined);
}, "`this` value is undefined");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.transfer.call(null);
}, "`this` value is null");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.transfer.call(true);
}, "`this` value is Boolean");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.transfer.call("");
}, "`this` value is String");
var symbol = Symbol();
assert.throws(TypeError, function() {
ArrayBuffer.prototype.transfer.call(symbol);
}, "`this` value is Symbol");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.transfer.call(1);
}, "`this` value is Number");
assert.throws(TypeError, function() {
ArrayBuffer.prototype.transfer.call(1n);
}, "`this` value is bigint");

View File

@ -0,0 +1,20 @@
// 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.transfer
description: Throws a TypeError if `this` value is a SharedArrayBuffer
info: |
ArrayBuffer.prototype.transfer ( [ 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.transfer.call(sab);
}, '`this` value cannot be a SharedArrayBuffer');