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