v8/test/mjsunit/wasm/origin-trial-flags.js
Andreas Haas 1408e12772 [wasm] Check the isolate if WebAssembly threads are enabled.
With the origin trial for WebAssembly threads, threads can be turned on
and off by the embedder depending on the context we are currently in.
With this CL we call the embedder callback stored on the isolate to
determine whether threads are enabled in the current context or not.

Design decision:
I decided to extend the {WasmFeaturesFromIsolate} function to ask the
embedder if WebAssembly threads are enabled. This is the function which
defines dynamically which features are turned on. It would be awkward
to have two such functions, one which calls the embedder and one which
does not.
A downside is that in WasmJs::Install the embedder does not seem to be
ready to be called. That's why I changed the code there to call
{WasmFeaturesFromFlags} instead.

R=titzer@chromium.org, mstarzinger@chromium.org

Bug: chromium:868844
Change-Id: I6bfa89960a54cec71992756e3717bbb3a9fe195e
Reviewed-on: https://chromium-review.googlesource.com/1169180
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: Ben Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55076}
2018-08-13 09:16:33 +00:00

36 lines
1.1 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: --noexperimental-wasm-threads --allow-natives-syntax
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
function instantiateModuleWithThreads() {
// Build a WebAssembly module which uses threads-features.
const builder = new WasmModuleBuilder();
const shared = true;
builder.addMemory(2, 10, false, shared);
builder.addFunction('main', kSig_i_ii)
.addBody([
kExprGetLocal, 0, kExprGetLocal, 1, kAtomicPrefix, kExprI32AtomicAdd, 2,
0
])
.exportFunc();
return builder.instantiate();
}
// Disable WebAssembly threads initially.
%SetWasmThreadsEnabled(false);
assertThrows(instantiateModuleWithThreads, WebAssembly.CompileError);
// Enable WebAssembly threads.
%SetWasmThreadsEnabled(true);
assertInstanceof(instantiateModuleWithThreads(), WebAssembly.Instance);
// Disable WebAssembly threads.
%SetWasmThreadsEnabled(false);
assertThrows(instantiateModuleWithThreads, WebAssembly.CompileError);