Commit 5d5ccb6e authored by ahaas's avatar ahaas Committed by Commit bot

[mjsunit] Change assertThrows such that it can check the exception message.

Up until now assertThrows allows to check the type field of an
exception, which is, however, a custom field introduced in a single
regression test. With the change assertThrows allows to check the
message field of an exception, which is set for standard V8 exceptions
by default.

I use the new assertThrows to refactor test/mjsunit/wasm/divrem-trap.js

R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2525313003
Cr-Commit-Position: refs/heads/master@{#41302}
parent a09e5eda
......@@ -376,7 +376,7 @@ var assertMatches;
failWithMessage("invalid use of assertThrows, maybe you want assertThrowsEquals");
}
if (arguments.length >= 3) {
assertEquals(e.type, cause_opt);
assertEquals(e.message, cause_opt);
}
// Success.
return;
......
......@@ -25,6 +25,30 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
assertThrows = function assertThrows(code, type_opt, cause_opt) {
var threwException = true;
try {
if (typeof code === 'function') {
code();
} else {
eval(code);
}
threwException = false;
} catch (e) {
if (typeof type_opt === 'function') {
assertInstanceof(e, type_opt);
} else if (type_opt !== void 0) {
failWithMessage("invalid use of assertThrows, maybe you want assertThrowsEquals");
}
if (arguments.length >= 3) {
assertEquals(e.type, cause_opt);
}
// Success.
return;
}
failWithMessage("Did not throw exception");
};
var obj = { length: { valueOf: function(){ throw { type: "length" }}}};
var sep = { toString: function(){ throw { type: "toString" }}};
assertThrows("Array.prototype.join.call(obj, sep)", undefined, "length");
......@@ -7,26 +7,8 @@
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
function assertTraps(code, msg) {
var threwException = true;
try {
if (typeof code === 'function') {
code();
} else {
eval(code);
}
threwException = false;
} catch (e) {
if (typeof type_opt === 'function') {
assertInstanceof(e, type_opt);
}
if (arguments.length >= 3) {
assertEquals(e.type, cause_opt);
}
// Success.
return;
}
throw new MjsUnitAssertionError("Did not throw exception");
var assertTraps = function(messageId, code) {
assertThrows(code, WebAssembly.RuntimeError, kTrapMsgs[messageId]);
}
......
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