Skip to content
  • Cheng Shao's avatar
    fd40eaa1
    wasm: revamp JSFFI internal implementation and documentation · fd40eaa1
    Cheng Shao authored and Marge Bot's avatar Marge Bot committed
    This patch revamps the wasm backend's JSFFI internal implementation
    and documentation:
    
    - `JSValManager` logic to allocate a key is simplified to simple
      bumping. According to experiments with all major browsers, the
      internal `Map` would overflow the heap much earlier before we really
      exhaust the 32-bit key space, so there's no point in the extra
      complexity.
    - `freeJSVal` is now idempotent and safe to call more than once. This
      is achieved by attaching the `StablePtr#` to the `JSVal#` closure
      and nullifying it when calling `freeJSVal`, so the same stable
      pointer cannot be double freed.
    - `mkWeakJSVal` no longer exposes the internal `Weak#` pointer and
      always creates a new `Weak#` on the fly. Otherwise by finalizing
      that `Weak#`, user could accidentally drop the `JSVal`, but
      `mkWeakJSVal` is only supposed to create a `Weak` that observes the
      `JSVal`'s liveliness without actually interfering it.
    - `PromisePendingException` is no longer exported since it's never
      meant to be caught by user code; it's a severe bug if it's actually
      raised at runtime.
    - Everything exported by user-facing `GHC.Wasm.Prim` now has proper
      haddock documentation.
    - Note [JSVal representation for wasm] has been updated to reflect the
      new JSVal# memory layout.
    fd40eaa1
    wasm: revamp JSFFI internal implementation and documentation
    Cheng Shao authored and Marge Bot's avatar Marge Bot committed
    This patch revamps the wasm backend's JSFFI internal implementation
    and documentation:
    
    - `JSValManager` logic to allocate a key is simplified to simple
      bumping. According to experiments with all major browsers, the
      internal `Map` would overflow the heap much earlier before we really
      exhaust the 32-bit key space, so there's no point in the extra
      complexity.
    - `freeJSVal` is now idempotent and safe to call more than once. This
      is achieved by attaching the `StablePtr#` to the `JSVal#` closure
      and nullifying it when calling `freeJSVal`, so the same stable
      pointer cannot be double freed.
    - `mkWeakJSVal` no longer exposes the internal `Weak#` pointer and
      always creates a new `Weak#` on the fly. Otherwise by finalizing
      that `Weak#`, user could accidentally drop the `JSVal`, but
      `mkWeakJSVal` is only supposed to create a `Weak` that observes the
      `JSVal`'s liveliness without actually interfering it.
    - `PromisePendingException` is no longer exported since it's never
      meant to be caught by user code; it's a severe bug if it's actually
      raised at runtime.
    - Everything exported by user-facing `GHC.Wasm.Prim` now has proper
      haddock documentation.
    - Note [JSVal representation for wasm] has been updated to reflect the
      new JSVal# memory layout.
Loading