-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fd4fb4
commit fd6bbbe
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
test/built-ins/Object/assign/target-is-frozen-accessor-property-set-succeeds.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 accessor property of frozen `target` succeeds. | ||
info: | | ||
SetIntegrityLevel ( O, level ) | ||
[...] | ||
3. Let status be ? O.[[PreventExtensions]](). | ||
[...] | ||
7. Else, | ||
a. Assert: level is frozen. | ||
b. For each element k of keys, do | ||
i. Let currentDesc be ? O.[[GetOwnProperty]](k). | ||
ii. If currentDesc is not undefined, then | ||
1. If IsAccessorDescriptor(currentDesc) is true, then | ||
a. Let desc be the PropertyDescriptor { [[Configurable]]: false }. | ||
[...] | ||
3. Perform ? DefinePropertyOrThrow(O, k, desc). | ||
8. Return true. | ||
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. | ||
features: [Symbol] | ||
---*/ | ||
|
||
var value1 = 1; | ||
var target1 = { | ||
set foo(val) { value1 = val; }, | ||
}; | ||
|
||
Object.freeze(target1); | ||
Object.assign(target1, { foo: 2 }); | ||
assert.sameValue(value1, 2); | ||
|
||
|
||
var sym = Symbol(); | ||
var value2 = 1; | ||
var target2 = Object.freeze({ | ||
set [sym](val) { value2 = val; }, | ||
}); | ||
|
||
Object.freeze(target2); | ||
Object.assign(target2, { [sym]: 2 }); | ||
assert.sameValue(value2, 2); |
59 changes: 59 additions & 0 deletions
59
test/built-ins/Object/assign/target-is-frozen-data-property-set-throws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 data property of frozen `target` fails with TypeError. | ||
info: | | ||
SetIntegrityLevel ( O, level ) | ||
[...] | ||
3. Let status be ? O.[[PreventExtensions]](). | ||
[...] | ||
7. Else, | ||
a. Assert: level is frozen. | ||
b. For each element k of keys, do | ||
i. Let currentDesc be ? O.[[GetOwnProperty]](k). | ||
ii. If currentDesc is not undefined, then | ||
1. If IsAccessorDescriptor(currentDesc) is true, then | ||
[...] | ||
2. Else, | ||
a. Let desc be the PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }. | ||
3. Perform ? DefinePropertyOrThrow(O, k, desc). | ||
8. Return true. | ||
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 | ||
a. If ownDesc.[[Writable]] is false, return false. | ||
features: [Symbol, Reflect] | ||
---*/ | ||
|
||
var sym = Symbol(); | ||
var target1 = { [sym]: 1 }; | ||
|
||
Object.freeze(target1); | ||
assert.throws(TypeError, function() { | ||
Object.assign(target1, { [sym]: 1 }); | ||
}); | ||
|
||
|
||
var target2 = Object.freeze({ foo: 1 }); | ||
|
||
assert.throws(TypeError, function() { | ||
Object.assign(target2, { foo: 1 }); | ||
}); |