Test "length" [[Value]] overflow check order in ArraySetLength

This commit is contained in:
Alexey Shvayka 2020-09-06 16:37:21 +03:00 committed by Rick Waldron
parent d993d87766
commit afd849ad29
2 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,56 @@
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraysetlength
description: >
Ordinary descriptor validation if [[Value]] is absent.
info: |
ArraySetLength ( A, Desc )
1. If Desc.[[Value]] is absent, then
a. Return OrdinaryDefineOwnProperty(A, "length", Desc).
OrdinaryDefineOwnProperty ( O, P, Desc )
[...]
3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current).
ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current )
[...]
4. If current.[[Configurable]] is false, then
a. If Desc.[[Configurable]] is present and its value is true, return false.
b. If Desc.[[Enumerable]] is present and
! SameValue(Desc.[[Enumerable]], current.[[Enumerable]]) is false, return false.
[...]
6. Else if ! SameValue(! IsDataDescriptor(current), ! IsDataDescriptor(Desc)) is false, then
a. If current.[[Configurable]] is false, return false.
[...]
7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true, then
a. If current.[[Configurable]] is false and current.[[Writable]] is false, then
i. If Desc.[[Writable]] is present and Desc.[[Writable]] is true, return false.
features: [Reflect]
---*/
assert.throws(TypeError, function() {
Object.defineProperty([], "length", {configurable: true});
});
assert(!Reflect.defineProperty([], "length", {enumerable: true}));
assert.throws(TypeError, function() {
Object.defineProperty([], "length", {
get: function() {
throw new Test262Error("[[Get]] shouldn't be called");
},
});
});
assert(!Reflect.defineProperty([], "length", {set: function(_value) {}}));
var array = [];
Object.defineProperty(array, "length", {writable: false});
assert.throws(TypeError, function() {
Object.defineProperty(array, "length", {writable: true});
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraysetlength
description: >
[[Value]] is checked for overflow before descriptor validation.
info: |
ArraySetLength ( A, Desc )
[...]
3. Let newLen be ? ToUint32(Desc.[[Value]]).
4. Let numberLen be ? ToNumber(Desc.[[Value]]).
5. If newLen numberLen, throw a RangeError exception.
---*/
assert.throws(RangeError, function() {
Object.defineProperty([], "length", {value: -1, configurable: true});
});
assert.throws(RangeError, function() {
Object.defineProperty([], "length", {value: NaN, enumerable: true});
});
var array = [];
Object.defineProperty(array, "length", {writable: false});
assert.throws(RangeError, function() {
Object.defineProperty(array, "length", {value: Number.MAX_SAFE_INTEGER, writable: true});
});