Commit 42bc23de authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm][exn] Add test for manipulated prototype chain

This adds a test which I suspected would fail, but luckily it doesn't.
The idea is to catch a proper wasm exception in JS, then construct a new
exception, but set the catched exception as the prototype. My suspicion
was that we would still handle that new exception like a wasm exception,
since the `WasmExceptionGetTag` and `WasmExceptionGetValues` runtime
functions to a standard property lookup, which includes a prototype
walk.
Interestingly, the prototype walk is already skipped automatically when
loading private symbols, so the implementation already supports this
case correctly.
Let's still add this test to have coverage for this case.

R=jkummerow@chromium.org
CC=aheejin@chromium.org

Bug: v8:8091
Change-Id: Idf9944cf47f96cca38e9678e9200bf03a39ea126
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2167438Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67391}
parent e1f53bc1
......@@ -182,13 +182,62 @@ load("test/mjsunit/wasm/exceptions-utils.js");
kExprEnd
]).exportFunc();
function throw_exc() {
throw exception = new WebAssembly.RuntimeError('My user text');
throw new WebAssembly.RuntimeError('My user text');
}
let instance = builder.instantiate({imp: {ort: throw_exc}});
assertEquals(11, instance.exports.call_import());
})();
(function TestExnWithWasmProtoNotCaught() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let except = builder.addException(kSig_v_v);
let imp = builder.addImport('imp', 'ort', kSig_v_v);
let throw_fn = builder.addFunction('throw', kSig_v_v)
.addBody([kExprThrow, except])
.exportFunc();
builder.addFunction('test', kSig_v_v)
.addBody([
// Calling "throw" directly should produce the expected exception.
kExprTry, kWasmStmt,
kExprCallFunction, throw_fn.index,
kExprCatch,
kExprBrOnExn, 0, except,
kExprRethrow,
kExprEnd,
// Calling through JS produces a wrapped exceptions which does not match
// the br_on_exn.
kExprTry, kWasmStmt,
kExprCallFunction, imp,
kExprCatch,
kExprBrOnExn, 0, except,
kExprRethrow,
kExprEnd
]).exportFunc();
let instance;
let wrapped_exn;
function js_import() {
try {
instance.exports.throw();
} catch (e) {
wrapped_exn = new Error();
wrapped_exn.__proto__ = e;
throw wrapped_exn;
}
}
instance = builder.instantiate({imp: {ort: js_import}});
let caught = undefined;
try {
instance.exports.test();
} catch (e) {
caught = e;
}
assertTrue(!!caught, 'should have trapped');
assertEquals(caught, wrapped_exn);
assertInstanceof(caught.__proto__, WebAssembly.RuntimeError);
})();
// Test that we can distinguish which exception was thrown by using a cascaded
// sequence of nested try blocks with a single handler in each catch block.
(function TestCatchComplex1() {
......
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