e60edd9505
This is only enabled when --experimental-wasm-threads is enabled. In addition, only shared WebAssembly.Memory may be sent, as specified here: https://github.com/WebAssembly/design/pull/1074/files#diff-8e85308ab5cc1e83e91ef59233648be2R227 Bug: v8:6895 Change-Id: Id009a7f890d15fa6c98e93f03806f7e7eff30c2a Reviewed-on: https://chromium-review.googlesource.com/719417 Commit-Queue: Brad Nelson <bradnelson@chromium.org> Reviewed-by: Deepti Gandluri <gdeepti@chromium.org> Reviewed-by: Brad Nelson <bradnelson@chromium.org> Cr-Commit-Position: refs/heads/master@{#48609}
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
// Copyright 2017 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: --experimental-wasm-threads
|
|
|
|
(function TestPostMessageUnsharedMemory() {
|
|
let worker = new Worker('');
|
|
let memory = new WebAssembly.Memory({initial: 1, maximum: 2});
|
|
|
|
assertThrows(() => worker.postMessage(memory), Error);
|
|
})();
|
|
|
|
(function TestPostMessageSharedMemory() {
|
|
let workerScript =
|
|
`onmessage = function(memory) {
|
|
// Can't use assert in a worker.
|
|
if (!(memory instanceof WebAssembly.Memory)) {
|
|
postMessage("Error: memory is not a WebAssembly.Memory");
|
|
return;
|
|
}
|
|
|
|
if (!(memory.buffer instanceof SharedArrayBuffer)) {
|
|
postMessage("Error: memory.buffer is not a SharedArrayBuffer");
|
|
return;
|
|
}
|
|
|
|
if (memory.buffer.byteLength != 65536) {
|
|
postMessage("Error: memory.buffer.byteLength is not 1 page");
|
|
return;
|
|
}
|
|
|
|
postMessage("OK");
|
|
};`;
|
|
let worker = new Worker(workerScript);
|
|
let memory = new WebAssembly.Memory({initial: 1, maximum: 2, shared: true});
|
|
worker.postMessage(memory);
|
|
assertEquals("OK", worker.getMessage());
|
|
worker.terminate();
|
|
})();
|