forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionals.js
More file actions
749 lines (741 loc) · 36.1 KB
/
Copy pathOptionals.js
File metadata and controls
749 lines (741 loc) · 36.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
// DO NOT EDIT.
//
// To update this file, just rebuild your project or run
// `swift package bridge-js`.
export async function createInstantiator(options, swift) {
let instance;
let memory;
let setException;
const textDecoder = new TextDecoder("utf-8");
const textEncoder = new TextEncoder("utf-8");
let tmpRetString;
let tmpRetBytes;
let tmpRetException;
let tmpRetOptionalBool;
let tmpRetOptionalInt;
let tmpRetOptionalFloat;
let tmpRetOptionalDouble;
let tmpRetOptionalHeapObject;
let strStack = [];
let i32Stack = [];
let f32Stack = [];
let f64Stack = [];
let ptrStack = [];
const enumHelpers = {};
const structHelpers = {};
let _exports = null;
let bjs = null;
return {
/**
* @param {WebAssembly.Imports} importObject
*/
addImports: (importObject, importsContext) => {
bjs = {};
importObject["bjs"] = bjs;
const imports = options.getImports(importsContext);
bjs["swift_js_return_string"] = function(ptr, len) {
const bytes = new Uint8Array(memory.buffer, ptr, len);
tmpRetString = textDecoder.decode(bytes);
}
bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) {
const source = swift.memory.getObject(sourceId);
swift.memory.release(sourceId);
const bytes = new Uint8Array(memory.buffer, bytesPtr);
bytes.set(source);
}
bjs["swift_js_make_js_string"] = function(ptr, len) {
const bytes = new Uint8Array(memory.buffer, ptr, len);
return swift.memory.retain(textDecoder.decode(bytes));
}
bjs["swift_js_init_memory_with_result"] = function(ptr, len) {
const target = new Uint8Array(memory.buffer, ptr, len);
target.set(tmpRetBytes);
tmpRetBytes = undefined;
}
bjs["swift_js_throw"] = function(id) {
tmpRetException = swift.memory.retainByRef(id);
}
bjs["swift_js_retain"] = function(id) {
return swift.memory.retainByRef(id);
}
bjs["swift_js_release"] = function(id) {
swift.memory.release(id);
}
bjs["swift_js_push_i32"] = function(v) {
i32Stack.push(v | 0);
}
bjs["swift_js_push_f32"] = function(v) {
f32Stack.push(Math.fround(v));
}
bjs["swift_js_push_f64"] = function(v) {
f64Stack.push(v);
}
bjs["swift_js_push_string"] = function(ptr, len) {
const bytes = new Uint8Array(memory.buffer, ptr, len);
const value = textDecoder.decode(bytes);
strStack.push(value);
}
bjs["swift_js_pop_i32"] = function() {
return i32Stack.pop();
}
bjs["swift_js_pop_f32"] = function() {
return f32Stack.pop();
}
bjs["swift_js_pop_f64"] = function() {
return f64Stack.pop();
}
bjs["swift_js_push_pointer"] = function(pointer) {
ptrStack.push(pointer);
}
bjs["swift_js_pop_pointer"] = function() {
return ptrStack.pop();
}
bjs["swift_js_return_optional_bool"] = function(isSome, value) {
if (isSome === 0) {
tmpRetOptionalBool = null;
} else {
tmpRetOptionalBool = value !== 0;
}
}
bjs["swift_js_return_optional_int"] = function(isSome, value) {
if (isSome === 0) {
tmpRetOptionalInt = null;
} else {
tmpRetOptionalInt = value | 0;
}
}
bjs["swift_js_return_optional_float"] = function(isSome, value) {
if (isSome === 0) {
tmpRetOptionalFloat = null;
} else {
tmpRetOptionalFloat = Math.fround(value);
}
}
bjs["swift_js_return_optional_double"] = function(isSome, value) {
if (isSome === 0) {
tmpRetOptionalDouble = null;
} else {
tmpRetOptionalDouble = value;
}
}
bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) {
if (isSome === 0) {
tmpRetString = null;
} else {
const bytes = new Uint8Array(memory.buffer, ptr, len);
tmpRetString = textDecoder.decode(bytes);
}
}
bjs["swift_js_return_optional_object"] = function(isSome, objectId) {
if (isSome === 0) {
tmpRetString = null;
} else {
tmpRetString = swift.memory.getObject(objectId);
}
}
bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) {
if (isSome === 0) {
tmpRetOptionalHeapObject = null;
} else {
tmpRetOptionalHeapObject = pointer;
}
}
bjs["swift_js_get_optional_int_presence"] = function() {
return tmpRetOptionalInt != null ? 1 : 0;
}
bjs["swift_js_get_optional_int_value"] = function() {
const value = tmpRetOptionalInt;
tmpRetOptionalInt = undefined;
return value;
}
bjs["swift_js_get_optional_string"] = function() {
const str = tmpRetString;
tmpRetString = undefined;
if (str == null) {
return -1;
} else {
const bytes = textEncoder.encode(str);
tmpRetBytes = bytes;
return bytes.length;
}
}
bjs["swift_js_get_optional_float_presence"] = function() {
return tmpRetOptionalFloat != null ? 1 : 0;
}
bjs["swift_js_get_optional_float_value"] = function() {
const value = tmpRetOptionalFloat;
tmpRetOptionalFloat = undefined;
return value;
}
bjs["swift_js_get_optional_double_presence"] = function() {
return tmpRetOptionalDouble != null ? 1 : 0;
}
bjs["swift_js_get_optional_double_value"] = function() {
const value = tmpRetOptionalDouble;
tmpRetOptionalDouble = undefined;
return value;
}
bjs["swift_js_get_optional_heap_object_pointer"] = function() {
const pointer = tmpRetOptionalHeapObject;
tmpRetOptionalHeapObject = undefined;
return pointer || 0;
}
bjs["swift_js_closure_unregister"] = function(funcRef) {}
// Wrapper functions for module: TestModule
if (!importObject["TestModule"]) {
importObject["TestModule"] = {};
}
importObject["TestModule"]["bjs_Greeter_wrap"] = function(pointer) {
const obj = _exports['Greeter'].__construct(pointer);
return swift.memory.retain(obj);
};
importObject["TestModule"]["bjs_OptionalPropertyHolder_wrap"] = function(pointer) {
const obj = _exports['OptionalPropertyHolder'].__construct(pointer);
return swift.memory.retain(obj);
};
const TestModule = importObject["TestModule"] = importObject["TestModule"] || {};
TestModule["bjs_WithOptionalJSClass_init"] = function bjs_WithOptionalJSClass_init(valueOrNullIsSome, valueOrNullWrappedValue, valueOrUndefinedIsSome, valueOrUndefinedWrappedValue) {
try {
let obj;
if (valueOrNullIsSome) {
obj = swift.memory.getObject(valueOrNullWrappedValue);
swift.memory.release(valueOrNullWrappedValue);
}
let obj1;
if (valueOrUndefinedIsSome) {
obj1 = swift.memory.getObject(valueOrUndefinedWrappedValue);
swift.memory.release(valueOrUndefinedWrappedValue);
}
return swift.memory.retain(new imports.WithOptionalJSClass(valueOrNullIsSome ? obj : null, valueOrUndefinedIsSome ? obj1 : undefined));
} catch (error) {
setException(error);
return 0
}
}
TestModule["bjs_WithOptionalJSClass_stringOrNull_get"] = function bjs_WithOptionalJSClass_stringOrNull_get(self) {
try {
let ret = swift.memory.getObject(self).stringOrNull;
const isSome = ret != null;
if (isSome) {
tmpRetString = ret;
} else {
tmpRetString = null;
}
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_stringOrUndefined_get"] = function bjs_WithOptionalJSClass_stringOrUndefined_get(self) {
try {
let ret = swift.memory.getObject(self).stringOrUndefined;
const isSome = ret !== undefined;
if (isSome) {
tmpRetString = ret;
} else {
tmpRetString = null;
}
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_doubleOrNull_get"] = function bjs_WithOptionalJSClass_doubleOrNull_get(self) {
try {
let ret = swift.memory.getObject(self).doubleOrNull;
const isSome = ret != null;
bjs["swift_js_return_optional_double"](isSome ? 1 : 0, isSome ? ret : 0.0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_doubleOrUndefined_get"] = function bjs_WithOptionalJSClass_doubleOrUndefined_get(self) {
try {
let ret = swift.memory.getObject(self).doubleOrUndefined;
const isSome = ret !== undefined;
bjs["swift_js_return_optional_double"](isSome ? 1 : 0, isSome ? ret : 0.0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_boolOrNull_get"] = function bjs_WithOptionalJSClass_boolOrNull_get(self) {
try {
let ret = swift.memory.getObject(self).boolOrNull;
const isSome = ret != null;
bjs["swift_js_return_optional_bool"](isSome ? 1 : 0, isSome ? (ret ? 1 : 0) : 0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_boolOrUndefined_get"] = function bjs_WithOptionalJSClass_boolOrUndefined_get(self) {
try {
let ret = swift.memory.getObject(self).boolOrUndefined;
const isSome = ret !== undefined;
bjs["swift_js_return_optional_bool"](isSome ? 1 : 0, isSome ? (ret ? 1 : 0) : 0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_intOrNull_get"] = function bjs_WithOptionalJSClass_intOrNull_get(self) {
try {
let ret = swift.memory.getObject(self).intOrNull;
const isSome = ret != null;
bjs["swift_js_return_optional_int"](isSome ? 1 : 0, isSome ? (ret | 0) : 0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_intOrUndefined_get"] = function bjs_WithOptionalJSClass_intOrUndefined_get(self) {
try {
let ret = swift.memory.getObject(self).intOrUndefined;
const isSome = ret !== undefined;
bjs["swift_js_return_optional_int"](isSome ? 1 : 0, isSome ? (ret | 0) : 0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_stringOrNull_set"] = function bjs_WithOptionalJSClass_stringOrNull_set(self, newValueIsSome, newValueWrappedValue) {
try {
let obj;
if (newValueIsSome) {
obj = swift.memory.getObject(newValueWrappedValue);
swift.memory.release(newValueWrappedValue);
}
swift.memory.getObject(self).stringOrNull = newValueIsSome ? obj : null;
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_stringOrUndefined_set"] = function bjs_WithOptionalJSClass_stringOrUndefined_set(self, newValueIsSome, newValueWrappedValue) {
try {
let obj;
if (newValueIsSome) {
obj = swift.memory.getObject(newValueWrappedValue);
swift.memory.release(newValueWrappedValue);
}
swift.memory.getObject(self).stringOrUndefined = newValueIsSome ? obj : undefined;
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_doubleOrNull_set"] = function bjs_WithOptionalJSClass_doubleOrNull_set(self, newValueIsSome, newValueWrappedValue) {
try {
swift.memory.getObject(self).doubleOrNull = newValueIsSome ? newValueWrappedValue : null;
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_doubleOrUndefined_set"] = function bjs_WithOptionalJSClass_doubleOrUndefined_set(self, newValueIsSome, newValueWrappedValue) {
try {
swift.memory.getObject(self).doubleOrUndefined = newValueIsSome ? newValueWrappedValue : undefined;
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_boolOrNull_set"] = function bjs_WithOptionalJSClass_boolOrNull_set(self, newValueIsSome, newValueWrappedValue) {
try {
swift.memory.getObject(self).boolOrNull = newValueIsSome ? newValueWrappedValue !== 0 : null;
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_boolOrUndefined_set"] = function bjs_WithOptionalJSClass_boolOrUndefined_set(self, newValueIsSome, newValueWrappedValue) {
try {
swift.memory.getObject(self).boolOrUndefined = newValueIsSome ? newValueWrappedValue !== 0 : undefined;
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_intOrNull_set"] = function bjs_WithOptionalJSClass_intOrNull_set(self, newValueIsSome, newValueWrappedValue) {
try {
swift.memory.getObject(self).intOrNull = newValueIsSome ? newValueWrappedValue : null;
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_intOrUndefined_set"] = function bjs_WithOptionalJSClass_intOrUndefined_set(self, newValueIsSome, newValueWrappedValue) {
try {
swift.memory.getObject(self).intOrUndefined = newValueIsSome ? newValueWrappedValue : undefined;
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_roundTripStringOrNull"] = function bjs_WithOptionalJSClass_roundTripStringOrNull(self, valueIsSome, valueWrappedValue) {
try {
let obj;
if (valueIsSome) {
obj = swift.memory.getObject(valueWrappedValue);
swift.memory.release(valueWrappedValue);
}
let ret = swift.memory.getObject(self).roundTripStringOrNull(valueIsSome ? obj : null);
const isSome = ret != null;
if (isSome) {
tmpRetString = ret;
} else {
tmpRetString = null;
}
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_roundTripStringOrUndefined"] = function bjs_WithOptionalJSClass_roundTripStringOrUndefined(self, valueIsSome, valueWrappedValue) {
try {
let obj;
if (valueIsSome) {
obj = swift.memory.getObject(valueWrappedValue);
swift.memory.release(valueWrappedValue);
}
let ret = swift.memory.getObject(self).roundTripStringOrUndefined(valueIsSome ? obj : undefined);
const isSome = ret !== undefined;
if (isSome) {
tmpRetString = ret;
} else {
tmpRetString = null;
}
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_roundTripDoubleOrNull"] = function bjs_WithOptionalJSClass_roundTripDoubleOrNull(self, valueIsSome, valueWrappedValue) {
try {
let ret = swift.memory.getObject(self).roundTripDoubleOrNull(valueIsSome ? valueWrappedValue : null);
const isSome = ret != null;
bjs["swift_js_return_optional_double"](isSome ? 1 : 0, isSome ? ret : 0.0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_roundTripDoubleOrUndefined"] = function bjs_WithOptionalJSClass_roundTripDoubleOrUndefined(self, valueIsSome, valueWrappedValue) {
try {
let ret = swift.memory.getObject(self).roundTripDoubleOrUndefined(valueIsSome ? valueWrappedValue : undefined);
const isSome = ret !== undefined;
bjs["swift_js_return_optional_double"](isSome ? 1 : 0, isSome ? ret : 0.0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_roundTripBoolOrNull"] = function bjs_WithOptionalJSClass_roundTripBoolOrNull(self, valueIsSome, valueWrappedValue) {
try {
let ret = swift.memory.getObject(self).roundTripBoolOrNull(valueIsSome ? valueWrappedValue !== 0 : null);
const isSome = ret != null;
bjs["swift_js_return_optional_bool"](isSome ? 1 : 0, isSome ? (ret ? 1 : 0) : 0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_roundTripBoolOrUndefined"] = function bjs_WithOptionalJSClass_roundTripBoolOrUndefined(self, valueIsSome, valueWrappedValue) {
try {
let ret = swift.memory.getObject(self).roundTripBoolOrUndefined(valueIsSome ? valueWrappedValue !== 0 : undefined);
const isSome = ret !== undefined;
bjs["swift_js_return_optional_bool"](isSome ? 1 : 0, isSome ? (ret ? 1 : 0) : 0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_roundTripIntOrNull"] = function bjs_WithOptionalJSClass_roundTripIntOrNull(self, valueIsSome, valueWrappedValue) {
try {
let ret = swift.memory.getObject(self).roundTripIntOrNull(valueIsSome ? valueWrappedValue : null);
const isSome = ret != null;
bjs["swift_js_return_optional_int"](isSome ? 1 : 0, isSome ? (ret | 0) : 0);
} catch (error) {
setException(error);
}
}
TestModule["bjs_WithOptionalJSClass_roundTripIntOrUndefined"] = function bjs_WithOptionalJSClass_roundTripIntOrUndefined(self, valueIsSome, valueWrappedValue) {
try {
let ret = swift.memory.getObject(self).roundTripIntOrUndefined(valueIsSome ? valueWrappedValue : undefined);
const isSome = ret !== undefined;
bjs["swift_js_return_optional_int"](isSome ? 1 : 0, isSome ? (ret | 0) : 0);
} catch (error) {
setException(error);
}
}
},
setInstance: (i) => {
instance = i;
memory = instance.exports.memory;
setException = (error) => {
instance.exports._swift_js_exception.value = swift.memory.retain(error)
}
},
/** @param {WebAssembly.Instance} instance */
createExports: (instance) => {
const js = swift.memory.heap;
const swiftHeapObjectFinalizationRegistry = (typeof FinalizationRegistry === "undefined") ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry((state) => {
if (state.hasReleased) {
return;
}
state.hasReleased = true;
try {
state.deinit(state.pointer);
} catch {}
});
/// Represents a Swift heap object like a class instance or an actor instance.
class SwiftHeapObject {
static __wrap(pointer, deinit, prototype) {
const obj = Object.create(prototype);
const state = { pointer, deinit, hasReleased: false };
obj.pointer = pointer;
obj.__swiftHeapObjectState = state;
swiftHeapObjectFinalizationRegistry.register(obj, state, state);
return obj;
}
release() {
const state = this.__swiftHeapObjectState;
if (state.hasReleased) {
return;
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
try {
state.deinit(state.pointer);
} catch {}
}
}
class Greeter extends SwiftHeapObject {
static __construct(ptr) {
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Greeter_deinit, Greeter.prototype);
}
constructor(name) {
const isSome = name != null;
let nameId, nameBytes;
if (isSome) {
nameBytes = textEncoder.encode(name);
nameId = swift.memory.retain(nameBytes);
}
const ret = instance.exports.bjs_Greeter_init(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0);
return Greeter.__construct(ret);
}
greet() {
instance.exports.bjs_Greeter_greet(this.pointer);
const ret = tmpRetString;
tmpRetString = undefined;
return ret;
}
changeName(name) {
const isSome = name != null;
let nameId, nameBytes;
if (isSome) {
nameBytes = textEncoder.encode(name);
nameId = swift.memory.retain(nameBytes);
}
instance.exports.bjs_Greeter_changeName(this.pointer, +isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0);
}
get name() {
instance.exports.bjs_Greeter_name_get(this.pointer);
const optResult = tmpRetString;
tmpRetString = undefined;
return optResult;
}
set name(value) {
const isSome = value != null;
let valueId, valueBytes;
if (isSome) {
valueBytes = textEncoder.encode(value);
valueId = swift.memory.retain(valueBytes);
}
instance.exports.bjs_Greeter_name_set(this.pointer, +isSome, isSome ? valueId : 0, isSome ? valueBytes.length : 0);
}
}
class OptionalPropertyHolder extends SwiftHeapObject {
static __construct(ptr) {
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_OptionalPropertyHolder_deinit, OptionalPropertyHolder.prototype);
}
constructor() {
const ret = instance.exports.bjs_OptionalPropertyHolder_init();
return OptionalPropertyHolder.__construct(ret);
}
get optionalName() {
instance.exports.bjs_OptionalPropertyHolder_optionalName_get(this.pointer);
const optResult = tmpRetString;
tmpRetString = undefined;
return optResult;
}
set optionalName(value) {
const isSome = value != null;
let valueId, valueBytes;
if (isSome) {
valueBytes = textEncoder.encode(value);
valueId = swift.memory.retain(valueBytes);
}
instance.exports.bjs_OptionalPropertyHolder_optionalName_set(this.pointer, +isSome, isSome ? valueId : 0, isSome ? valueBytes.length : 0);
}
get optionalAge() {
instance.exports.bjs_OptionalPropertyHolder_optionalAge_get(this.pointer);
const optResult = tmpRetOptionalInt;
tmpRetOptionalInt = undefined;
return optResult;
}
set optionalAge(value) {
const isSome = value != null;
instance.exports.bjs_OptionalPropertyHolder_optionalAge_set(this.pointer, +isSome, isSome ? value : 0);
}
get optionalGreeter() {
instance.exports.bjs_OptionalPropertyHolder_optionalGreeter_get(this.pointer);
const pointer = tmpRetOptionalHeapObject;
tmpRetOptionalHeapObject = undefined;
const optResult = pointer === null ? null : Greeter.__construct(pointer);
return optResult;
}
set optionalGreeter(value) {
const isSome = value != null;
instance.exports.bjs_OptionalPropertyHolder_optionalGreeter_set(this.pointer, +isSome, isSome ? value.pointer : 0);
}
}
const exports = {
Greeter,
OptionalPropertyHolder,
roundTripOptionalClass: function bjs_roundTripOptionalClass(value) {
const isSome = value != null;
instance.exports.bjs_roundTripOptionalClass(+isSome, isSome ? value.pointer : 0);
const pointer = tmpRetOptionalHeapObject;
tmpRetOptionalHeapObject = undefined;
const optResult = pointer === null ? null : Greeter.__construct(pointer);
return optResult;
},
testOptionalPropertyRoundtrip: function bjs_testOptionalPropertyRoundtrip(holder) {
const isSome = holder != null;
instance.exports.bjs_testOptionalPropertyRoundtrip(+isSome, isSome ? holder.pointer : 0);
const pointer = tmpRetOptionalHeapObject;
tmpRetOptionalHeapObject = undefined;
const optResult = pointer === null ? null : OptionalPropertyHolder.__construct(pointer);
return optResult;
},
roundTripString: function bjs_roundTripString(name) {
const isSome = name != null;
let nameId, nameBytes;
if (isSome) {
nameBytes = textEncoder.encode(name);
nameId = swift.memory.retain(nameBytes);
}
instance.exports.bjs_roundTripString(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0);
const optResult = tmpRetString;
tmpRetString = undefined;
return optResult;
},
roundTripInt: function bjs_roundTripInt(value) {
const isSome = value != null;
instance.exports.bjs_roundTripInt(+isSome, isSome ? value : 0);
const optResult = tmpRetOptionalInt;
tmpRetOptionalInt = undefined;
return optResult;
},
roundTripBool: function bjs_roundTripBool(flag) {
const isSome = flag != null;
instance.exports.bjs_roundTripBool(+isSome, isSome ? flag : 0);
const optResult = tmpRetOptionalBool;
tmpRetOptionalBool = undefined;
return optResult;
},
roundTripFloat: function bjs_roundTripFloat(number) {
const isSome = number != null;
instance.exports.bjs_roundTripFloat(+isSome, isSome ? number : 0);
const optResult = tmpRetOptionalFloat;
tmpRetOptionalFloat = undefined;
return optResult;
},
roundTripDouble: function bjs_roundTripDouble(precision) {
const isSome = precision != null;
instance.exports.bjs_roundTripDouble(+isSome, isSome ? precision : 0);
const optResult = tmpRetOptionalDouble;
tmpRetOptionalDouble = undefined;
return optResult;
},
roundTripSyntax: function bjs_roundTripSyntax(name) {
const isSome = name != null;
let nameId, nameBytes;
if (isSome) {
nameBytes = textEncoder.encode(name);
nameId = swift.memory.retain(nameBytes);
}
instance.exports.bjs_roundTripSyntax(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0);
const optResult = tmpRetString;
tmpRetString = undefined;
return optResult;
},
roundTripMixSyntax: function bjs_roundTripMixSyntax(name) {
const isSome = name != null;
let nameId, nameBytes;
if (isSome) {
nameBytes = textEncoder.encode(name);
nameId = swift.memory.retain(nameBytes);
}
instance.exports.bjs_roundTripMixSyntax(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0);
const optResult = tmpRetString;
tmpRetString = undefined;
return optResult;
},
roundTripSwiftSyntax: function bjs_roundTripSwiftSyntax(name) {
const isSome = name != null;
let nameId, nameBytes;
if (isSome) {
nameBytes = textEncoder.encode(name);
nameId = swift.memory.retain(nameBytes);
}
instance.exports.bjs_roundTripSwiftSyntax(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0);
const optResult = tmpRetString;
tmpRetString = undefined;
return optResult;
},
roundTripMixedSwiftSyntax: function bjs_roundTripMixedSwiftSyntax(name) {
const isSome = name != null;
let nameId, nameBytes;
if (isSome) {
nameBytes = textEncoder.encode(name);
nameId = swift.memory.retain(nameBytes);
}
instance.exports.bjs_roundTripMixedSwiftSyntax(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0);
const optResult = tmpRetString;
tmpRetString = undefined;
return optResult;
},
roundTripWithSpaces: function bjs_roundTripWithSpaces(value) {
const isSome = value != null;
instance.exports.bjs_roundTripWithSpaces(+isSome, isSome ? value : 0);
const optResult = tmpRetOptionalDouble;
tmpRetOptionalDouble = undefined;
return optResult;
},
roundTripAlias: function bjs_roundTripAlias(age) {
const isSome = age != null;
instance.exports.bjs_roundTripAlias(+isSome, isSome ? age : 0);
const optResult = tmpRetOptionalInt;
tmpRetOptionalInt = undefined;
return optResult;
},
roundTripOptionalAlias: function bjs_roundTripOptionalAlias(name) {
const isSome = name != null;
let nameId, nameBytes;
if (isSome) {
nameBytes = textEncoder.encode(name);
nameId = swift.memory.retain(nameBytes);
}
instance.exports.bjs_roundTripOptionalAlias(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0);
const optResult = tmpRetString;
tmpRetString = undefined;
return optResult;
},
testMixedOptionals: function bjs_testMixedOptionals(firstName, lastName, age, active) {
const isSome = firstName != null;
let firstNameId, firstNameBytes;
if (isSome) {
firstNameBytes = textEncoder.encode(firstName);
firstNameId = swift.memory.retain(firstNameBytes);
}
const isSome1 = lastName != null;
let lastNameId, lastNameBytes;
if (isSome1) {
lastNameBytes = textEncoder.encode(lastName);
lastNameId = swift.memory.retain(lastNameBytes);
}
const isSome2 = age != null;
instance.exports.bjs_testMixedOptionals(+isSome, isSome ? firstNameId : 0, isSome ? firstNameBytes.length : 0, +isSome1, isSome1 ? lastNameId : 0, isSome1 ? lastNameBytes.length : 0, +isSome2, isSome2 ? age : 0, active);
const optResult = tmpRetString;
tmpRetString = undefined;
return optResult;
},
};
_exports = exports;
return exports;
},
}
}