Commit cd0c116e authored by Manos Koukoutos's avatar Manos Koukoutos Committed by V8 LUCI CQ

[stringrefs][test] Use regexes in error messages

This way we make tests more flexible wrt. future changes, especially
when it comes to module offsets.

Bug: v8:12868
Change-Id: Ie99806603603e5c731c61267469b14f81c88ffac
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3776195Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81846}
parent 3fd930a4
......@@ -9,38 +9,31 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
function assertInvalid(fn, message) {
let builder = new WasmModuleBuilder();
fn(builder);
assertThrows(() => builder.toModule(), WebAssembly.CompileError,
`WebAssembly.Module(): ${message}`);
assertThrows(() => builder.toModule(), WebAssembly.CompileError, message);
}
assertInvalid(
builder => builder.addLiteralStringRef("foo"),
/unexpected section <StringRef> \(enable with --experimental-wasm-stringref\)/);
let enableMessage = 'enable with --experimental-wasm-stringref'
assertInvalid(builder => builder.addLiteralStringRef("foo"),
`unexpected section <StringRef> (${enableMessage}) @+10`);
for (let [name, code] of [['string', kStringRefCode],
['stringview_wtf8', kStringViewWtf8Code],
['stringview_wtf16', kStringViewWtf16Code],
['stringview_iter', kStringViewIterCode]]) {
let message = `invalid value type '${name}ref', ${enableMessage}`;
let message = new RegExp(`invalid value type '${name}ref', ${enableMessage}`);
let default_init = [kExprRefNull, code];
assertInvalid(b => b.addType(makeSig([code], [])),
`${message} @+13`);
assertInvalid(b => b.addStruct([makeField(code, true)]),
`${message} @+13`);
assertInvalid(b => b.addArray(code, true),
`${message} @+12`);
assertInvalid(b => b.addType(makeSig([], [code])),
`${message} @+14`);
assertInvalid(b => b.addGlobal(code, true, default_init),
`${message} @+11`);
assertInvalid(b => b.addTable(code, 0),
`${message} @+11`);
assertInvalid(b => b.addPassiveElementSegment([default_init], code),
`${message} @+12`);
assertInvalid(b => b.addTag(makeSig([code], [])),
`${message} @+13`);
assertInvalid(b => b.addType(makeSig([code], [])), message);
assertInvalid(b => b.addStruct([makeField(code, true)]), message);
assertInvalid(b => b.addArray(code, true), message);
assertInvalid(b => b.addType(makeSig([], [code])), message);
assertInvalid(b => b.addGlobal(code, true, default_init), message);
assertInvalid(b => b.addTable(code, 0), message);
assertInvalid(b => b.addPassiveElementSegment([default_init], code), message);
assertInvalid(b => b.addTag(makeSig([code], [])), message);
assertInvalid(
b => b.addFunction(undefined, kSig_v_v).addLocals(code, 1).addBody([]),
`Compiling function #0 failed: ${message} @+24`);
message);
}
......@@ -17,8 +17,7 @@ function assertValid(fn) {
function assertInvalid(fn, message) {
let builder = new WasmModuleBuilder();
fn(builder);
assertThrows(() => builder.toModule(), WebAssembly.CompileError,
`WebAssembly.Module(): ${message}`);
assertThrows(() => builder.toModule(), WebAssembly.CompileError, message);
}
assertValid(builder => builder.addLiteralStringRef("foo"));
......@@ -334,8 +333,7 @@ assertInvalid(
kGCPrefix, kExprStringConst, 0
]);
},
"Compiling function #0:\"string.const/bad-index\" failed: " +
"Invalid string literal index: 0 @+26");
/Invalid string literal index: 0/);
assertInvalid(
builder => {
......@@ -345,8 +343,7 @@ assertInvalid(
kGCPrefix, kExprStringNewWtf8, 0, kWtf8PolicyAccept
]);
},
"Compiling function #0:\"string.new_wtf8/no-mem\" failed: " +
"memory instruction with no memory @+32");
/memory instruction with no memory/);
assertInvalid(
builder => {
......@@ -357,8 +354,7 @@ assertInvalid(
kGCPrefix, kExprStringNewWtf8, 1, kWtf8PolicyAccept
]);
},
"Compiling function #0:\"string.new_wtf8/bad-mem\" failed: " +
"expected memory index 0, found 1 @+37");
/expected memory index 0, found 1/);
assertInvalid(
builder => {
......@@ -368,8 +364,7 @@ assertInvalid(
kGCPrefix, kExprStringEncodeWtf8, 0, kWtf8PolicyAccept
]);
},
"Compiling function #0:\"string.encode_wtf8/no-mem\" failed: " +
"memory instruction with no memory @+32");
/memory instruction with no memory/);
assertInvalid(
builder => {
......@@ -380,8 +375,7 @@ assertInvalid(
kGCPrefix, kExprStringEncodeWtf8, 1, kWtf8PolicyAccept
]);
},
"Compiling function #0:\"string.encode_wtf8/bad-mem\" failed: " +
"expected memory index 0, found 1 @+37");
/expected memory index 0, found 1/);
assertInvalid(
builder => {
......@@ -392,8 +386,7 @@ assertInvalid(
kGCPrefix, kExprStringEncodeWtf8, 0, 3
]);
},
"Compiling function #0:\"string.encode_wtf8/bad-policy\" failed: " +
"expected wtf8 policy 0, 1, or 2, but found 3 @+38");
/expected wtf8 policy 0, 1, or 2, but found 3/);
assertInvalid(
builder => {
......@@ -403,8 +396,7 @@ assertInvalid(
kGCPrefix, kExprStringMeasureWtf8, 3
]);
},
"Compiling function #0:\"string.measure_wtf8/bad-policy\" failed: " +
"expected wtf8 policy 0, 1, or 2, but found 3 @+29");
/expected wtf8 policy 0, 1, or 2, but found 3/);
assertInvalid(
builder => {
......@@ -417,8 +409,7 @@ assertInvalid(
kGCPrefix, kExprStringNewWtf8Array, 3
]);
},
"Compiling function #0:\"string.new_wtf8_array/bad-policy\" failed: " +
"expected wtf8 policy 0, 1, or 2, but found 3 @+35");
/expected wtf8 policy 0, 1, or 2, but found 3/);
assertInvalid(
builder => {
......@@ -431,9 +422,7 @@ assertInvalid(
kGCPrefix, kExprStringNewWtf8Array, kWtf8PolicyAccept
]);
},
"Compiling function #0:\"string.new_wtf8_array/bad-type\" failed: " +
"string.new_wtf8_array[0] expected array of i8, " +
"found ref.null of type (ref null 0) @+27");
/string.new_wtf8_array\[0\] expected array of i8, found ref.null of type \(ref null 0\)/);
assertInvalid(
builder => {
......@@ -446,9 +435,7 @@ assertInvalid(
kGCPrefix, kExprStringNewWtf16Array
]);
},
"Compiling function #0:\"string.new_wtf16_array/bad-type\" failed: " +
"string.new_wtf16_array[0] expected array of i16, " +
"found ref.null of type (ref null 0) @+27");
/string.new_wtf16_array\[0\] expected array of i16, found ref.null of type \(ref null 0\)/);
assertInvalid(
builder => {
......@@ -465,9 +452,7 @@ assertInvalid(
kGCPrefix, kExprStringEncodeWtf8Array, kWtf8PolicyAccept,
]);
},
"Compiling function #0:\"string.encode_wtf8_array/bad-type\" failed: " +
"string.encode_wtf8_array[1] expected array of mutable i8, " +
"found local.get of type (ref 0) @+33");
/string.encode_wtf8_array\[1\] expected array of mutable i8, found local.get of type \(ref 0\)/);
assertInvalid(
builder => {
......@@ -484,6 +469,4 @@ assertInvalid(
kGCPrefix, kExprStringEncodeWtf16Array,
]);
},
"Compiling function #0:\"string.encode_wtf16_array/bad-type\" failed: " +
"string.encode_wtf16_array[1] expected array of mutable i16, " +
"found local.get of type (ref 0) @+33");
/string.encode_wtf16_array\[1\] expected array of mutable i16, found local.get of type \(ref 0\)/);
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