v8/test/mjsunit/shared-memory/shared-struct-atomics.js
Shu-yu Guo 16457b0ca0 [shared-struct] Support shared structs in Atomics.{load,store}
Atomics.load and Atomics.store now accept string field names as the
2nd argument when the 1st argument is a shared struct.

Currently these are implemented in C++ and not yet in CSA.

Bug: v8:12547
Change-Id: Ideeafc13fb6a925540edf3dc17428c8e50bcee79
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3510837
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79431}
2022-03-10 02:23:44 +00:00

36 lines
1.1 KiB
JavaScript

// Copyright 2022 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: --shared-string-table --harmony-struct
"use strict";
let S = new SharedStructType(['field']);
(function TestPrimitivesUsingAtomics() {
// All primitives can be stored in fields.
let s = new S();
for (let prim of [42, -0, undefined, null, true, false, "foo"]) {
Atomics.store(s, 'field', prim);
assertEquals(Atomics.load(s, 'field'), prim);
}
})();
(function TestObjectsUsingAtomics() {
let s = new S();
// Shared objects cannot point to non-shared objects.
assertThrows(() => { Atomics.store(s, 'field', []); });
assertThrows(() => { Atomics.store(s, 'field', {}); });
// Shared objects can point to other shared objects.
let shared_rhs = new S();
Atomics.store(s, 'field', shared_rhs);
assertEquals(Atomics.load(s, 'field'), shared_rhs);
})();
(function TestNotExtensibleUsingAtomics() {
let s = new S();
// Shared structs are non-extensible.
assertThrows(() => { Atomics.store(s, 'nonExistent', 42); });
})();