Commit 784055ad authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Extend encoding of references as exception values.

This extends the existing test coverage of interactions between the
exception handling and the reference type proposal. Now "any-func" and
"except-ref" can both be encoded as an exception value. Missing switch
cases have been added.

R=clemensh@chromium.org
TEST=mjsunit/wasm/exceptions-anyref[-interpreter]
BUG=v8:8091,v8:7581

Change-Id: Ie2e9819fe66b4daab623390f27bb19007131f619
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1581600Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60977}
parent 381a7f9e
......@@ -2123,6 +2123,8 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index,
graph()->NewNode(m->I32x4ExtractLane(3), value));
break;
case wasm::kWasmAnyRef:
case wasm::kWasmAnyFunc:
case wasm::kWasmExceptRef:
STORE_FIXED_ARRAY_SLOT_ANY(values_array, index, value);
++index;
break;
......@@ -2255,6 +2257,8 @@ Node** WasmGraphBuilder::GetExceptionValues(
BuildDecodeException32BitValue(values_array, &index));
break;
case wasm::kWasmAnyRef:
case wasm::kWasmAnyFunc:
case wasm::kWasmExceptRef:
value = LOAD_FIXED_ARRAY_SLOT_ANY(values_array, index);
++index;
break;
......
......@@ -260,6 +260,9 @@ struct BlockTypeImmediate {
case kLocalAnyRef:
*result = kWasmAnyRef;
return true;
case kLocalExceptRef:
*result = kWasmExceptRef;
return true;
default:
*result = kWasmVar;
return false;
......
......@@ -2532,7 +2532,9 @@ class ThreadImpl {
EncodeI32ExceptionValue(encoded_values, &encoded_index, s128.val[3]);
break;
}
case kWasmAnyRef: {
case kWasmAnyRef:
case kWasmAnyFunc:
case kWasmExceptRef: {
Handle<Object> anyref = value.to_anyref();
encoded_values->set(encoded_index++, *anyref);
break;
......@@ -2630,7 +2632,9 @@ class ThreadImpl {
value = WasmValue(Simd128(s128));
break;
}
case kWasmAnyRef: {
case kWasmAnyRef:
case kWasmAnyFunc:
case kWasmExceptRef: {
Handle<Object> anyref(encoded_values->get(encoded_index++), isolate_);
value = WasmValue(anyref);
break;
......
......@@ -1860,6 +1860,8 @@ uint32_t WasmExceptionPackage::GetEncodedSize(
encoded_size += 8;
break;
case wasm::kWasmAnyRef:
case wasm::kWasmAnyFunc:
case wasm::kWasmExceptRef:
encoded_size += 1;
break;
default:
......
......@@ -98,3 +98,48 @@ load("test/mjsunit/wasm/exceptions-utils.js");
assertEquals(2.3, instance.exports.throw_catch_param(2.3));
assertEquals("str", instance.exports.throw_catch_param("str"));
})();
// Test throwing/catching a function reference type value.
(function TestThrowCatchAnyFunc() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let except = builder.addException(kSig_v_a);
builder.addFunction("throw_catch_local", kSig_r_v)
.addLocals({anyfunc_count: 1})
.addBody([
kExprTry, kWasmAnyFunc,
kExprGetLocal, 0,
kExprThrow, except,
kExprCatch,
kExprBrOnExn, 0, except,
kExprRethrow,
kExprEnd,
]).exportFunc();
let instance = builder.instantiate();
assertEquals(null, instance.exports.throw_catch_local());
})();
// Test throwing/catching an encapsulated exception type value.
(function TestThrowCatchExceptRef() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let except = builder.addException(kSig_v_e);
builder.addFunction("throw_catch_param", kSig_e_e)
.addBody([
kExprTry, kWasmExceptRef,
kExprGetLocal, 0,
kExprThrow, except,
kExprCatch,
kExprBrOnExn, 0, except,
kExprRethrow,
kExprEnd,
]).exportFunc();
let instance = builder.instantiate();
let e = new Error("my encapsulated error");
assertEquals(e, instance.exports.throw_catch_param(e));
assertEquals(1, instance.exports.throw_catch_param(1));
assertEquals(2.3, instance.exports.throw_catch_param(2.3));
assertEquals("str", instance.exports.throw_catch_param("str"));
})();
......@@ -150,6 +150,7 @@ let kSig_f_d = makeSig([kWasmF64], [kWasmF32]);
let kSig_d_d = makeSig([kWasmF64], [kWasmF64]);
let kSig_r_r = makeSig([kWasmAnyRef], [kWasmAnyRef]);
let kSig_a_a = makeSig([kWasmAnyFunc], [kWasmAnyFunc]);
let kSig_e_e = makeSig([kWasmExceptRef], [kWasmExceptRef]);
let kSig_i_r = makeSig([kWasmAnyRef], [kWasmI32]);
let kSig_v_r = makeSig([kWasmAnyRef], []);
let kSig_v_a = makeSig([kWasmAnyFunc], []);
......
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