Shim function that's expected to wrap any invocations of WebAssembly from Go itself. This is used to handle traps and error returns from any invocation of WebAssembly. This will also automatically propagate panics that happen within Go from one end back to this original invocation point. The `stor
(store Storelike, wasm func(**C.wasm_trap_t) *C.wasmtime_error_t)
| 520 | // is the closure which will internally execute WebAssembly. A trap pointer is |
| 521 | // provided to the closure and it's expected that the closure returns an error. |
| 522 | func enterWasm(store Storelike, wasm func(**C.wasm_trap_t) *C.wasmtime_error_t) error { |
| 523 | // Load the internal `storeData` that our `store` references, which is |
| 524 | // used for handling panics which we are going to use here. |
| 525 | data := getDataInStore(store) |
| 526 | |
| 527 | var trap *C.wasm_trap_t |
| 528 | err := wasm(&trap) |
| 529 | |
| 530 | // Take ownership of any returned values to ensure we properly run |
| 531 | // destructors for them. |
| 532 | var wrappedTrap *Trap |
| 533 | var wrappedError error |
| 534 | if trap != nil { |
| 535 | wrappedTrap = mkTrap(trap) |
| 536 | } |
| 537 | if err != nil { |
| 538 | wrappedError = mkError(err) |
| 539 | } |
| 540 | |
| 541 | // Check to see if wasm panicked, and if it did then we need to |
| 542 | // propagate that. Note that this happens after we take ownership of |
| 543 | // return values to ensure they're cleaned up properly. |
| 544 | if data.lastPanic != nil { |
| 545 | lastPanic := data.lastPanic |
| 546 | data.lastPanic = nil |
| 547 | panic(lastPanic) |
| 548 | } |
| 549 | |
| 550 | // If there wasn't a panic then we determine whether to return the trap |
| 551 | // or the error. |
| 552 | if wrappedTrap != nil { |
| 553 | return wrappedTrap |
| 554 | } |
| 555 | return wrappedError |
| 556 | } |
no test coverage detected
searching dependent graphs…