Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Object / assign / target-is-frozen-data-property-set-throws.js
blob943798ccc6b1a4857cc565f5c12c24bae88b7cd8
1 // Copyright (C) 2021 Alexey Shvayka. All rights reserved.
2 // This code is governed by the license found in the LICENSE file.
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 )
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.
26   Object.assign ( target, ...sources )
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).
38   OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
40   [...]
41   3. If IsDataDescriptor(ownDesc) is true, then
42     a. If ownDesc.[[Writable]] is false, return false.
43 features: [Symbol, Reflect]
44 ---*/
46 var sym = Symbol();
47 var target1 = { [sym]: 1 };
49 Object.freeze(target1);
50 assert.throws(TypeError, function() {
51   Object.assign(target1, { [sym]: 1 });
52 });
55 var target2 = Object.freeze({ foo: 1 });
57 assert.throws(TypeError, function() {
58   Object.assign(target2, { foo: 1 });
59 });
61 reportCompare(0, 0);