nodejs/deps/v8/test/mjsunit/object-define-property-length.js
Michaël Zasso 09a8440b45
deps: update V8 to 12.2.281.27
PR-URL: https://github.com/nodejs/node/pull/51362
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2024-03-31 15:36:07 +02:00

44 lines
1.0 KiB
JavaScript

// Copyright 2024 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Tests the object.defineProperty method - ES 15.2.3.6
var arr = new Array()
arr[1] = 'foo'
arr[2] = 'bar'
arr[3] = '42'
arr[4] = '43'
arr[5] = '44'
// ES6 9.4.2.1
// If P is 'length', than ArraySetLength(A, Desc).
assertThrows(
() => Object.defineProperty(arr, 'length', { value: -1, configurable: true }),
RangeError,
'Invalid array length'
)
assertThrows(
() =>
Object.defineProperty(arr, 'len' + 'gth', {
value: -1,
configurable: true
}),
RangeError,
'Invalid array length'
)
assertThrows(
() => Object.defineProperty(arr, 'length', { value: 1, configurable: true }),
TypeError,
'Cannot redefine property: length'
)
Object.defineProperty(arr, 'length', { value: 10 })
desc = Object.getOwnPropertyDescriptor(arr, 'length')
assertEquals(desc.value, 10)
assertTrue(desc.writable)
assertFalse(desc.enumerable)
assertFalse(desc.configurable)