Resizable ArrayBuffer: ArrayBuffer constructor (#3018)

* Add "feature" for "Resizable ArrayBuffer" proposal

* Resizable ArrayBuffer: ArrayBuffer constructor
This commit is contained in:
jugglinmike 2021-06-25 13:18:42 -04:00 committed by GitHub
parent 966c76617e
commit b3c2d3a88e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 204 additions and 0 deletions

View File

@ -331,3 +331,7 @@ import-assertions
# JSON modules
# https://github.com/tc39/proposal-json-modules
json-modules
# Resizable Arraybuffer
# https://github.com/tc39/proposal-resizablearraybuffer
resizable-arraybuffer

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-constructor
description: |
Invoked with an options object whose `maxByteLength` property is less than
the length.
info:
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
4. If requestedMaxByteLength is empty, then
a. [...]
5. If byteLength > requestedMaxByteLength, throw a RangeError exception.
features: [resizable-arraybuffer]
---*/
assert.throws(RangeError, function() {
new ArrayBuffer(1, {maxByteLength: 0});
});

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-constructor
description: |
Invoked with an options object whose `maxByteLength` property exceeds the
maximum length value
info:
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
[...]
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
2. Let maxByteLength be ? Get(options, "maxByteLength").
3. If maxByteLength is undefined, return empty.
4. Return ? ToIndex(maxByteLength).
features: [resizable-arraybuffer]
---*/
assert.throws(RangeError, function() {
// Math.pow(2, 53) = 9007199254740992
new ArrayBuffer(0, { maxByteLength: 9007199254740992 });
});

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-constructor
description: Invoked with an options object whose `maxByteLength` property is negative
info:
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
[...]
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
2. Let maxByteLength be ? Get(options, "maxByteLength").
3. If maxByteLength is undefined, return empty.
4. Return ? ToIndex(maxByteLength).
features: [resizable-arraybuffer]
---*/
assert.throws(RangeError, function() {
new ArrayBuffer(0, { maxByteLength: -1 });
});

View File

@ -0,0 +1,45 @@
// 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-constructor
description: |
Invoked with an options object whose `maxByteLength` property cannot be
coerced to a primitive value
info:
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
[...]
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
2. Let maxByteLength be ? Get(options, "maxByteLength").
3. If maxByteLength is undefined, return empty.
4. Return ? ToIndex(maxByteLength).
features: [resizable-arraybuffer]
---*/
var log = [];
var options = {
maxByteLength: {
toString: function() {
log.push('toString');
return {};
},
valueOf: function() {
log.push('valueOf');
return {};
}
}
};
assert.throws(TypeError, function() {
new ArrayBuffer(0, options);
});
assert.sameValue(log.length, 2);
assert.sameValue(log[0], 'valueOf');
assert.sameValue(log[1], 'toString');

View File

@ -0,0 +1,29 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer-constructor
description: Invoked with an options object whose `maxByteLength` property throws
info: |
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
[...]
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
2. Let maxByteLength be ? Get(options, "maxByteLength").
features: [resizable-arraybuffer]
---*/
var options = {
get maxByteLength() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
new ArrayBuffer(0, options);
});

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-constructor
description: Invoked with an options object whose `maxByteLength` property is undefined
info: |
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
4. If requestedMaxByteLength is empty, then
a. Return ? AllocateArrayBuffer(NewTarget, byteLength).
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
2. Let maxByteLength be ? Get(options, "maxByteLength").
3. If maxByteLength is undefined, return empty.
features: [resizable-arraybuffer]
---*/
assert.sameValue(new ArrayBuffer(0, {}).resizable, false);
assert.sameValue(new ArrayBuffer(0, {maxByteLength: undefined}).resizable, false);

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-constructor
description: Invoked with a non-object value for options
info: |
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
4. If requestedMaxByteLength is empty, then
a. Return ? AllocateArrayBuffer(NewTarget, byteLength).
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
features: [resizable-arraybuffer]
---*/
assert.sameValue(new ArrayBuffer(0, null).resizable, false, 'null');
assert.sameValue(new ArrayBuffer(0, true).resizable, false, 'boolean');
assert.sameValue(new ArrayBuffer(0, Symbol(3)).resizable, false, 'symbol');
assert.sameValue(new ArrayBuffer(0, 1n).resizable, false, 'bigint');
assert.sameValue(new ArrayBuffer(0, 'string').resizable, false, 'string');
assert.sameValue(new ArrayBuffer(0, 9).resizable, false, 'number');
assert.sameValue(new ArrayBuffer(0, undefined).resizable, false, 'undefined');