BridgeJS: Add JSTypedArray convenience typealiases as recognized types#9
Draft
krodak wants to merge 1 commit into
Draft
BridgeJS: Add JSTypedArray convenience typealiases as recognized types#9krodak wants to merge 1 commit into
krodak wants to merge 1 commit into
Conversation
Add JSInt8Array, JSUint8Array, JSInt16Array, JSUint16Array, JSInt32Array, JSUint32Array, JSFloat32Array, JSFloat64Array typealiases and pre-seed them in SwiftToSkeleton so BridgeJS recognizes them in @js signatures. Users can now write: @js func processData(_ data: JSUint8Array) -> JSUint8Array Generated TypeScript uses native typed array names: processData(data: Uint8Array): Uint8Array Bridging is reference-based (passes JSObject ID, no data copying). Follows the existing JSPromise pre-seeding pattern.
315d7be to
87d9404
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Add
JSTypedArray<T>as a recognized BridgeJS type, so users can use typed arrays directly in@JSfunction signatures. Both the generic form and convenience typealiases are supported:Both generate identical TypeScript:
Bridging is reference-based — passes the JSObject ID across the boundary with no data copying. The TypedArray lives on the JS heap.
This complements the separate numeric array optimization PR (#8) which makes
[Int]/[Double]faster internally while keepingnumber[]in TypeScript. This PR gives users the option to use actual TypedArray types when they need them (e.g., forfetchbody, WebGPU).What changed
JSTypedArray.swift— 8 convenience typealiases:JSInt8Array,JSUint8Array,JSInt16Array,JSUint16Array,JSInt32Array,JSUint32Array,JSFloat32Array,JSFloat64ArraySwiftToSkeleton.swift— Pre-seed typed array types in the type resolver (same pattern asJSPromise). RecognizeJSTypedArray<T>generic form and map to the corresponding typealias.BridgeJSLink.swift— Map Swift typealias names to JS TypedArray constructor names intsType(e.g.,JSUint8Array→Uint8Array)JSTypedArrayTypes.swifttest input covering both typealias and generic formsType mapping
JSTypedArray<Int8>/JSInt8ArrayInt8ArrayJSTypedArray<UInt8>/JSUint8ArrayUint8ArrayJSTypedArray<Int16>/JSInt16ArrayInt16ArrayJSTypedArray<UInt16>/JSUint16ArrayUint16ArrayJSTypedArray<Int32>/JSInt32ArrayInt32ArrayJSTypedArray<UInt32>/JSUint32ArrayUint32ArrayJSTypedArray<Float>/JSFloat32ArrayFloat32ArrayJSTypedArray<Double>/JSFloat64ArrayFloat64Array