@@ -327,21 +327,51 @@ impl<T> Store<T> {
327
327
inner. limiter = Some ( Box :: new ( limiter) ) ;
328
328
}
329
329
330
- /// Configure a function that runs each time WebAssembly code running on this [`Store`] calls
331
- /// into native code .
330
+ /// Configure a function that runs each time the host resumes execution from
331
+ /// WebAssembly .
332
332
///
333
- /// This function may return a [`Trap`], which terminates execution.
333
+ /// This hook is called in two circumstances:
334
+ ///
335
+ /// * When WebAssembly calls a function defined by the host, this hook is
336
+ /// called before other host code runs.
337
+ /// * When WebAssembly returns back to the host after being called, this
338
+ /// hook is called.
339
+ ///
340
+ /// This method can be used with [`Store::exiting_native_code_hook`] to track
341
+ /// execution time of WebAssembly, for example, by starting/stopping timers
342
+ /// in the enter/exit hooks.
343
+ ///
344
+ /// This function may return a [`Trap`]. If a trap is returned when an
345
+ /// import was called, it is immediately raised as-if the host import had
346
+ /// returned the trap. If a trap is returned after wasm returns to the host
347
+ /// then the wasm function's result is ignored and this trap is returned
348
+ /// instead.
334
349
pub fn entering_native_code_hook (
335
350
& mut self ,
336
351
hook : impl FnMut ( & mut T ) -> Result < ( ) , Trap > + Send + Sync + ' static ,
337
352
) {
338
353
self . inner . entering_native_hook = Some ( Box :: new ( hook) ) ;
339
354
}
340
355
341
- /// Configure a function that runs before native code running on this [`Store`] returns to
342
- /// WebAssembly code.
356
+ /// Configure a function that runs just before WebAssembly code starts
357
+ /// executing.
358
+ ///
359
+ /// The closure provided is called in two circumstances:
360
+ ///
361
+ /// * When the host calls a WebAssembly function, the hook is called just
362
+ /// before WebAssembly starts executing.
363
+ /// * When a host function returns back to WebAssembly this hook is called
364
+ /// just before the return.
365
+ ///
366
+ /// This method can be used with [`Store::entering_native_code_hook`] to track
367
+ /// execution time of WebAssembly, for example, by starting/stopping timers
368
+ /// in the enter/exit hooks.
343
369
///
344
- /// This function may return a [`Trap`], which terminates execution.
370
+ /// This function may return a [`Trap`]. If a trap is returned when an
371
+ /// imported host function is returning, then the imported host function's
372
+ /// result is ignored and the trap is raised. If a trap is returned when
373
+ /// the host is about to start executing WebAssembly, then no WebAssembly
374
+ /// code is run and the trap is returned instead.
345
375
pub fn exiting_native_code_hook (
346
376
& mut self ,
347
377
hook : impl FnMut ( & mut T ) -> Result < ( ) , Trap > + Send + Sync + ' static ,
0 commit comments