forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsync.Import.js
More file actions
170 lines (163 loc) · 6.21 KB
/
Async.Import.js
File metadata and controls
170 lines (163 loc) · 6.21 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
// 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 tmpRetTag;
let tmpRetStrings = [];
let tmpRetInts = [];
let tmpRetF32s = [];
let tmpRetF64s = [];
let tmpRetBools = [];
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);
const value = textDecoder.decode(bytes);
tmpRetString = value;
tmpRetStrings.push(value);
}
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_return_tag"] = function(tag) {
tmpRetTag = tag | 0;
tmpRetString = undefined;
tmpRetStrings = [];
tmpRetInts = [];
tmpRetF32s = [];
tmpRetF64s = [];
tmpRetBools = [];
}
bjs["swift_js_return_int"] = function(v) {
const value = v | 0;
tmpRetInts.push(value);
}
bjs["swift_js_return_f32"] = function(v) {
const value = Math.fround(v);
tmpRetF32s.push(value);
}
bjs["swift_js_return_f64"] = function(v) {
tmpRetF64s.push(v);
}
bjs["swift_js_return_bool"] = function(v) {
const value = v !== 0;
tmpRetBools.push(value);
}
const TestModule = importObject["TestModule"] = importObject["TestModule"] || {};
TestModule["bjs_asyncReturnVoid"] = function bjs_asyncReturnVoid() {
try {
let ret = imports.asyncReturnVoid();
return swift.memory.retain(ret);
} catch (error) {
setException(error);
return 0
}
}
TestModule["bjs_asyncRoundTripInt"] = function bjs_asyncRoundTripInt(v) {
try {
let ret = imports.asyncRoundTripInt(v);
return swift.memory.retain(ret);
} catch (error) {
setException(error);
return 0
}
}
TestModule["bjs_asyncRoundTripString"] = function bjs_asyncRoundTripString(v) {
try {
const vObject = swift.memory.getObject(v);
swift.memory.release(v);
let ret = imports.asyncRoundTripString(vObject);
return swift.memory.retain(ret);
} catch (error) {
setException(error);
return 0
}
}
TestModule["bjs_asyncRoundTripBool"] = function bjs_asyncRoundTripBool(v) {
try {
let ret = imports.asyncRoundTripBool(v);
return swift.memory.retain(ret);
} catch (error) {
setException(error);
return 0
}
}
TestModule["bjs_asyncRoundTripFloat"] = function bjs_asyncRoundTripFloat(v) {
try {
let ret = imports.asyncRoundTripFloat(v);
return swift.memory.retain(ret);
} catch (error) {
setException(error);
return 0
}
}
TestModule["bjs_asyncRoundTripDouble"] = function bjs_asyncRoundTripDouble(v) {
try {
let ret = imports.asyncRoundTripDouble(v);
return swift.memory.retain(ret);
} catch (error) {
setException(error);
return 0
}
}
TestModule["bjs_asyncRoundTripJSObject"] = function bjs_asyncRoundTripJSObject(v) {
try {
let ret = imports.asyncRoundTripJSObject(swift.memory.getObject(v));
return swift.memory.retain(ret);
} catch (error) {
setException(error);
return 0
}
}
},
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;
return {
};
},
}
}