mirror of https://github.com/tc39/test262.git
Resizable ArrayBuffer: SharedArrayBuffer methods (#3024)
* Add "feature" for "Resizable ArrayBuffer" proposal * Resizable ArrayBuffer: SharedArrayBuffer methods * fixup! Resizable ArrayBuffer: SharedArrayBuffer methods
This commit is contained in:
parent
1db1bb8216
commit
a82aeaa391
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
SharedArrayBuffer.prototype.grow has default data property attributes.
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( 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(SharedArrayBuffer.prototype, 'grow', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: SharedArrayBuffer.prototype.grow is extensible.
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( 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(SharedArrayBuffer.prototype.grow));
|
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
Behavior when attempting to grow a growable array buffer to a larger size
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( newLength )
|
||||
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
3. If IsSharedArrayBuffer(O) is false throw a TypeError exception.
|
||||
4. Let newByteLength be ? ToIntegerOrInfinity(newLength).
|
||||
5. Let hostHandled be ? HostGrowSharedArrayBuffer(O, newByteLength).
|
||||
6. If hostHandled is handled, return undefined.
|
||||
[...]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
var sab = new SharedArrayBuffer(4, {maxByteLength: 5});
|
||||
var result;
|
||||
|
||||
// If the host chooses to throw as allowed by the specification, the observed
|
||||
// behavior will be identical to the case where
|
||||
// `SharedArrayBuffer.prototype.grow` has not been implemented. The following
|
||||
// assertion prevents this test from passing in runtimes which have not
|
||||
// implemented the method.
|
||||
assert.sameValue(typeof sab.grow, 'function');
|
||||
|
||||
try {
|
||||
result = ab.grow(5);
|
||||
} catch (_) {}
|
||||
|
||||
// One of the following three conditions must be met:
|
||||
//
|
||||
// - HostGrowSharedArrayBuffer returns an abrupt completion
|
||||
// - HostGrowSharedArrayBuffer handles the grow operation, and the `grow`
|
||||
// method returns early
|
||||
// - HostGrowSharedArrayBuffer does not handle the grow operation, and the
|
||||
// `grow` method executes its final steps
|
||||
//
|
||||
// All three conditions have the same effect on the value of `result`.
|
||||
assert.sameValue(result, undefined, 'normal completion value');
|
||||
|
||||
// Neither the length nor the contents of the SharedArrayBuffer are guaranteed
|
||||
// by the host-defined abstract operation, so they are not asserted in this
|
||||
// test.
|
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
Behavior when attempting to grow a growable array buffer to its current size
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( newLength )
|
||||
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
3. If IsSharedArrayBuffer(O) is false throw a TypeError exception.
|
||||
4. Let newByteLength be ? ToIntegerOrInfinity(newLength).
|
||||
5. Let hostHandled be ? HostGrowSharedArrayBuffer(O, newByteLength).
|
||||
6. If hostHandled is handled, return undefined.
|
||||
[...]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
var sab = new SharedArrayBuffer(4, {maxByteLength: 5});
|
||||
var result;
|
||||
|
||||
// If the host chooses to throw as allowed by the specification, the observed
|
||||
// behavior will be identical to the case where
|
||||
// `SharedArrayBuffer.prototype.grow` has not been implemented. The following
|
||||
// assertion prevents this test from passing in runtimes which have not
|
||||
// implemented the method.
|
||||
assert.sameValue(typeof sab.grow, 'function');
|
||||
|
||||
try {
|
||||
result = ab.grow(4);
|
||||
} catch (_) {}
|
||||
|
||||
// One of the following three conditions must be met:
|
||||
//
|
||||
// - HostGrowSharedArrayBuffer returns an abrupt completion
|
||||
// - HostGrowSharedArrayBuffer handles the grow operation, and the `grow`
|
||||
// method returns early
|
||||
// - HostGrowSharedArrayBuffer does not handle the grow operation, and the
|
||||
// `grow` method executes its final steps
|
||||
//
|
||||
// All three conditions have the same effect on the value of `result`.
|
||||
assert.sameValue(result, undefined, 'normal completion value');
|
||||
|
||||
// Neither the length nor the contents of the SharedArrayBuffer are guaranteed
|
||||
// by the host-defined abstract operation, so they are not asserted in this
|
||||
// test.
|
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
Behavior when attempting to grow a growable array buffer to a smaller size
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( newLength )
|
||||
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
3. If IsSharedArrayBuffer(O) is false throw a TypeError exception.
|
||||
4. Let newByteLength be ? ToIntegerOrInfinity(newLength).
|
||||
5. Let hostHandled be ? HostGrowSharedArrayBuffer(O, newByteLength).
|
||||
6. If hostHandled is handled, return undefined.
|
||||
[...]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
var sab = new SharedArrayBuffer(4, {maxByteLength: 5});
|
||||
var result;
|
||||
|
||||
// If the host chooses to throw as allowed by the specification, the observed
|
||||
// behavior will be identical to the case where
|
||||
// `SharedArrayBuffer.prototype.grow` has not been implemented. The following
|
||||
// assertion prevents this test from passing in runtimes which have not
|
||||
// implemented the method.
|
||||
assert.sameValue(typeof sab.grow, 'function');
|
||||
|
||||
try {
|
||||
result = ab.grow(3);
|
||||
} catch (_) {}
|
||||
|
||||
// One of the following three conditions must be met:
|
||||
//
|
||||
// - HostGrowSharedArrayBuffer returns an abrupt completion
|
||||
// - HostGrowSharedArrayBuffer handles the grow operation, and the `grow`
|
||||
// method returns early
|
||||
// - HostGrowSharedArrayBuffer does not handle the grow operation, and the
|
||||
// `grow` method executes its final steps
|
||||
//
|
||||
// All three conditions have the same effect on the value of `result`.
|
||||
assert.sameValue(result, undefined, 'normal completion value');
|
||||
|
||||
// Neither the length nor the contents of the SharedArrayBuffer are guaranteed
|
||||
// by the host-defined abstract operation, so they are not asserted in this
|
||||
// test.
|
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
SharedArrayBuffer.prototype.grow.length is 1.
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( 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(SharedArrayBuffer.prototype.grow, 'length', {
|
||||
value: 1,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
configurable: true
|
||||
});
|
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
SharedArrayBuffer.prototype.grow.name is "grow".
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( 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(SharedArrayBuffer.prototype.grow, 'name', {
|
||||
value: 'grow',
|
||||
enumerable: false,
|
||||
wrtiable: false,
|
||||
configurable: true
|
||||
});
|
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
Throws a RangeError the newLength value is larger than the max byte length
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( newLength )
|
||||
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
|
||||
4. Let newByteLength be ? ToIntegerOrInfinity(newLength).
|
||||
5. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
|
||||
throw a RangeError exception.
|
||||
[...]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
var ab = new SharedArrayBuffer(4, {maxByteLength: 4});
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
ab.grow(5);
|
||||
});
|
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
Throws a RangeError the newLength value is less than zero
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( newLength )
|
||||
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
|
||||
4. Let newByteLength be ? ToIntegerOrInfinity(newLength).
|
||||
5. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
|
||||
throw a RangeError exception.
|
||||
[...]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
var ab = new SharedArrayBuffer(4, {maxByteLength: 4});
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
ab.grow(-1);
|
||||
});
|
|
@ -0,0 +1,36 @@
|
|||
// 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-sharedarraybuffer.prototype.grow
|
||||
description: Throws a TypeError if provided length cannot be coerced to a number
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( newLength )
|
||||
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
|
||||
4. 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 SharedArrayBuffer(0, {maxByteLength: 4});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
ab.grow(newLength);
|
||||
});
|
||||
|
||||
assert.sameValue(log.length, 2);
|
||||
assert.sameValue(log[0], 'valueOf');
|
||||
assert.sameValue(log[1], 'toString');
|
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
SharedArrayBuffer.prototype.grow is not a constructor function.
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( 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(SharedArrayBuffer.prototype.grow, 'prototype'),
|
||||
false
|
||||
);
|
||||
|
||||
var arrayBuffer = new SharedArrayBuffer(8);
|
||||
assert.throws(TypeError, function() {
|
||||
new arrayBuffer.grow();
|
||||
});
|
28
test/built-ins/SharedArrayBuffer/prototype/grow/this-is-not-arraybuffer-object.js
vendored
Normal file
28
test/built-ins/SharedArrayBuffer/prototype/grow/this-is-not-arraybuffer-object.js
vendored
Normal 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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot.
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( newLength )
|
||||
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
[...]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof SharedArrayBuffer.prototype.grow, 'function');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow();
|
||||
}, '`this` value is the SharedArrayBuffer prototype');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow.call({});
|
||||
}, '`this` value is an object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow.call([]);
|
||||
}, '`this` value is an array');
|
|
@ -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-sharedarraybuffer.prototype.grow
|
||||
description: Throws a TypeError if `this` valueis not an object.
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( newLength )
|
||||
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
[...]
|
||||
features: [resizable-arraybuffer, Symbol, BigInt]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof SharedArrayBuffer.prototype.grow, "function");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow.call(undefined);
|
||||
}, "`this` value is undefined");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow.call(null);
|
||||
}, "`this` value is null");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow.call(true);
|
||||
}, "`this` value is Boolean");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow.call("");
|
||||
}, "`this` value is String");
|
||||
|
||||
var symbol = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow.call(symbol);
|
||||
}, "`this` value is Symbol");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow.call(1);
|
||||
}, "`this` value is Number");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow.call(1n);
|
||||
}, "`this` value is bigint");
|
38
test/built-ins/SharedArrayBuffer/prototype/grow/this-is-not-resizable-arraybuffer-object.js
vendored
Normal file
38
test/built-ins/SharedArrayBuffer/prototype/grow/this-is-not-resizable-arraybuffer-object.js
vendored
Normal 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-sharedarraybuffer.prototype.grow
|
||||
description: >
|
||||
Throws a TypeError if `this` does not have an [[ArrayBufferMaxByteLength]] internal slot.
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( newLength )
|
||||
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
[...]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
var ab;
|
||||
|
||||
assert.sameValue(typeof SharedArrayBuffer.prototype.grow, 'function');
|
||||
|
||||
ab = new SharedArrayBuffer(4);
|
||||
assert.throws(TypeError, function() {
|
||||
ab.grow(0);
|
||||
}, 'zero byte length');
|
||||
|
||||
ab = new SharedArrayBuffer(4);
|
||||
assert.throws(TypeError, function() {
|
||||
ab.grow(3);
|
||||
}, 'smaller byte length');
|
||||
|
||||
ab = new SharedArrayBuffer(4);
|
||||
assert.throws(TypeError, function() {
|
||||
ab.grow(4);
|
||||
}, 'same byte length');
|
||||
|
||||
ab = new SharedArrayBuffer(4);
|
||||
assert.throws(TypeError, function() {
|
||||
ab.grow(5);
|
||||
}, 'larger byte length');
|
20
test/built-ins/SharedArrayBuffer/prototype/grow/this-is-sharedarraybuffer.js
vendored
Normal file
20
test/built-ins/SharedArrayBuffer/prototype/grow/this-is-sharedarraybuffer.js
vendored
Normal 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-sharedarraybuffer.prototype.grow
|
||||
description: Throws a TypeError if `this` value is an ArrayBuffer
|
||||
info: |
|
||||
SharedArrayBuffer.prototype.grow ( newLength )
|
||||
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
|
||||
[...]
|
||||
features: [ArrayBuffer, resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
var ab = new ArrayBuffer(0);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
SharedArrayBuffer.prototype.grow.call(ab);
|
||||
}, '`this` value cannot be an ArrayBuffer');
|
Loading…
Reference in New Issue