Commit 4c9d7ff9 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[api] Add API callback setter for the wasm exceptions origin trial

The implementation is similar to the callbacks that already exist for
the origin trial for WebAssembly simd.

Bug: v8:8091
Change-Id: I969b68c209ea62cf70dbaf317616300b782b5e14
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2672020Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72628}
parent 44116f70
......@@ -7750,6 +7750,9 @@ using WasmLoadSourceMapCallback = Local<String> (*)(Isolate* isolate,
// --- Callback for checking if WebAssembly Simd is enabled ---
using WasmSimdEnabledCallback = bool (*)(Local<Context> context);
// --- Callback for checking if WebAssembly exceptions are enabled ---
using WasmExceptionsEnabledCallback = bool (*)(Local<Context> context);
// --- Garbage Collection Callbacks ---
/**
......@@ -9652,6 +9655,8 @@ class V8_EXPORT Isolate {
void SetWasmSimdEnabledCallback(WasmSimdEnabledCallback callback);
void SetWasmExceptionsEnabledCallback(WasmExceptionsEnabledCallback callback);
/**
* Check if V8 is dead and therefore unusable. This is the case after
* fatal errors such as out-of-memory situations.
......
......@@ -9053,6 +9053,9 @@ CALLBACK_SETTER(WasmLoadSourceMapCallback, WasmLoadSourceMapCallback,
CALLBACK_SETTER(WasmSimdEnabledCallback, WasmSimdEnabledCallback,
wasm_simd_enabled_callback)
CALLBACK_SETTER(WasmExceptionsEnabledCallback, WasmExceptionsEnabledCallback,
wasm_exceptions_enabled_callback)
void Isolate::AddNearHeapLimitCallback(v8::NearHeapLimitCallback callback,
void* data) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
......
......@@ -2613,6 +2613,14 @@ bool Isolate::IsWasmSimdEnabled(Handle<Context> context) {
return FLAG_experimental_wasm_simd;
}
bool Isolate::AreWasmExceptionsEnabled(Handle<Context> context) {
if (wasm_exceptions_enabled_callback()) {
v8::Local<v8::Context> api_context = v8::Utils::ToLocal(context);
return wasm_exceptions_enabled_callback()(api_context);
}
return FLAG_experimental_wasm_eh;
}
Handle<Context> Isolate::GetIncumbentContext() {
JavaScriptFrameIterator it(this);
......
......@@ -433,6 +433,7 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>;
V(WasmThreadsEnabledCallback, wasm_threads_enabled_callback, nullptr) \
V(WasmLoadSourceMapCallback, wasm_load_source_map_callback, nullptr) \
V(WasmSimdEnabledCallback, wasm_simd_enabled_callback, nullptr) \
V(WasmExceptionsEnabledCallback, wasm_exceptions_enabled_callback, nullptr) \
/* State for Relocatable. */ \
V(Relocatable*, relocatable_top, nullptr) \
V(DebugObjectCache*, string_stream_debug_object_cache, nullptr) \
......@@ -672,6 +673,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
bool AreWasmThreadsEnabled(Handle<Context> context);
bool IsWasmSimdEnabled(Handle<Context> context);
bool AreWasmExceptionsEnabled(Handle<Context> context);
THREAD_LOCAL_TOP_ADDRESS(Object, pending_exception)
......
......@@ -30,6 +30,9 @@ WasmFeatures WasmFeatures::FromIsolate(Isolate* isolate) {
if (isolate->IsWasmSimdEnabled(handle(isolate->context(), isolate))) {
features.Add(kFeature_simd);
}
if (isolate->AreWasmExceptionsEnabled(handle(isolate->context(), isolate))) {
features.Add(kFeature_eh);
}
return features;
}
......
......@@ -131,6 +131,7 @@ namespace {
bool wasm_threads_enabled_value = false;
bool wasm_simd_enabled_value = false;
bool wasm_exceptions_enabled_value = false;
bool MockWasmThreadsEnabledCallback(v8::Local<v8::Context>) {
return wasm_threads_enabled_value;
......@@ -140,6 +141,10 @@ bool MockWasmSimdEnabledCallback(v8::Local<v8::Context>) {
return wasm_simd_enabled_value;
}
bool MockWasmExceptionsEnabledCallback(v8::Local<v8::Context>) {
return wasm_exceptions_enabled_value;
}
} // namespace
TEST(TestSetWasmThreadsEnabledCallback) {
......@@ -199,3 +204,32 @@ TEST(TestSetWasmSimdEnabledCallback) {
i::FLAG_experimental_wasm_simd = false;
CHECK(i_isolate->IsWasmSimdEnabled(i_context));
}
TEST(TestSetWasmExceptionsEnabledCallback) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
i::Handle<i::Context> i_context = v8::Utils::OpenHandle(*context);
// {Isolate::AreWasmExceptionsEnabled} calls the callback set by the embedder
// if such a callback exists. Otherwise it returns
// {FLAG_experimental_wasm_eh}. First we test that the flag is returned
// correctly if no callback is set. Then we test that the flag is ignored if
// the callback is set.
i::FLAG_experimental_wasm_eh = false;
CHECK(!i_isolate->AreWasmExceptionsEnabled(i_context));
i::FLAG_experimental_wasm_eh = true;
CHECK(i_isolate->AreWasmExceptionsEnabled(i_context));
isolate->SetWasmExceptionsEnabledCallback(MockWasmExceptionsEnabledCallback);
wasm_exceptions_enabled_value = false;
CHECK(!i_isolate->AreWasmExceptionsEnabled(i_context));
wasm_exceptions_enabled_value = true;
i::FLAG_experimental_wasm_eh = false;
CHECK(i_isolate->AreWasmExceptionsEnabled(i_context));
}
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