Skip to content

Fix example Response.json() this-binding; document how to run it#25

Merged
ikorich merged 1 commit into
mainfrom
fix/example-json-binding
Jun 11, 2026
Merged

Fix example Response.json() this-binding; document how to run it#25
ikorich merged 1 commit into
mainfrom
fix/example-json-binding

Conversation

@ikorich

@ikorich ikorich commented Jun 11, 2026

Copy link
Copy Markdown
Member

Motivation

Asked "can OpenCombineJSExample run on a simulator, or is it unrunnable?" — investigation showed (a) it can never run as a native process (JavaScriptKit's JS bridge is #if __wasm32__; native launch is an immediate SIGABRT), and (b) once actually run in a browser, the example failed every tick: the #8 rewrite called Response.json() unbound → "Illegal invocation".

Changes

  • jsonFn(this: responseObject) — bound call (example + README mirror).
  • README "Running the example": PackageToJS --use-cdn bundle, index.html loader, static serve, opening in a host browser or Safari inside a booted iOS simulator (xcrun simctl openurl).
  • CHANGELOG 0.6.1 section.

Test plan

  • Verified live in Chrome: "received uuid …" ticking every second.
  • Verified live in iOS Simulator (iPhone 16, iOS 26.5) Safari: UUID rendering (screenshot in workspace evidence).
  • swiftformat --lint clean; wasm bundle builds via swift package js --use-cdn.

Fixes #24

The #8 rewrite extracted `responseObject.json.function` and invoked it
unbound, so `this` was undefined and every fetch tick failed in real
browsers with "Illegal invocation". Call it bound via `jsonFn(this:)`.

Verified end-to-end in Chrome and in iOS Simulator Safari via the
PackageToJS `--use-cdn` browser bundle; README gains a "Running the
example" guide (bundle, index.html loader, static serve, simulator
Safari) so the run path is documented.

Fixes #24
@ikorich ikorich added bug Something isn't working documentation Improvements or additions to documentation labels Jun 11, 2026
@ikorich
ikorich merged commit be3b9c6 into main Jun 11, 2026
8 checks passed
@ikorich
ikorich deleted the fix/example-json-binding branch June 12, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Example: Response.json() called without this-binding — Illegal invocation in browser

1 participant