1+ // NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
2+ // DO NOT EDIT.
3+ //
4+ // To update this file, just rebuild your project or run
5+ // `swift package bridge-js`.
6+
7+ export async function createInstantiator ( options , swift ) {
8+ let instance ;
9+ let memory ;
10+ let setException ;
11+ const textDecoder = new TextDecoder ( "utf-8" ) ;
12+ const textEncoder = new TextEncoder ( "utf-8" ) ;
13+ let tmpRetString ;
14+ let tmpRetBytes ;
15+ let tmpRetException ;
16+ let tmpRetOptionalBool ;
17+ let tmpRetOptionalInt ;
18+ let tmpRetOptionalFloat ;
19+ let tmpRetOptionalDouble ;
20+ let tmpRetOptionalHeapObject ;
21+ let tmpRetTag ;
22+ let tmpRetStrings = [ ] ;
23+ let tmpRetInts = [ ] ;
24+ let tmpRetF32s = [ ] ;
25+ let tmpRetF64s = [ ] ;
26+ let tmpParamInts = [ ] ;
27+ let tmpParamF32s = [ ] ;
28+ let tmpParamF64s = [ ] ;
29+ let tmpRetPointers = [ ] ;
30+ let tmpParamPointers = [ ] ;
31+ let tmpStructCleanups = [ ] ;
32+ const enumHelpers = { } ;
33+ const structHelpers = { } ;
34+
35+ let _exports = null ;
36+ let bjs = null ;
37+ const __bjs_createPointHelpers = ( ) => {
38+ return ( tmpParamInts , tmpParamF32s , tmpParamF64s , tmpParamPointers , tmpRetPointers , textEncoder , swift , enumHelpers ) => ( {
39+ lower : ( value ) => {
40+ tmpParamInts . push ( ( value . x | 0 ) ) ;
41+ tmpParamInts . push ( ( value . y | 0 ) ) ;
42+ return { cleanup : undefined } ;
43+ } ,
44+ raise : ( tmpRetStrings , tmpRetInts , tmpRetF32s , tmpRetF64s , tmpRetPointers ) => {
45+ const int = tmpRetInts . pop ( ) ;
46+ const int1 = tmpRetInts . pop ( ) ;
47+ return { x : int1 , y : int } ;
48+ }
49+ } ) ;
50+ } ;
51+
52+ return {
53+ /**
54+ * @param {WebAssembly.Imports } importObject
55+ */
56+ addImports : ( importObject , importsContext ) => {
57+ bjs = { } ;
58+ importObject [ "bjs" ] = bjs ;
59+ const imports = options . getImports ( importsContext ) ;
60+ bjs [ "swift_js_return_string" ] = function ( ptr , len ) {
61+ const bytes = new Uint8Array ( memory . buffer , ptr , len ) ;
62+ tmpRetString = textDecoder . decode ( bytes ) ;
63+ }
64+ bjs [ "swift_js_init_memory" ] = function ( sourceId , bytesPtr ) {
65+ const source = swift . memory . getObject ( sourceId ) ;
66+ const bytes = new Uint8Array ( memory . buffer , bytesPtr ) ;
67+ bytes . set ( source ) ;
68+ }
69+ bjs [ "swift_js_make_js_string" ] = function ( ptr , len ) {
70+ const bytes = new Uint8Array ( memory . buffer , ptr , len ) ;
71+ return swift . memory . retain ( textDecoder . decode ( bytes ) ) ;
72+ }
73+ bjs [ "swift_js_init_memory_with_result" ] = function ( ptr , len ) {
74+ const target = new Uint8Array ( memory . buffer , ptr , len ) ;
75+ target . set ( tmpRetBytes ) ;
76+ tmpRetBytes = undefined ;
77+ }
78+ bjs [ "swift_js_throw" ] = function ( id ) {
79+ tmpRetException = swift . memory . retainByRef ( id ) ;
80+ }
81+ bjs [ "swift_js_retain" ] = function ( id ) {
82+ return swift . memory . retainByRef ( id ) ;
83+ }
84+ bjs [ "swift_js_release" ] = function ( id ) {
85+ swift . memory . release ( id ) ;
86+ }
87+ bjs [ "swift_js_push_tag" ] = function ( tag ) {
88+ tmpRetTag = tag ;
89+ }
90+ bjs [ "swift_js_push_int" ] = function ( v ) {
91+ tmpRetInts . push ( v | 0 ) ;
92+ }
93+ bjs [ "swift_js_push_f32" ] = function ( v ) {
94+ tmpRetF32s . push ( Math . fround ( v ) ) ;
95+ }
96+ bjs [ "swift_js_push_f64" ] = function ( v ) {
97+ tmpRetF64s . push ( v ) ;
98+ }
99+ bjs [ "swift_js_push_string" ] = function ( ptr , len ) {
100+ const bytes = new Uint8Array ( memory . buffer , ptr , len ) ;
101+ const value = textDecoder . decode ( bytes ) ;
102+ tmpRetStrings . push ( value ) ;
103+ }
104+ bjs [ "swift_js_pop_param_int32" ] = function ( ) {
105+ return tmpParamInts . pop ( ) ;
106+ }
107+ bjs [ "swift_js_pop_param_f32" ] = function ( ) {
108+ return tmpParamF32s . pop ( ) ;
109+ }
110+ bjs [ "swift_js_pop_param_f64" ] = function ( ) {
111+ return tmpParamF64s . pop ( ) ;
112+ }
113+ bjs [ "swift_js_push_pointer" ] = function ( pointer ) {
114+ tmpRetPointers . push ( pointer ) ;
115+ }
116+ bjs [ "swift_js_pop_param_pointer" ] = function ( ) {
117+ return tmpParamPointers . pop ( ) ;
118+ }
119+ bjs [ "swift_js_struct_cleanup" ] = function ( cleanupId ) {
120+ if ( cleanupId === 0 ) { return ; }
121+ const index = ( cleanupId | 0 ) - 1 ;
122+ const cleanup = tmpStructCleanups [ index ] ;
123+ tmpStructCleanups [ index ] = null ;
124+ if ( cleanup ) { cleanup ( ) ; }
125+ while ( tmpStructCleanups . length > 0 && tmpStructCleanups [ tmpStructCleanups . length - 1 ] == null ) {
126+ tmpStructCleanups . pop ( ) ;
127+ }
128+ }
129+ bjs [ "swift_js_struct_lower_Point" ] = function ( objectId ) {
130+ const { cleanup : cleanup } = structHelpers . Point . lower ( swift . memory . getObject ( objectId ) ) ;
131+ if ( cleanup ) {
132+ return tmpStructCleanups . push ( cleanup ) ;
133+ }
134+ return 0 ;
135+ }
136+ bjs [ "swift_js_struct_raise_Point" ] = function ( ) {
137+ const value = structHelpers . Point . raise ( tmpRetStrings , tmpRetInts , tmpRetF32s , tmpRetF64s , tmpRetPointers ) ;
138+ return swift . memory . retain ( value ) ;
139+ }
140+ bjs [ "swift_js_return_optional_bool" ] = function ( isSome , value ) {
141+ if ( isSome === 0 ) {
142+ tmpRetOptionalBool = null ;
143+ } else {
144+ tmpRetOptionalBool = value !== 0 ;
145+ }
146+ }
147+ bjs [ "swift_js_return_optional_int" ] = function ( isSome , value ) {
148+ if ( isSome === 0 ) {
149+ tmpRetOptionalInt = null ;
150+ } else {
151+ tmpRetOptionalInt = value | 0 ;
152+ }
153+ }
154+ bjs [ "swift_js_return_optional_float" ] = function ( isSome , value ) {
155+ if ( isSome === 0 ) {
156+ tmpRetOptionalFloat = null ;
157+ } else {
158+ tmpRetOptionalFloat = Math . fround ( value ) ;
159+ }
160+ }
161+ bjs [ "swift_js_return_optional_double" ] = function ( isSome , value ) {
162+ if ( isSome === 0 ) {
163+ tmpRetOptionalDouble = null ;
164+ } else {
165+ tmpRetOptionalDouble = value ;
166+ }
167+ }
168+ bjs [ "swift_js_return_optional_string" ] = function ( isSome , ptr , len ) {
169+ if ( isSome === 0 ) {
170+ tmpRetString = null ;
171+ } else {
172+ const bytes = new Uint8Array ( memory . buffer , ptr , len ) ;
173+ tmpRetString = textDecoder . decode ( bytes ) ;
174+ }
175+ }
176+ bjs [ "swift_js_return_optional_object" ] = function ( isSome , objectId ) {
177+ if ( isSome === 0 ) {
178+ tmpRetString = null ;
179+ } else {
180+ tmpRetString = swift . memory . getObject ( objectId ) ;
181+ }
182+ }
183+ bjs [ "swift_js_return_optional_heap_object" ] = function ( isSome , pointer ) {
184+ if ( isSome === 0 ) {
185+ tmpRetOptionalHeapObject = null ;
186+ } else {
187+ tmpRetOptionalHeapObject = pointer ;
188+ }
189+ }
190+ bjs [ "swift_js_get_optional_int_presence" ] = function ( ) {
191+ return tmpRetOptionalInt != null ? 1 : 0 ;
192+ }
193+ bjs [ "swift_js_get_optional_int_value" ] = function ( ) {
194+ const value = tmpRetOptionalInt ;
195+ tmpRetOptionalInt = undefined ;
196+ return value ;
197+ }
198+ bjs [ "swift_js_get_optional_string" ] = function ( ) {
199+ const str = tmpRetString ;
200+ tmpRetString = undefined ;
201+ if ( str == null ) {
202+ return - 1 ;
203+ } else {
204+ const bytes = textEncoder . encode ( str ) ;
205+ tmpRetBytes = bytes ;
206+ return bytes . length ;
207+ }
208+ }
209+ bjs [ "swift_js_get_optional_float_presence" ] = function ( ) {
210+ return tmpRetOptionalFloat != null ? 1 : 0 ;
211+ }
212+ bjs [ "swift_js_get_optional_float_value" ] = function ( ) {
213+ const value = tmpRetOptionalFloat ;
214+ tmpRetOptionalFloat = undefined ;
215+ return value ;
216+ }
217+ bjs [ "swift_js_get_optional_double_presence" ] = function ( ) {
218+ return tmpRetOptionalDouble != null ? 1 : 0 ;
219+ }
220+ bjs [ "swift_js_get_optional_double_value" ] = function ( ) {
221+ const value = tmpRetOptionalDouble ;
222+ tmpRetOptionalDouble = undefined ;
223+ return value ;
224+ }
225+ bjs [ "swift_js_get_optional_heap_object_pointer" ] = function ( ) {
226+ const pointer = tmpRetOptionalHeapObject ;
227+ tmpRetOptionalHeapObject = undefined ;
228+ return pointer || 0 ;
229+ }
230+ const TestModule = importObject [ "TestModule" ] = importObject [ "TestModule" ] || { } ;
231+ TestModule [ "bjs_translate" ] = function bjs_translate ( point , dx , dy ) {
232+ try {
233+ const value = swift . memory . getObject ( point ) ;
234+ swift . memory . release ( point ) ;
235+ let ret = imports . translate ( value , dx , dy ) ;
236+ return swift . memory . retain ( ret ) ;
237+ } catch ( error ) {
238+ setException ( error ) ;
239+ }
240+ }
241+ } ,
242+ setInstance : ( i ) => {
243+ instance = i ;
244+ memory = instance . exports . memory ;
245+
246+ setException = ( error ) => {
247+ instance . exports . _swift_js_exception . value = swift . memory . retain ( error )
248+ }
249+ } ,
250+ /** @param {WebAssembly.Instance } instance */
251+ createExports : ( instance ) => {
252+ const js = swift . memory . heap ;
253+ const PointHelpers = __bjs_createPointHelpers ( ) ( tmpParamInts , tmpParamF32s , tmpParamF64s , tmpParamPointers , tmpRetPointers , textEncoder , swift , enumHelpers ) ;
254+ structHelpers . Point = PointHelpers ;
255+
256+ const exports = {
257+ } ;
258+ _exports = exports ;
259+ return exports ;
260+ } ,
261+ }
262+ }
0 commit comments