[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/WebAssembly/Reference/JavaScript_interface/Exception/stack [Back]  [Original]

WebAssembly.Exception.prototype.stack - WebAssembly | MDN

MDN Web Docs

View in English Always switch to English

WebAssembly.Exception.prototype.stack

:

WebAssembly.Exception stack

WebAssembly

WebAssembly JavaScript options.trackStack=true

WebAssembly

undefined

WebAssembly URL

${url}:wasm-function[${funcIndex}]:${pcOffset}

WebAssembly

WebAssembly example.wasm $tagname $throwExnWithStack run throwExnWithStack JavaScript

wat
(module
  ;;  $tagname
  (import "extmod" "exttag" (tag $tagname (param i32)))

  ;;  $throwExnWithStack
  (import "extmod" "throwExnWithStack" (func $throwExnWithStack (param i32)))

  ;;  42  $throwExnWithStack
  (func (export "run")
    i32.const 42
    call $throwExnWithStack
  )
)

JavaScript tag throwExceptionWithStack WebAssembly importObject WebAssembly

WebAssembly run() catch

js
const tag = new WebAssembly.Tag({ parameters: ["i32"] });

function throwExceptionWithStack(param) {
  // {traceStack: true}
  throw new WebAssembly.Exception(tag, [param], { traceStack: true });
}

// importObject  WebAssembly import 
const importObject = {
  extmod: {
    exttag: tag,
    throwExnWithStack: throwExceptionWithStack,
  },
};

WebAssembly.instantiateStreaming(fetch("example.wasm"), importObject)
  .then((obj) => {
    console.log(obj.instance.exports.run());
  })
  .catch((e) => {
    console.log(`${e.stack}`);
  });

// 
// throwExceptionWithStack@http://<url>/main.js:76:9
// @http://<url>/example.wasm:wasm-function[3]:0x73
// @http://<url>/main.js:82:38

js
new WebAssembly.Exception(tag, [param], { traceStack: true });

{traceStack: true} WebAssembly WebAssembly.Exception undefined


Web Proxy Viewer  |  New URL  |  Original Page