v8/test/mjsunit/shared-memory/shared-array-workers.js
Luis Fernando Pardo Sixtos afb26623df [shared-struct] Shared Array Initial prototype
Initial implementation for concurrent shared arrays. Current implementation exposes a `SharedArray` constructor, but its syntax might
change in the future.

Shared arrays can be shared across Isolates, have a fixed size, have no
prototype, have no constructor, and can only store primitives, shared structs and other shared arrays. With this CL shared structs are also allowed to store shared arrays.

The Backing storage for the SharedArrays is a `FixedArrayBase`. This CL introdces a new ElementKind: `SHARED_ARRAY_ELEMENTS`. The new kind should match the overall functionality of the `PACKED_SEALED_ELEMENTS` kind, but having it as standalone kind allows for easier branching in CSA and turbofan code.

Bug: v8:12547
Change-Id: I054a04624d4cf1f37bc26ae4b92b6fe33408538a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3585353
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Luis Fernando Pardo Sixtos <lpardosixtos@microsoft.com>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81285}
2022-06-22 02:24:46 +00:00

42 lines
1.2 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 TestSharedArrayPostMessage() {
let workerScript = `onmessage = function(arr) {
arr[0][0] = 42;
arr[1] = "worker";
arr[2].payload = "updated";
postMessage("done");
};
postMessage("started");`;
let worker = new Worker(workerScript, {type: 'string'});
let started = worker.getMessage();
assertEquals('started', started);
let outer_arr = new SharedArray(3);
outer_arr[0] = new SharedArray(1);
outer_arr[1] = 'main';
let Struct = new SharedStructType(['payload']);
let struct = new Struct();
struct.payload = 'original';
outer_arr[2] = struct;
assertEquals('main', outer_arr[1]);
assertEquals(undefined, outer_arr[0][0]);
worker.postMessage(outer_arr);
assertEquals('done', worker.getMessage());
assertEquals('worker', outer_arr[1]);
assertEquals(42, outer_arr[0][0]);
assertEquals('updated', outer_arr[2].payload);
worker.terminate();
})();
}