mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 02:30:33 +00:00

PR-URL: https://github.com/nodejs/node/pull/47251 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
// Copyright 2023 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
//
|
|
// Flags: --harmony-struct
|
|
|
|
// Shared objects have fixed layout and cannot have their properties
|
|
// redefined. They are constructed sealed. In ordinary objects, sealed objects
|
|
// can be redefined to be frozen. This is disallowed for shared objects.
|
|
|
|
function TestSharedObjectCannotRedefineProperty(sharedObj) {
|
|
function TestRedefine(sharedObj, propName) {
|
|
if (Object.hasOwn(sharedObj, propName)) {
|
|
assertThrows(() => Object.defineProperty(sharedObj, propName, {
|
|
value: 99,
|
|
enumerable: true,
|
|
writable: false,
|
|
configurable: false
|
|
}));
|
|
Object.defineProperty(
|
|
sharedObj, propName,
|
|
{value: 99, enumerable: true, writable: true, configurable: false});
|
|
assertEquals(99, sharedObj[propName]);
|
|
}
|
|
}
|
|
|
|
TestRedefine(sharedObj, 'p');
|
|
TestRedefine(sharedObj, '0');
|
|
// Objects without any properties are a degenerate case and are considered
|
|
// frozen (or any integrity level, really).
|
|
if (Object.getOwnPropertyNames(sharedObj).length > 0) {
|
|
assertThrows(() => Object.freeze(sharedObj));
|
|
}
|
|
assertTrue(Object.isSealed(sharedObj));
|
|
}
|
|
|
|
TestSharedObjectCannotRedefineProperty(new Atomics.Condition());
|
|
TestSharedObjectCannotRedefineProperty(new Atomics.Mutex());
|
|
TestSharedObjectCannotRedefineProperty(new (new SharedStructType(['p'])));
|
|
TestSharedObjectCannotRedefineProperty(new SharedArray(1));
|