Skip to content

Commit

Permalink
fix(xsnap): supply missing file, line numbers based on sourceURL
Browse files Browse the repository at this point in the history
fixes #2578
  • Loading branch information
dckc committed Aug 29, 2021
1 parent af29c9a commit 796c438
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions packages/xsnap/test/test-err-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const a = () => {b()};
try {
a();
} catch (err) {
send(err.stack);
err.stack;
}
//# sourceURL=/filename.js
Expand All @@ -31,25 +31,30 @@ async function makeWorker() {
const vat = xsnap(opts);

await vat.evaluate(`
const send = it => issueCommand(ArrayBuffer.fromString(JSON.stringify(it)));
globalThis.send = send;
globalThis.handleCommand = bytes => {
const report = {};
const src = String.fromArrayBuffer(bytes);
const it = eval(src);
report.result = ArrayBuffer.fromString(JSON.stringify(it));
return report;
};
`);

return {
async run(js) {
await vat.evaluate(js);
// console.log(opts.messages);
const result = opts.messages.pop();
return JSON.parse(result);
/** @param { string } src */
async run(src) {
const { reply } = await vat.issueStringCommand(src);
return JSON.parse(reply);
},
};
}

test.failing('XS stack traces include file, line numbers', async t => {
test('XS stack traces include file, line numbers', async t => {
const w = await makeWorker();

const x = await w.run('send(1+1)');
const x = await w.run('1+1');
t.is(x, 2);
const stack = await w.run(code);
t.regex(stack, /filename/);
t.log(stack);
t.regex(stack, /filename.js:9/);
});

0 comments on commit 796c438

Please sign in to comment.