Commit 1b1b4572 authored by Thibaud Michaud's avatar Thibaud Michaud Committed by V8 LUCI CQ

[wasm][eh] Add WebAssembly.Exception.is()

R=jkummerow@chromium.org

Bug: v8:11992
Change-Id: I9fd1eabf70408f6abc4480c999ac26bf5d8ccd8d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3067321
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76096}
parent 6e474ae9
......@@ -2160,6 +2160,30 @@ void WebAssemblyExceptionGetArg(
args.GetReturnValue().Set(result);
}
void WebAssemblyExceptionIs(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
HandleScope scope(isolate);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Exception.is()");
EXTRACT_THIS(exception, WasmExceptionPackage);
if (thrower.error()) return;
auto tag = i::WasmExceptionPackage::GetExceptionTag(i_isolate, exception);
if (tag->IsUndefined()) {
thrower.TypeError("Expected a WebAssembly.Exception object");
return;
}
DCHECK(tag->IsWasmExceptionTag());
auto maybe_tag = GetFirstArgumentAsTag(args, &thrower);
if (thrower.error()) {
return;
}
auto tag_arg = maybe_tag.ToHandleChecked();
args.GetReturnValue().Set(tag_arg->tag() == *tag);
}
void WebAssemblyGlobalGetValueCommon(
const v8::FunctionCallbackInfo<v8::Value>& args, const char* name) {
v8::Isolate* isolate = args.GetIsolate();
......@@ -2623,6 +2647,7 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
isolate);
InstallFunc(isolate, exception_proto, "getArg", WebAssemblyExceptionGetArg,
2);
InstallFunc(isolate, exception_proto, "is", WebAssemblyExceptionIs, 1);
context->set_wasm_exception_constructor(*exception_constructor);
JSFunction::SetInitialMap(isolate, exception_constructor, exception_map,
exception_proto);
......
......@@ -219,3 +219,18 @@ function TestGetArgHelper(types_str, types, values) {
TestGetArgHelper(['externref'], [kWasmExternRef], [{val: 5}]);
TestGetArgHelper(['i32', 'i64', 'f32', 'f64', 'externref'], [kWasmI32, kWasmI64, kWasmF32, kWasmF64, kWasmExternRef], [5, 6n, 7, 8, {val: 9}]);
})();
(function TestExceptionIs() {
print(arguments.callee.name);
let tag1 = new WebAssembly.Tag({parameters: []});
let tag2 = new WebAssembly.Tag({parameters: []});
assertThrows(() => new WebAssembly.Exception({}, []), TypeError,
/Argument 0 must be a WebAssembly tag/);
let exception = new WebAssembly.Exception(tag1, []);
assertTrue(exception.is(tag1));
assertFalse(exception.is(tag2));
assertThrows(() => exception.is.apply({}, tag1), TypeError,
/Expected a WebAssembly.Exception object/);
})();
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