mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 07:45:30 +00:00
Bug 1709358 - [devtools] Handle wasm parser errors r=jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D115578
This commit is contained in:
parent
cdb6c6cca0
commit
7261bca63f
@ -20,6 +20,16 @@ describe("wasm", () => {
|
||||
"\x03\x82\x80\x80\x80\x00\x01\x00\x06\x81\x80\x80\x80\x00\x00" +
|
||||
"\n\x89\x80\x80\x80\x00\x01\x83\x80\x80\x80\x00\x00\x01\v",
|
||||
};
|
||||
|
||||
// malformed binary which contains an unknown operator (\x09) which
|
||||
// should cause the wasm parser to throw.
|
||||
const MALFORMED_SIMPLE_WASM = {
|
||||
binary:
|
||||
"\x00asm\x01\x00\x00\x00\x09\x84\x80\x80\x80\x00\x01`\x00\x00" +
|
||||
"\x03\x82\x80\x80\x80\x00\x01\x00\x06\x81\x80\x80\x80\x00\x00" +
|
||||
"\n\x89\x80\x80\x80\x00\x01\x83\x80\x80\x80\x00\x00\x01\v",
|
||||
};
|
||||
|
||||
const SIMPLE_WASM_TEXT = `(module
|
||||
(func $func0
|
||||
nop
|
||||
@ -50,6 +60,15 @@ describe("wasm", () => {
|
||||
expect(lines.join("\n")).toEqual(SIMPLE_WASM_TEXT);
|
||||
clearWasmStates();
|
||||
});
|
||||
|
||||
it("should return error information when the parser throws", () => {
|
||||
const source = makeMockWasmSourceWithContent(MALFORMED_SIMPLE_WASM);
|
||||
const lines = renderWasmText(source.id, source.content.value);
|
||||
expect(lines.join("\n")).toEqual(
|
||||
"Error occured during wast conversion : Unknown operator: 6"
|
||||
);
|
||||
clearWasmStates();
|
||||
});
|
||||
});
|
||||
|
||||
describe("lineToWasmOffset", () => {
|
||||
|
@ -32,16 +32,25 @@ function maybeWasmSectionNameResolver(data) {
|
||||
export function getWasmText(sourceId, data) {
|
||||
const nameResolver = maybeWasmSectionNameResolver(data);
|
||||
const parser = new BinaryReader();
|
||||
let result;
|
||||
parser.setData(data.buffer, 0, data.length);
|
||||
const dis = new WasmDisassembler();
|
||||
if (nameResolver) {
|
||||
dis.nameResolver = nameResolver;
|
||||
}
|
||||
dis.addOffsets = true;
|
||||
const done = dis.disassembleChunk(parser);
|
||||
let result = dis.getResult();
|
||||
if (result.lines.length === 0) {
|
||||
result = { lines: ["No luck with wast conversion"], offsets: [0], done };
|
||||
try {
|
||||
const done = dis.disassembleChunk(parser);
|
||||
result = dis.getResult();
|
||||
if (result.lines.length === 0) {
|
||||
result = { lines: ["No luck with wast conversion"], offsets: [0], done };
|
||||
}
|
||||
} catch (e) {
|
||||
result = {
|
||||
lines: [`Error occured during wast conversion : ${e.message}`],
|
||||
offsets: [0],
|
||||
done: null,
|
||||
};
|
||||
}
|
||||
|
||||
const { offsets } = result;
|
||||
|
Loading…
Reference in New Issue
Block a user