Commit 2f55187e authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm][test] Deduplicate assertWasmThrows helper method.

R=clemensh@chromium.org

Change-Id: Ie4f40314eb41957c6983796e43eeefe655458160
Reviewed-on: https://chromium-review.googlesource.com/c/1367806
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58118}
parent 4233ec0f
......@@ -32,6 +32,7 @@
'modules-skip*': [SKIP],
'harmony/modules-skip*': [SKIP],
'regress/modules-skip*': [SKIP],
'wasm/exceptions-utils': [SKIP],
'wasm/wasm-constants': [SKIP],
'wasm/wasm-module-builder': [SKIP],
......
......@@ -6,27 +6,7 @@
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
// TODO(mstarzinger): Duplicated in the exceptions.js file. Dedupe.
function assertWasmThrows(instance, runtime_id, values, code) {
try {
if (typeof code === 'function') {
code();
} else {
eval(code);
}
} catch (e) {
assertInstanceof(e, WebAssembly.RuntimeError);
var e_runtime_id = %GetWasmExceptionId(e, instance);
assertTrue(Number.isInteger(e_runtime_id));
assertEquals(e_runtime_id, runtime_id);
var e_values = %GetWasmExceptionValues(e);
assertArrayEquals(values, e_values);
return; // Success.
}
throw new MjsUnitAssertionError('Did not throw expected <' + runtime_id +
'> with values: ' + values);
}
load("test/mjsunit/wasm/exceptions-utils.js");
// Test the encoding of a thrown exception with a null-ref value.
(function TestThrowRefNull() {
......
......@@ -6,23 +6,7 @@
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
function assertWasmThrows(instance, runtime_id, code) {
try {
if (typeof code === 'function') {
code();
} else {
eval(code);
}
} catch (e) {
assertInstanceof(e, WebAssembly.RuntimeError);
var e_runtime_id = %GetWasmExceptionId(e, instance);
assertTrue(Number.isInteger(e_runtime_id));
assertEquals(e_runtime_id, runtime_id);
return; // Success.
}
throw new MjsUnitAssertionError('Did not throw <' + runtime_id + '>');
}
load("test/mjsunit/wasm/exceptions-utils.js");
// Test that rethrow expressions can target catch blocks.
(function TestRethrowInCatch() {
......@@ -52,8 +36,8 @@ function assertWasmThrows(instance, runtime_id, code) {
]).exportFunc();
let instance = builder.instantiate();
assertWasmThrows(instance, except, () => instance.exports.rethrow0());
assertWasmThrows(instance, except, () => instance.exports.rethrow1(0));
assertWasmThrows(instance, except, [], () => instance.exports.rethrow0());
assertWasmThrows(instance, except, [], () => instance.exports.rethrow1(0));
assertEquals(23, instance.exports.rethrow1(1));
})();
......@@ -85,8 +69,8 @@ function assertWasmThrows(instance, runtime_id, code) {
]).exportFunc();
let instance = builder.instantiate();
assertWasmThrows(instance, except, () => instance.exports.rethrow0());
assertWasmThrows(instance, except, () => instance.exports.rethrow1(0));
assertWasmThrows(instance, except, [], () => instance.exports.rethrow0());
assertWasmThrows(instance, except, [], () => instance.exports.rethrow1(0));
assertEquals(23, instance.exports.rethrow1(1));
})();
......@@ -123,8 +107,8 @@ function assertWasmThrows(instance, runtime_id, code) {
]).exportFunc();
let instance = builder.instantiate();
assertWasmThrows(instance, except1, () => instance.exports.rethrow_nested(0));
assertWasmThrows(instance, except2, () => instance.exports.rethrow_nested(1));
assertWasmThrows(instance, except1, [], () => instance.exports.rethrow_nested(0));
assertWasmThrows(instance, except2, [], () => instance.exports.rethrow_nested(1));
assertEquals(23, instance.exports.rethrow_nested(2));
})();
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
// This file is intended to be loaded by other tests to provide utility methods
// requiring natives syntax (and hence not suited for the mjsunit.js file).
function assertWasmThrows(instance, runtime_id, values, code) {
try {
if (typeof code === 'function') {
code();
} else {
eval(code);
}
} catch (e) {
assertInstanceof(e, WebAssembly.RuntimeError);
var e_runtime_id = %GetWasmExceptionId(e, instance);
assertTrue(Number.isInteger(e_runtime_id));
assertEquals(e_runtime_id, runtime_id);
var e_values = %GetWasmExceptionValues(e);
assertArrayEquals(values, e_values);
return; // Success.
}
throw new MjsUnitAssertionError('Did not throw expected <' + runtime_id +
'> with values: ' + values);
}
......@@ -6,26 +6,7 @@
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
function assertWasmThrows(instance, runtime_id, values, code) {
try {
if (typeof code === 'function') {
code();
} else {
eval(code);
}
} catch (e) {
assertInstanceof(e, WebAssembly.RuntimeError);
var e_runtime_id = %GetWasmExceptionId(e, instance);
assertTrue(Number.isInteger(e_runtime_id));
assertEquals(e_runtime_id, runtime_id);
var e_values = %GetWasmExceptionValues(e);
assertArrayEquals(values, e_values);
return; // Success.
}
throw new MjsUnitAssertionError('Did not throw expected <' + runtime_id +
'> with values: ' + values);
}
load("test/mjsunit/wasm/exceptions-utils.js");
// First we just test that "except_ref" local variables are allowed.
(function TestLocalExceptRef() {
......
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