summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/length/define-own-prop-length-overflow-order.js
blob: 9cdb0d38607dcf70c599fe87fb412b021a5a2164 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 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});
}, 'Object.defineProperty([], "length", {value: -1, configurable: true}) throws a RangeError exception');

assert.throws(RangeError, function() {
  Object.defineProperty([], "length", {value: NaN, enumerable: true});
}, 'Object.defineProperty([], "length", {value: NaN, enumerable: true}) throws a RangeError exception');

var array = [];
Object.defineProperty(array, "length", {writable: false});
assert.throws(RangeError, function() {
  Object.defineProperty(array, "length", {value: Number.MAX_SAFE_INTEGER, writable: true});
}, 'Object.defineProperty(array, "length", {value: Number.MAX_SAFE_INTEGER, writable: true}) throws a RangeError exception');

reportCompare(0, 0);