Skip to content

Commit da3e63f

Browse files
committed
add tests and support for wasm stack frames
1 parent 727cbe6 commit da3e63f

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

source-map-support.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,12 @@ function wrapCallSite(frame, state) {
520520
// from getScriptNameOrSourceURL() instead
521521
var source = frame.getFileName() || frame.getScriptNameOrSourceURL();
522522
if (source) {
523+
// v8 does not expose its internal isWasm, etc methods, so we do this instead.
524+
if(source.startsWith('wasm://')) {
525+
state.curPosition = null;
526+
return frame;
527+
}
528+
523529
var line = frame.getLineNumber();
524530
var column = frame.getColumnNumber() - 1;
525531

test-fixtures/wasm/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
To test support for WASM stack traces, we have a tiny WASM module that we call
2+
into.
3+
4+
It imports a JS function and exports a WASM function
5+
that, when called, will call the JS function.
6+
7+
When we call the wasm function, it calls back into JS. We can throw an error
8+
and know that one of the stack frames will be wasm.
9+
10+
The module is described in both text and binary formats. Compilation from text
11+
to binary format was done using an online tool. I didn't bother to set up a
12+
build script, opting instead ot store the binary in version control.

test-fixtures/wasm/wasm.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
exports.call_js_function = async function(fn) {
5+
const mod = await WebAssembly.instantiate(
6+
fs.readFileSync(path.resolve(__dirname, 'wasm.wasm')),
7+
{
8+
jsapi: {
9+
fn
10+
}
11+
}
12+
);
13+
mod.instance.exports.call_js_function();
14+
}

test-fixtures/wasm/wasm.wasm

89 Bytes
Binary file not shown.

test-fixtures/wasm/wasm.wat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(module
2+
(import "jsapi" "fn" (func $jsapi_fn))
3+
(func (export "call_js_function")
4+
call $jspapi_fn
5+
)
6+
)

test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,17 @@ it('async stack frames: Promise.any', async function() {
526526
]);
527527
});
528528

529+
it('wasm stack frames', async function() {
530+
await compareStackTrace(createMultiLineSourceMap(), [
531+
'return require("./test-fixtures/wasm/wasm.js").call_js_function(() => { throw new Error("test"); });'
532+
], [
533+
'Error: test',
534+
re`^ at ${stackFramePathStartsWith()}(?:.*[/\\])?line1.js:1001:101$`,
535+
re`^ at wasm:\/\/wasm\/c2de0ab2:wasm-function\[1\]:0x3b$`,
536+
re`^ at Object\.exports\.call_js_function \(.*[/\\]wasm\.js:13:24\)$`,
537+
]);
538+
});
539+
529540
it('throw with empty source map', async function() {
530541
await compareStackTrace(createEmptySourceMap(), [
531542
'throw new Error("test");'

0 commit comments

Comments
 (0)