Tags: swiftwasm/JavaScriptKit
Tags
[BridgeJS] Synthesize typed-closure init access from declaration surf… …ace (#709) (#727) * [BridgeJS] Synthesize typed-closure init access from declaration surface Resolves #709: a public `@JSClass` exposing a `JSTypedClosure<...>` parameter could not be consumed from another target because the synthesized `extension JSTypedClosure { init(...) }` was always internal, leaving downstream callers no way to construct the closure value without hand-rolling a public wrapper. Imported skeleton entries now record the source access level (`public`/`package`/`internal`); the closure-signature collector takes the maximum across every surface that references a given signature, and `ClosureCodegen` prefixes the synthesized init with the resulting modifier (internal stays bare). This matches the pattern `JSClassMacro` already uses for `init(unsafelyWrapping:)`. * [BridgeJS] Address PR feedback and refresh generated artifacts - Make `accessLevel` decode-tolerant on imported skeleton structs (`ImportedFunctionSkeleton`, `ImportedConstructorSkeleton`, `ImportedGetterSkeleton`, `ImportedSetterSkeleton`, `ImportedTypeSkeleton`) by writing explicit `init(from:)` decoders that fall back to `.internal` when the key is missing. Without this, any pre-existing skeleton JSON without the new field fails decoding — the `build-examples` CI job hit `DecodingError.keyNotFound` for `accessLevel` against externally consumed skeletons. - Extract a private `recordSignature` helper so `visitClosure` and `recordInjectedSignature` share a single merge implementation. - Assert in `withAccessLevel(rawLevel:)` so unknown access strings ("open", "private", future schema additions) surface in debug builds instead of silently inheriting the outer level. - Document the `.internal` seeding assumption on `ClosureSignatureCollectorVisitor.init(moduleName:signatures:)`. - Regenerate the BridgeJS pre-generated artifacts under Benchmarks/, Examples/PlayBridgeJS/, Tests/BridgeJSIdentityTests/, and Tests/BridgeJSRuntimeTests/ via `./Utilities/bridge-js-generate.sh`, per CONTRIBUTING.md. The runtime-tests Swift output now emits `public init` on three `JSTypedClosure` extensions whose signatures surface through public exported types. * [BridgeJS] Refresh identity tests skeleton after merge with main #731 added the GC lifecycle test (with new imported function entries) to main while this branch was open. Re-running the BridgeJS regen against the merged tree fills in the `accessLevel` field on the new entries that were absent at merge time. * ci: retry flaky JSPromiseTests.testPromiseAndTimer
Add JSRemote<JSObject> (#711) Add `JSRemote<JSObject>` API for accessing JSObjects without transfer The new API allows creating a handle for a `JSObject` that remains on its original JavaScript thread and hopping back to that thread to access the object when needed. This is useful for cases where the object cannot be transferred to another thread, but occasional access is still required or when we want to guarantee that an object is always accessed on the same thread for safety (it should be statically guaranteed with strict Sendable checking, but modules with language mode 5 don't have that). Example: ```swift let document = JSObject.global.document.object! let remoteDocument = JSRemote(document) let executor = try await WebWorkerTaskExecutor(numberOfThreads: 1) let title = try await Task(executorPreference: executor) { try await remoteDocument.withJSObject { document in document.title.string ?? "" } }.value ```
BridgeJS: support imports of JS `Promise` as `async` Swift (#707) * BridgeJS: support imports of `Promise` JS as `async` Swift * E2e testing of bridging Promise<interface> returns * fix formatting * `JSTypedClosure`-based approach * Clean up `BridgeJSLink` * Fix missing `import _Concurrency` * Fix formatting * Use `JSTypedClosure` without wrapping the result value * Make closure parameters as `sending` * Check more stack ABI types * Add support for `async` in `@JSFunction` * Use namespaced import * Fix missing `fetchWeatherData` * Bring back `fetchWeatherData` * Regenerate `fetchWeatherData` bridging code * BridgeJS: Centralize closure sig collection in BridgeSkeletonWalker * BridgeJS: Stop spreading isAsync handling outside of CallJSEmission * BridgeJS: Remove error-prone default effects in thunk generation * BridgeJSLink: Centralize async handling in ImportedThunkBuilder * BridgeJS: Remove reundant returnType from `call` family of methods in ImportedThunkBuilder --------- Co-authored-by: Yuta Saito <[email protected]>
PreviousNext