| 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 existing data property of non-extensible `target` is successful. |
| 8 |
info: | |
| 9 |
OrdinaryPreventExtensions ( O ) |
| 10 |
|
| 11 |
1. Set O.[[Extensible]] to false. |
| 12 |
|
| 13 |
Object.assign ( target, ...sources ) |
| 14 |
|
| 15 |
[...] |
| 16 |
3. For each element nextSource of sources, do |
| 17 |
a. If nextSource is neither undefined nor null, then |
| 18 |
[...] |
| 19 |
iii. For each element nextKey of keys, do |
| 20 |
1. Let desc be ? from.[[GetOwnProperty]](nextKey). |
| 21 |
2. If desc is not undefined and desc.[[Enumerable]] is true, then |
| 22 |
[...] |
| 23 |
b. Perform ? Set(to, nextKey, propValue, true). |
| 24 |
|
| 25 |
OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) |
| 26 |
|
| 27 |
[...] |
| 28 |
3. If IsDataDescriptor(ownDesc) is true, then |
| 29 |
[...] |
| 30 |
c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). |
| 31 |
d. If existingDescriptor is not undefined, then |
| 32 |
[...] |
| 33 |
iii. Let valueDesc be the PropertyDescriptor { [[Value]]: V }. |
| 34 |
iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc). |
| 35 |
|
| 36 |
ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) |
| 37 |
|
| 38 |
[...] |
| 39 |
9. If O is not undefined, then |
| 40 |
a. For each field of Desc that is present, set the corresponding attribute |
| 41 |
of the property named P of object O to the value of the field. |
| 42 |
10. Return true. |
| 43 |
features: [Symbol] |
| 44 |
---*/ |
| 45 |
|
| 46 |
var target1 = Object.preventExtensions({ foo: 1 }); |
| 47 |
|
| 48 |
Object.assign(target1, { foo: 2 }); |
| 49 |
assert.sameValue(target1.foo, 2); |
| 50 |
|
| 51 |
|
| 52 |
var sym = Symbol(); |
| 53 |
var target2 = { [sym]: 1 }; |
| 54 |
|
| 55 |
Object.preventExtensions(target2); |
| 56 |
Object.assign(target2, { [sym]: 2 }); |
| 57 |
assert.sameValue(target2[sym], 2); |
| 58 |
|
| 59 |
reportCompare(0, 0); |