mirror of
https://github.com/tc39/test262.git
synced 2025-07-20 20:44:43 +02:00
Add Object.preventExtensions tests
This commit is contained in:
parent
fd27d1f5d0
commit
83ffa3d911
@ -0,0 +1,50 @@
|
|||||||
|
// 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 non-extensible `target` is successful.
|
||||||
|
info: |
|
||||||
|
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.
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var value1 = 1;
|
||||||
|
var target1 = Object.preventExtensions({
|
||||||
|
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.preventExtensions(target2);
|
||||||
|
Object.assign(target2, { [sym]: 2 });
|
||||||
|
assert.sameValue(value2, 2);
|
@ -0,0 +1,57 @@
|
|||||||
|
// 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 non-extensible `target` is successful.
|
||||||
|
info: |
|
||||||
|
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.
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target1 = Object.preventExtensions({ foo: 1 });
|
||||||
|
|
||||||
|
Object.assign(target1, { foo: 2 });
|
||||||
|
assert.sameValue(target1.foo, 2);
|
||||||
|
|
||||||
|
|
||||||
|
var sym = Symbol();
|
||||||
|
var target2 = { [sym]: 1 };
|
||||||
|
|
||||||
|
Object.preventExtensions(target2);
|
||||||
|
Object.assign(target2, { [sym]: 2 });
|
||||||
|
assert.sameValue(target2[sym], 2);
|
@ -0,0 +1,53 @@
|
|||||||
|
// 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 non-extensible `target` fails with TypeError.
|
||||||
|
info: |
|
||||||
|
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]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target1 = Object.preventExtensions({ foo: 1 });
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.assign(target1, { get bar() {} });
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var target2 = {};
|
||||||
|
|
||||||
|
Object.preventExtensions(target2);
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.assign(target2, { [Symbol()]: 1 });
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user