forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumNamespace.Export.js
More file actions
247 lines (234 loc) · 8.91 KB
/
EnumNamespace.Export.js
File metadata and controls
247 lines (234 loc) · 8.91 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
// 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 const Method = {
Get: 0,
Post: 1,
Put: 2,
Delete: 3,
};
export const LogLevel = {
Debug: "debug",
Info: "info",
Warning: "warning",
Error: "error",
};
export const Port = {
Http: 80,
Https: 443,
Development: 3000,
};
export const SupportedMethod = {
Get: 0,
Post: 1,
};
if (typeof globalThis.Networking === 'undefined') {
globalThis.Networking = {};
}
if (typeof globalThis.Networking.API === 'undefined') {
globalThis.Networking.API = {};
}
if (typeof globalThis.Configuration === 'undefined') {
globalThis.Configuration = {};
}
if (typeof globalThis.Networking.APIV2 === 'undefined') {
globalThis.Networking.APIV2 = {};
}
if (typeof globalThis.Networking.APIV2.Internal === 'undefined') {
globalThis.Networking.APIV2.Internal = {};
}
globalThis.Networking.API.Method = Method;
globalThis.Configuration.LogLevel = LogLevel;
globalThis.Configuration.Port = Port;
globalThis.Networking.APIV2.Internal.SupportedMethod = SupportedMethod;
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 tmpRetTag;
let tmpRetStrings = [];
let tmpRetInts = [];
let tmpRetF32s = [];
let tmpRetF64s = [];
let tmpParamInts = [];
let tmpParamF32s = [];
let tmpParamF64s = [];
return {
/**
* @param {WebAssembly.Imports} importObject
*/
addImports: (importObject, importsContext) => {
const 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);
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_tag"] = function(tag) {
tmpRetTag = tag;
}
bjs["swift_js_push_int"] = function(v) {
tmpRetInts.push(v | 0);
}
bjs["swift_js_push_f32"] = function(v) {
tmpRetF32s.push(Math.fround(v));
}
bjs["swift_js_push_f64"] = function(v) {
tmpRetF64s.push(v);
}
bjs["swift_js_push_string"] = function(ptr, len) {
const bytes = new Uint8Array(memory.buffer, ptr, len);
const value = textDecoder.decode(bytes);
tmpRetStrings.push(value);
}
bjs["swift_js_pop_param_int32"] = function() {
return tmpParamInts.pop();
}
bjs["swift_js_pop_param_f32"] = function() {
return tmpParamF32s.pop();
}
bjs["swift_js_pop_param_f64"] = function() {
return tmpParamF64s.pop();
}
// Wrapper functions for module: TestModule
if (!importObject["TestModule"]) {
importObject["TestModule"] = {};
}
importObject["TestModule"]["bjs_Converter_wrap"] = function(pointer) {
const obj = Converter.__construct(pointer);
return swift.memory.retain(obj);
};
importObject["TestModule"]["bjs_HTTPServer_wrap"] = function(pointer) {
const obj = HTTPServer.__construct(pointer);
return swift.memory.retain(obj);
};
importObject["TestModule"]["bjs_TestServer_wrap"] = function(pointer) {
const obj = TestServer.__construct(pointer);
return swift.memory.retain(obj);
};
},
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;
/// 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);
obj.pointer = pointer;
obj.hasReleased = false;
obj.deinit = deinit;
obj.registry = new FinalizationRegistry((pointer) => {
deinit(pointer);
});
obj.registry.register(this, obj.pointer);
return obj;
}
release() {
this.registry.unregister(this);
this.deinit(this.pointer);
}
}
class Converter extends SwiftHeapObject {
static __construct(ptr) {
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Converter_deinit, Converter.prototype);
}
constructor() {
const ret = instance.exports.bjs_Converter_init();
return Converter.__construct(ret);
}
toString(value) {
instance.exports.bjs_Converter_toString(this.pointer, value);
const ret = tmpRetString;
tmpRetString = undefined;
return ret;
}
}
class HTTPServer extends SwiftHeapObject {
static __construct(ptr) {
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_HTTPServer_deinit, HTTPServer.prototype);
}
constructor() {
const ret = instance.exports.bjs_HTTPServer_init();
return HTTPServer.__construct(ret);
}
call(method) {
instance.exports.bjs_HTTPServer_call(this.pointer, method);
}
}
class TestServer extends SwiftHeapObject {
static __construct(ptr) {
return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_TestServer_deinit, TestServer.prototype);
}
constructor() {
const ret = instance.exports.bjs_TestServer_init();
return TestServer.__construct(ret);
}
call(method) {
instance.exports.bjs_TestServer_call(this.pointer, method);
}
}
const exports = {
Converter,
HTTPServer,
TestServer,
};
if (typeof globalThis.Networking === 'undefined') {
globalThis.Networking = {};
}
if (typeof globalThis.Networking.API === 'undefined') {
globalThis.Networking.API = {};
}
if (typeof globalThis.Networking.APIV2 === 'undefined') {
globalThis.Networking.APIV2 = {};
}
if (typeof globalThis.Networking.APIV2.Internal === 'undefined') {
globalThis.Networking.APIV2.Internal = {};
}
if (typeof globalThis.Utils === 'undefined') {
globalThis.Utils = {};
}
globalThis.Utils.Converter = exports.Converter;
globalThis.Networking.API.HTTPServer = exports.HTTPServer;
globalThis.Networking.APIV2.Internal.TestServer = exports.TestServer;
return exports;
},
}
}