From 1fd4fb480cd3bbe985f77a5a7643f1b412a2a7ed Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Fri, 5 Feb 2021 15:57:47 +0200 Subject: [PATCH] Add Object.seal tests --- ...et-is-sealed-existing-accessor-property.js | 55 ++++++++++++++++ ...target-is-sealed-existing-data-property.js | 62 +++++++++++++++++++ ...rget-is-sealed-property-creation-throws.js | 59 ++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 test/built-ins/Object/assign/target-is-sealed-existing-accessor-property.js create mode 100644 test/built-ins/Object/assign/target-is-sealed-existing-data-property.js create mode 100644 test/built-ins/Object/assign/target-is-sealed-property-creation-throws.js diff --git a/test/built-ins/Object/assign/target-is-sealed-existing-accessor-property.js b/test/built-ins/Object/assign/target-is-sealed-existing-accessor-property.js new file mode 100644 index 0000000000..d56ca143dc --- /dev/null +++ b/test/built-ins/Object/assign/target-is-sealed-existing-accessor-property.js @@ -0,0 +1,55 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to existing accessor property of sealed `target` is successful. +info: | + SetIntegrityLevel ( O, level ) + + [...] + 3. Let status be ? O.[[PreventExtensions]](). + [...] + + OrdinaryPreventExtensions ( O ) + + 1. Set O.[[Extensible]] to false. + + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 7. Perform ? Call(setter, Receiver, « V »). + 8. Return true. +---*/ + +var value1 = 1; +var target1 = Object.seal({ + set foo(val) { value1 = val; }, +}); + +Object.assign(target1, { foo: 2 }); +assert.sameValue(value1, 2); + + +var sym = Symbol(); +var value2 = 1; +var target2 = { + set [sym](val) { value2 = val; }, +}; + +Object.seal(target2); +Object.assign(target2, { [sym]: 2 }); +assert.sameValue(value2, 2); diff --git a/test/built-ins/Object/assign/target-is-sealed-existing-data-property.js b/test/built-ins/Object/assign/target-is-sealed-existing-data-property.js new file mode 100644 index 0000000000..b3562de2ef --- /dev/null +++ b/test/built-ins/Object/assign/target-is-sealed-existing-data-property.js @@ -0,0 +1,62 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to existing data property of sealed `target` is successful. +info: | + SetIntegrityLevel ( O, level ) + + [...] + 3. Let status be ? O.[[PreventExtensions]](). + [...] + + OrdinaryPreventExtensions ( O ) + + 1. Set O.[[Extensible]] to false. + + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 3. If IsDataDescriptor(ownDesc) is true, then + [...] + c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). + d. If existingDescriptor is not undefined, then + [...] + iii. Let valueDesc be the PropertyDescriptor { [[Value]]: V }. + iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc). + + ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) + + [...] + 9. If O is not undefined, then + a. For each field of Desc that is present, set the corresponding attribute + of the property named P of object O to the value of the field. + 10. Return true. +---*/ + +var target1 = Object.seal({ foo: 1 }); + +Object.assign(target1, { foo: 2 }); +assert.sameValue(target1.foo, 2); + + +var sym = Symbol(); +var target2 = { [sym]: 1 }; + +Object.seal(target2); +Object.assign(target2, { [sym]: 2 }); +assert.sameValue(target2[sym], 2); diff --git a/test/built-ins/Object/assign/target-is-sealed-property-creation-throws.js b/test/built-ins/Object/assign/target-is-sealed-property-creation-throws.js new file mode 100644 index 0000000000..510dd83bf9 --- /dev/null +++ b/test/built-ins/Object/assign/target-is-sealed-property-creation-throws.js @@ -0,0 +1,59 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to non-existing property of sealed `target` fails with TypeError. +info: | + SetIntegrityLevel ( O, level ) + + [...] + 3. Let status be ? O.[[PreventExtensions]](). + [...] + + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 3. If IsDataDescriptor(ownDesc) is true, then + [...] + c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). + d. If existingDescriptor is not undefined, then + [...] + e. Else, + i. Assert: Receiver does not currently have a property P. + ii. Return ? CreateDataProperty(Receiver, P, V). + + ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) + + [...] + 2. If current is undefined, then + a. If extensible is false, return false. +features: [Symbol, Reflect] +---*/ + +var target1 = Object.seal({ foo: 1 }); + +assert.throws(TypeError, function() { + Object.assign(target1, { get bar() {} }); +}); + + +var target2 = {}; + +Object.seal(target2); +assert.throws(TypeError, function() { + Object.assign(target2, { [Symbol()]: 1 }); +});