16457b0ca0
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}
42 lines
1.4 KiB
JavaScript
42 lines
1.4 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 --allow-natives-syntax
|
|
|
|
"use strict";
|
|
|
|
if (this.Worker) {
|
|
|
|
(function TestSharedStructPostMessage() {
|
|
let workerScript =
|
|
`onmessage = function(struct) {
|
|
// Non-atomic write that will be made visible once main thread
|
|
// observes the atomic write below.
|
|
struct.struct_field.payload = 42;
|
|
Atomics.store(struct, "string_field", "worker");
|
|
};
|
|
postMessage("started");`;
|
|
|
|
let worker = new Worker(workerScript, { type: 'string' });
|
|
let started = worker.getMessage();
|
|
assertEquals("started", started);
|
|
|
|
let OuterStruct = new SharedStructType(['string_field', 'struct_field']);
|
|
let InnerStruct = new SharedStructType(['payload']);
|
|
let struct = new OuterStruct();
|
|
struct.struct_field = new InnerStruct();
|
|
struct.string_field = "main";
|
|
assertEquals("main", struct.string_field);
|
|
assertEquals(undefined, struct.struct_field.payload);
|
|
worker.postMessage(struct);
|
|
// Spin until we observe the worker's write of string_field.
|
|
while (Atomics.load(struct, "string_field") !== "worker") {}
|
|
// The non-atomic store write must also be visible.
|
|
assertEquals(42, struct.struct_field.payload);
|
|
|
|
worker.terminate();
|
|
})();
|
|
|
|
}
|