Skip to content

BridgeJS: Add JSObject and @JSClass struct support for arrays and struct#566

Merged
krodak merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:krodak/jsobject-stack-support
Feb 3, 2026
Merged

BridgeJS: Add JSObject and @JSClass struct support for arrays and struct#566
krodak merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:krodak/jsobject-stack-support

Conversation

@krodak
Copy link
Member

@krodak krodak commented Feb 3, 2026

Overview

Follow-up to array support PR - adds missing support for JSObject and @JSClass struct element types, to address: #543

The implementation for these types already existed in the codebase (@JSClass struct maps to .jsObject internally and shares the same code path), but it was not tested and was not entirely working, so this PR:

  1. Fixes array cleanup behavior to be consistent with non-array JSObject handling
  2. Adds test coverage to verify and document the functionality

Fix

JSObject arrays were incorrectly adding cleanup callbacks that released retained objects. This differed from:

  • Non-array JSObject parameters: No cleanup (retain only)
  • String arrays: Have cleanup because they create TEMPORARY byte arrays that Swift copies from

For JSObjects, we retain the original object reference, not a temporary copy. Swift might return the same object, so cleanup would incorrectly release an object still in use. The fix removes cleanup for JSObject array elements, making them consistent with non-array JSObject handling.

Notes

Let me know if I missed something and we should extend support somehow, but I guess the other improvement would be to support import-side but this is separate issue.

@krodak krodak self-assigned this Feb 3, 2026
@krodak krodak merged commit d35ef58 into swiftwasm:main Feb 3, 2026
11 checks passed
@krodak krodak deleted the krodak/jsobject-stack-support branch February 3, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants