Debian Codegraph @

js/src/tests/test262/built-ins/Array/length/define-own-prop-length-no-value-order.js

raw
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-arraysetlength
6 description: >
7 Ordinary descriptor validation if [[Value]] is absent.
8 info: |
9 ArraySetLength ( A, Desc )
10
11 1. If Desc.[[Value]] is absent, then
12 a. Return OrdinaryDefineOwnProperty(A, "length", Desc).
13
14 OrdinaryDefineOwnProperty ( O, P, Desc )
15
16 [...]
17 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current).
18
19 ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current )
20
21 [...]
22 4. If current.[[Configurable]] is false, then
23 a. If Desc.[[Configurable]] is present and its value is true, return false.
24 b. If Desc.[[Enumerable]] is present and
25 ! SameValue(Desc.[[Enumerable]], current.[[Enumerable]]) is false, return false.
26 [...]
27 6. Else if ! SameValue(! IsDataDescriptor(current), ! IsDataDescriptor(Desc)) is false, then
28 a. If current.[[Configurable]] is false, return false.
29 [...]
30 7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true, then
31 a. If current.[[Configurable]] is false and current.[[Writable]] is false, then
32 i. If Desc.[[Writable]] is present and Desc.[[Writable]] is true, return false.
33 features: [Reflect]
34 ---*/
35
36 assert.throws(TypeError, function() {
37 Object.defineProperty([], "length", {configurable: true});
38 }, 'Object.defineProperty([], "length", {configurable: true}) throws a TypeError exception');
39
40 assert(
41 !Reflect.defineProperty([], "length", {enumerable: true}),
42 'The value of !Reflect.defineProperty([], "length", {enumerable: true}) is expected to be true'
43 );
44
45 assert.throws(TypeError, function() {
46 Object.defineProperty([], "length", {
47 get: function() {
48 throw new Test262Error("[[Get]] shouldn't be called");
49 },
50 });
51 }, 'Object.defineProperty([], "length", {get: function() {throw new Test262Error("[[Get]] shouldn"t be called");},}) throws a TypeError exception');
52
53 assert(
54 !Reflect.defineProperty([], "length", {set: function(_value) {}}),
55 'The value of !Reflect.defineProperty([], "length", {set: function(_value) {}}) is expected to be true'
56 );
57
58 var array = [];
59 Object.defineProperty(array, "length", {writable: false});
60 assert.throws(TypeError, function() {
61 Object.defineProperty(array, "length", {writable: true});
62 }, 'Object.defineProperty(array, "length", {writable: true}) throws a TypeError exception');
63
64 reportCompare(0, 0);