Skip to content

Tests, improved ESM support, switch to @jridgewell/trace-mapping, etc #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests and support for wasm stack frames
  • Loading branch information
cspotcode committed May 1, 2022
commit da3e63f2da0cb28ca77a992a19a81455078c4893
6 changes: 6 additions & 0 deletions source-map-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ function wrapCallSite(frame, state) {
// from getScriptNameOrSourceURL() instead
var source = frame.getFileName() || frame.getScriptNameOrSourceURL();
if (source) {
// v8 does not expose its internal isWasm, etc methods, so we do this instead.
if(source.startsWith('wasm://')) {
state.curPosition = null;
return frame;
}

var line = frame.getLineNumber();
var column = frame.getColumnNumber() - 1;

Expand Down
12 changes: 12 additions & 0 deletions test-fixtures/wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
To test support for WASM stack traces, we have a tiny WASM module that we call
into.

It imports a JS function and exports a WASM function
that, when called, will call the JS function.

When we call the wasm function, it calls back into JS. We can throw an error
and know that one of the stack frames will be wasm.

The module is described in both text and binary formats. Compilation from text
to binary format was done using an online tool. I didn't bother to set up a
build script, opting instead ot store the binary in version control.
14 changes: 14 additions & 0 deletions test-fixtures/wasm/wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');
const path = require('path');

exports.call_js_function = async function(fn) {
const mod = await WebAssembly.instantiate(
fs.readFileSync(path.resolve(__dirname, 'wasm.wasm')),
{
jsapi: {
fn
}
}
);
mod.instance.exports.call_js_function();
}
Binary file added test-fixtures/wasm/wasm.wasm
Binary file not shown.
6 changes: 6 additions & 0 deletions test-fixtures/wasm/wasm.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(module
(import "jsapi" "fn" (func $jsapi_fn))
(func (export "call_js_function")
call $jspapi_fn
)
)
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,17 @@ it('async stack frames: Promise.any', async function() {
]);
});

it('wasm stack frames', async function() {
await compareStackTrace(createMultiLineSourceMap(), [
'return require("./test-fixtures/wasm/wasm.js").call_js_function(() => { throw new Error("test"); });'
], [
'Error: test',
re`^ at ${stackFramePathStartsWith()}(?:.*[/\\])?line1.js:1001:101$`,
re`^ at wasm:\/\/wasm\/c2de0ab2:wasm-function\[1\]:0x3b$`,
re`^ at Object\.exports\.call_js_function \(.*[/\\]wasm\.js:13:24\)$`,
]);
});

it('throw with empty source map', async function() {
await compareStackTrace(createEmptySourceMap(), [
'throw new Error("test");'
Expand Down