Commit 76b53b66 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[api] Add a SharedArrayBuffersEnabled callback.

- Adds a SharedArrayBuffersEnabled callback and uses it to
  enable/disable SABs per context. The feature flag is used
  if no callback is registered.

Bug: chromium:923807
Change-Id: I4d3472fcd79b158cb50dc98793aece6dbbb81d93
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2316901Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69057}
parent b3b42a30
...@@ -7506,6 +7506,9 @@ typedef Local<String> (*WasmLoadSourceMapCallback)(Isolate* isolate, ...@@ -7506,6 +7506,9 @@ typedef Local<String> (*WasmLoadSourceMapCallback)(Isolate* isolate,
// --- Callback for checking if WebAssembly Simd is enabled --- // --- Callback for checking if WebAssembly Simd is enabled ---
typedef bool (*WasmSimdEnabledCallback)(Local<Context> context); typedef bool (*WasmSimdEnabledCallback)(Local<Context> context);
// --- Callback for checking if SharedArrayBuffers are enabled ---
typedef bool (*SharedArrayBuffersEnabledCallback)(Local<Context> context);
// --- Garbage Collection Callbacks --- // --- Garbage Collection Callbacks ---
/** /**
...@@ -9373,6 +9376,9 @@ class V8_EXPORT Isolate { ...@@ -9373,6 +9376,9 @@ class V8_EXPORT Isolate {
void SetWasmSimdEnabledCallback(WasmSimdEnabledCallback callback); void SetWasmSimdEnabledCallback(WasmSimdEnabledCallback callback);
void SetSharedArrayBuffersEnabledCallback(
SharedArrayBuffersEnabledCallback callback);
/** /**
* Check if V8 is dead and therefore unusable. This is the case after * Check if V8 is dead and therefore unusable. This is the case after
* fatal errors such as out-of-memory situations. * fatal errors such as out-of-memory situations.
......
...@@ -8989,6 +8989,10 @@ CALLBACK_SETTER(WasmLoadSourceMapCallback, WasmLoadSourceMapCallback, ...@@ -8989,6 +8989,10 @@ CALLBACK_SETTER(WasmLoadSourceMapCallback, WasmLoadSourceMapCallback,
CALLBACK_SETTER(WasmSimdEnabledCallback, WasmSimdEnabledCallback, CALLBACK_SETTER(WasmSimdEnabledCallback, WasmSimdEnabledCallback,
wasm_simd_enabled_callback) wasm_simd_enabled_callback)
CALLBACK_SETTER(SharedArrayBuffersEnabledCallback,
SharedArrayBuffersEnabledCallback,
shared_array_buffers_enabled_callback)
void Isolate::AddNearHeapLimitCallback(v8::NearHeapLimitCallback callback, void Isolate::AddNearHeapLimitCallback(v8::NearHeapLimitCallback callback,
void* data) { void* data) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
......
...@@ -2634,6 +2634,14 @@ bool Isolate::IsWasmSimdEnabled(Handle<Context> context) { ...@@ -2634,6 +2634,14 @@ bool Isolate::IsWasmSimdEnabled(Handle<Context> context) {
return FLAG_experimental_wasm_simd; return FLAG_experimental_wasm_simd;
} }
bool Isolate::AreSharedArrayBuffersEnabled(Handle<Context> context) {
if (shared_array_buffers_enabled_callback()) {
v8::Local<v8::Context> api_context = v8::Utils::ToLocal(context);
return shared_array_buffers_enabled_callback()(api_context);
}
return FLAG_harmony_sharedarraybuffer;
}
Handle<Context> Isolate::GetIncumbentContext() { Handle<Context> Isolate::GetIncumbentContext() {
JavaScriptFrameIterator it(this); JavaScriptFrameIterator it(this);
......
...@@ -410,6 +410,8 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>; ...@@ -410,6 +410,8 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>;
V(WasmThreadsEnabledCallback, wasm_threads_enabled_callback, nullptr) \ V(WasmThreadsEnabledCallback, wasm_threads_enabled_callback, nullptr) \
V(WasmLoadSourceMapCallback, wasm_load_source_map_callback, nullptr) \ V(WasmLoadSourceMapCallback, wasm_load_source_map_callback, nullptr) \
V(WasmSimdEnabledCallback, wasm_simd_enabled_callback, nullptr) \ V(WasmSimdEnabledCallback, wasm_simd_enabled_callback, nullptr) \
V(SharedArrayBuffersEnabledCallback, shared_array_buffers_enabled_callback, \
nullptr) \
/* State for Relocatable. */ \ /* State for Relocatable. */ \
V(Relocatable*, relocatable_top, nullptr) \ V(Relocatable*, relocatable_top, nullptr) \
V(DebugObjectCache*, string_stream_debug_object_cache, nullptr) \ V(DebugObjectCache*, string_stream_debug_object_cache, nullptr) \
...@@ -634,6 +636,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { ...@@ -634,6 +636,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
bool AreWasmThreadsEnabled(Handle<Context> context); bool AreWasmThreadsEnabled(Handle<Context> context);
bool IsWasmSimdEnabled(Handle<Context> context); bool IsWasmSimdEnabled(Handle<Context> context);
bool AreSharedArrayBuffersEnabled(Handle<Context> context);
THREAD_LOCAL_TOP_ADDRESS(Object, pending_exception) THREAD_LOCAL_TOP_ADDRESS(Object, pending_exception)
......
...@@ -4137,7 +4137,7 @@ void Genesis::InitializeGlobal_harmony_atomics_waitasync() { ...@@ -4137,7 +4137,7 @@ void Genesis::InitializeGlobal_harmony_atomics_waitasync() {
} }
void Genesis::InitializeGlobal_harmony_sharedarraybuffer() { void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
if (!FLAG_harmony_sharedarraybuffer) return; if (!isolate()->AreSharedArrayBuffersEnabled(native_context())) return;
Handle<JSGlobalObject> global(native_context()->global_object(), isolate()); Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment