Debian Codegraph @

js/src/tests/test262/built-ins/Object/assign/target-is-frozen-data-property-set-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 data property of frozen `target` fails with TypeError.
8 info: |
9 SetIntegrityLevel ( O, level )
10
11 [...]
12 3. Let status be ? O.[[PreventExtensions]]().
13 [...]
14 7. Else,
15 a. Assert: level is frozen.
16 b. For each element k of keys, do
17 i. Let currentDesc be ? O.[[GetOwnProperty]](k).
18 ii. If currentDesc is not undefined, then
19 1. If IsAccessorDescriptor(currentDesc) is true, then
20 [...]
21 2. Else,
22 a. Let desc be the PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }.
23 3. Perform ? DefinePropertyOrThrow(O, k, desc).
24 8. Return true.
25
26 Object.assign ( target, ...sources )
27
28 [...]
29 3. For each element nextSource of sources, do
30 a. If nextSource is neither undefined nor null, then
31 [...]
32 iii. For each element nextKey of keys, do
33 1. Let desc be ? from.[[GetOwnProperty]](nextKey).
34 2. If desc is not undefined and desc.[[Enumerable]] is true, then
35 [...]
36 b. Perform ? Set(to, nextKey, propValue, true).
37
38 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
39
40 [...]
41 3. If IsDataDescriptor(ownDesc) is true, then
42 a. If ownDesc.[[Writable]] is false, return false.
43 features: [Symbol, Reflect]
44 ---*/
45
46 var sym = Symbol();
47 var target1 = { [sym]: 1 };
48
49 Object.freeze(target1);
50 assert.throws(TypeError, function() {
51 Object.assign(target1, { [sym]: 1 });
52 });
53
54
55 var target2 = Object.freeze({ foo: 1 });
56
57 assert.throws(TypeError, function() {
58 Object.assign(target2, { foo: 1 });
59 });
60
61 reportCompare(0, 0);