Debian Codegraph @

js/src/tests/test262/built-ins/Object/assign/target-is-non-extensible-property-creation-throws.js

raw
1 // Copyright (C) 2021 Alexey Shvayka. All rights reserved.
2 // This code is governed by the license found in the LICENSE file.
3
4 /*---
5 esid: sec-object.assign
6 description: >
7 [[Set]] to non-existing property of non-extensible `target` fails with TypeError.
8 info: |
9 Object.assign ( target, ...sources )
10
11 [...]
12 3. For each element nextSource of sources, do
13 a. If nextSource is neither undefined nor null, then
14 [...]
15 iii. For each element nextKey of keys, do
16 1. Let desc be ? from.[[GetOwnProperty]](nextKey).
17 2. If desc is not undefined and desc.[[Enumerable]] is true, then
18 [...]
19 b. Perform ? Set(to, nextKey, propValue, true).
20
21 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
22
23 [...]
24 3. If IsDataDescriptor(ownDesc) is true, then
25 [...]
26 c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P).
27 d. If existingDescriptor is not undefined, then
28 [...]
29 e. Else,
30 i. Assert: Receiver does not currently have a property P.
31 ii. Return ? CreateDataProperty(Receiver, P, V).
32
33 ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current )
34
35 [...]
36 2. If current is undefined, then
37 a. If extensible is false, return false.
38 features: [Symbol]
39 ---*/
40
41 var target1 = Object.preventExtensions({ foo: 1 });
42
43 assert.throws(TypeError, function() {
44 Object.assign(target1, { get bar() {} });
45 });
46
47
48 var target2 = {};
49
50 Object.preventExtensions(target2);
51 assert.throws(TypeError, function() {
52 Object.assign(target2, { [Symbol()]: 1 });
53 });
54
55 reportCompare(0, 0);