[wasm] Fix test utils and tests
Add a check to appendToTable to catch illegal input, and fix a test case triggering this check. Also removing unused variables and fix indentation. R=ahaas@chromium.org Change-Id: I0eaa48ab95ef710530a3cfbe94ed4dd419618cda Reviewed-on: https://chromium-review.googlesource.com/458436 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Andreas Haas <ahaas@chromium.org> Cr-Commit-Position: refs/heads/master@{#44027}
This commit is contained in:
parent
1fe5f0e3ad
commit
ee64674811
@ -406,19 +406,18 @@ var failWithMessage;
|
||||
|
||||
|
||||
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");
|
||||
failWithMessage(
|
||||
'invalid use of assertThrows, maybe you want assertThrowsEquals');
|
||||
}
|
||||
if (arguments.length >= 3) {
|
||||
assertEquals(e.message, cause_opt);
|
||||
@ -426,7 +425,7 @@ var failWithMessage;
|
||||
// Success.
|
||||
return;
|
||||
}
|
||||
failWithMessage("Did not throw exception");
|
||||
failWithMessage('Did not throw exception');
|
||||
};
|
||||
|
||||
|
||||
|
@ -74,7 +74,7 @@ module = (function () {
|
||||
kExprCallIndirect, sig_i_ii, kTableZero
|
||||
])
|
||||
.exportFunc();
|
||||
builder.appendToTable([mul.index, add.index, popcnt.index, main.index]);
|
||||
builder.appendToTable([mul, add.index, popcnt.index, main.index]);
|
||||
|
||||
return builder.instantiate({q: {mul: function(a, b) { return a * b | 0; }}});
|
||||
})();
|
||||
|
@ -339,36 +339,34 @@ let kTrapMsgs = [
|
||||
];
|
||||
|
||||
function assertTraps(trap, code) {
|
||||
var threwException = true;
|
||||
try {
|
||||
if (typeof code === 'function') {
|
||||
code();
|
||||
} else {
|
||||
eval(code);
|
||||
}
|
||||
threwException = false;
|
||||
} catch (e) {
|
||||
assertEquals("object", typeof e);
|
||||
assertEquals(kTrapMsgs[trap], e.message);
|
||||
// Success.
|
||||
return;
|
||||
try {
|
||||
if (typeof code === 'function') {
|
||||
code();
|
||||
} else {
|
||||
eval(code);
|
||||
}
|
||||
throw new MjsUnitAssertionError("Did not trap, expected: " + kTrapMsgs[trap]);
|
||||
} catch (e) {
|
||||
assertEquals('object', typeof e);
|
||||
assertEquals(kTrapMsgs[trap], e.message);
|
||||
// Success.
|
||||
return;
|
||||
}
|
||||
throw new MjsUnitAssertionError('Did not trap, expected: ' + kTrapMsgs[trap]);
|
||||
}
|
||||
|
||||
function assertWasmThrows(value, code) {
|
||||
assertEquals("number", typeof(value));
|
||||
try {
|
||||
if (typeof code === 'function') {
|
||||
code();
|
||||
} else {
|
||||
eval(code);
|
||||
}
|
||||
} catch (e) {
|
||||
assertEquals("number", typeof e);
|
||||
assertEquals(value, e);
|
||||
// Success.
|
||||
return;
|
||||
assertEquals('number', typeof value);
|
||||
try {
|
||||
if (typeof code === 'function') {
|
||||
code();
|
||||
} else {
|
||||
eval(code);
|
||||
}
|
||||
throw new MjsUnitAssertionError("Did not throw at all, expected: " + value);
|
||||
} catch (e) {
|
||||
assertEquals('number', typeof e);
|
||||
assertEquals(value, e);
|
||||
// Success.
|
||||
return;
|
||||
}
|
||||
throw new MjsUnitAssertionError('Did not throw, expected: ' + value);
|
||||
}
|
||||
|
@ -98,7 +98,8 @@ class WasmFunctionBuilder {
|
||||
|
||||
addBody(body) {
|
||||
for (let b of body) {
|
||||
if (typeof b != 'number') throw new Error('invalid body: ' + body);
|
||||
if (typeof b != 'number')
|
||||
throw new Error('invalid body (entries have to be numbers): ' + body);
|
||||
}
|
||||
this.body = body;
|
||||
// Automatically add the end for the function block to the body.
|
||||
@ -264,6 +265,10 @@ class WasmModuleBuilder {
|
||||
}
|
||||
|
||||
appendToTable(array) {
|
||||
for (let n of array) {
|
||||
if (typeof n != 'number')
|
||||
throw new Error('invalid table (entries have to be numbers): ' + array);
|
||||
}
|
||||
return this.addFunctionTableInit(this.function_table.length, false, array);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user