1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// 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));
|