-
Notifications
You must be signed in to change notification settings - Fork 572
/
Copy pathclient-wasm.js
365 lines (291 loc) · 15 KB
/
client-wasm.js
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
'use strict'
const { tspl } = require('@matteo.collina/tspl')
const { describe, test } = require('node:test')
;[
['generic', require('../lib/llhttp/llhttp-wasm.js')],
['simd', require('../lib/llhttp/llhttp_simd-wasm.js')]
].forEach(([name, llhttp]) => {
describe(name, () => {
test('can compile the wasm code', async () => {
await WebAssembly.compile(llhttp)
})
test('can instantiate the wasm code', async () => {
const mod = await WebAssembly.compile(llhttp)
await WebAssembly.instantiate(mod, {
env: {
wasm_on_url: () => { },
wasm_on_status: () => { },
wasm_on_message_begin: () => { },
wasm_on_header_field: () => { },
wasm_on_header_value: () => { },
wasm_on_headers_complete: () => { },
wasm_on_body: () => { },
wasm_on_message_complete: () => { }
}
})
})
describe('exports', async () => {
const mod = await WebAssembly.compile(llhttp)
const instance = await WebAssembly.instantiate(mod, {
env: {
wasm_on_url: () => { },
wasm_on_status: () => { },
wasm_on_message_begin: () => { },
wasm_on_header_field: () => { },
wasm_on_header_value: () => { },
wasm_on_headers_complete: () => { },
wasm_on_body: () => { },
wasm_on_message_complete: () => { }
}
})
test('has the right amount of exports', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(instance.exports, 'exports are present')
t.deepStrictEqual(Object.keys(instance.exports), [
'memory',
'_initialize',
'__indirect_function_table',
'llhttp_init',
'llhttp_should_keep_alive',
'llhttp_alloc',
'malloc',
'llhttp_free',
'free',
'llhttp_get_type',
'llhttp_get_http_major',
'llhttp_get_http_minor',
'llhttp_get_method',
'llhttp_get_status_code',
'llhttp_get_upgrade',
'llhttp_reset',
'llhttp_execute',
'llhttp_settings_init',
'llhttp_finish',
'llhttp_pause',
'llhttp_resume',
'llhttp_resume_after_upgrade',
'llhttp_get_errno',
'llhttp_get_error_reason',
'llhttp_set_error_reason',
'llhttp_get_error_pos',
'llhttp_errno_name',
'llhttp_method_name',
'llhttp_status_name',
'llhttp_set_lenient_headers',
'llhttp_set_lenient_chunked_length',
'llhttp_set_lenient_keep_alive',
'llhttp_set_lenient_transfer_encoding',
'llhttp_set_lenient_version',
'llhttp_set_lenient_data_after_close',
'llhttp_set_lenient_optional_lf_after_cr',
'llhttp_set_lenient_optional_crlf_after_chunk',
'llhttp_set_lenient_optional_cr_before_lf',
'llhttp_set_lenient_spaces_after_chunk_size',
'llhttp_message_needs_eof'
])
await t.completed
})
test('instance.exports.memory', async (t) => {
t = tspl(t, { plan: 1 })
t.ok(instance.exports.memory instanceof WebAssembly.Memory, 'memory is present')
})
// _initialize
test('instance.exports._initialize', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports._initialize === 'function', '_initialize is present')
t.strictEqual(instance.exports._initialize.length, 0, '_initialize has the right number of arguments')
})
// __indirect_function_table
test('instance.exports.__indirect_function_table', async (t) => {
t = tspl(t, { plan: 1 })
t.ok(instance.exports.__indirect_function_table instanceof WebAssembly.Table, '__indirect_function_table is present')
})
// malloc
test('instance.exports.malloc', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.malloc === 'function', 'malloc is present')
t.strictEqual(instance.exports.malloc.length, 1, 'malloc has the right number of arguments')
})
// free
test('instance.exports.free', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.free === 'function', 'free is present')
t.strictEqual(instance.exports.free.length, 1, 'free has the right number of arguments')
})
// llhttp_init
test('instance.exports.llhttp_init', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_init === 'function', 'llhttp_init is present')
t.strictEqual(instance.exports.llhttp_init.length, 3, 'llhttp_init has the right number of arguments')
})
// llhttp_alloc
test('instance.exports.llhttp_alloc', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_alloc === 'function', 'llhttp_alloc is present')
t.strictEqual(instance.exports.llhttp_alloc.length, 1, 'llhttp_alloc has the right number of arguments')
})
// llhttp_free
test('instance.exports.llhttp_free', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_free === 'function', 'llhttp_free is present')
t.strictEqual(instance.exports.llhttp_free.length, 1, 'llhttp_free has the right number of arguments')
})
// llhttp_get_type
test('instance.exports.llhttp_get_type', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_get_type === 'function', 'llhttp_get_type is present')
t.strictEqual(instance.exports.llhttp_get_type.length, 1, 'llhttp_get_type has the right number of arguments')
})
// llhttp_should_keep_alive
test('instance.exports.llhttp_should_keep_alive', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_should_keep_alive === 'function', 'llhttp_should_keep_alive is present')
t.strictEqual(instance.exports.llhttp_should_keep_alive.length, 1, 'llhttp_should_keep_alive has the right number of arguments')
})
// llhttp_get_http_major
test('instance.exports.llhttp_get_http_major', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_get_http_major === 'function', 'llhttp_get_http_major is present')
t.strictEqual(instance.exports.llhttp_get_http_major.length, 1, 'llhttp_get_http_major has the right number of arguments')
})
// llhttp_get_http_minor
test('instance.exports.llhttp_get_http_minor', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_get_http_minor === 'function', 'llhttp_get_http_minor is present')
t.strictEqual(instance.exports.llhttp_get_http_minor.length, 1, 'llhttp_get_http_minor has the right number of arguments')
})
// llhttp_get_method
test('instance.exports.llhttp_get_method', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_get_method === 'function', 'llhttp_get_method is present')
t.strictEqual(instance.exports.llhttp_get_method.length, 1, 'llhttp_get_method has the right number of arguments')
})
// llhttp_get_status_code
test('instance.exports.llhttp_get_status_code', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_get_status_code === 'function', 'llhttp_get_status_code is present')
t.strictEqual(instance.exports.llhttp_get_status_code.length, 1, 'llhttp_get_status_code has the right number of arguments')
})
// llhttp_get_upgrade
test('instance.exports.llhttp_get_upgrade', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_get_upgrade === 'function', 'llhttp_get_upgrade is present')
t.strictEqual(instance.exports.llhttp_get_upgrade.length, 1, 'llhttp_get_upgrade has the right number of arguments')
})
// llhttp_reset
test('instance.exports.llhttp_reset', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_reset === 'function', 'llhttp_reset is present')
t.strictEqual(instance.exports.llhttp_reset.length, 1, 'llhttp_reset has the right number of arguments')
})
// llhttp_execute
test('instance.exports.llhttp_execute', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_execute === 'function', 'llhttp_execute is present')
t.strictEqual(instance.exports.llhttp_execute.length, 3, 'llhttp_execute has the right number of arguments')
})
// llhttp_settings_init
test('instance.exports.llhttp_settings_init', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_settings_init === 'function', 'llhttp_settings_init is present')
t.strictEqual(instance.exports.llhttp_settings_init.length, 1, 'llhttp_settings_init has the right number of arguments')
})
// llhttp_finish
test('instance.exports.llhttp_finish', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_finish === 'function', 'llhttp_finish is present')
t.strictEqual(instance.exports.llhttp_finish.length, 1, 'llhttp_finish has the right number of arguments')
})
// llhttp_pause
test('instance.exports.llhttp_pause', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_pause === 'function', 'llhttp_pause is present')
t.strictEqual(instance.exports.llhttp_pause.length, 1, 'llhttp_pause has the right number of arguments')
})
// llhttp_resume
test('instance.exports.llhttp_resume', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_resume === 'function', 'llhttp_resume is present')
t.strictEqual(instance.exports.llhttp_resume.length, 1, 'llhttp_resume has the right number of arguments')
})
// llhttp_resume_after_upgrade
test('instance.exports.llhttp_resume_after_upgrade', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_resume_after_upgrade === 'function', 'llhttp_resume_after_upgrade is present')
t.strictEqual(instance.exports.llhttp_resume_after_upgrade.length, 1, 'llhttp_resume_after_upgrade has the right number of arguments')
})
// llhttp_get_errno
test('instance.exports.llhttp_get_errno', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_get_errno === 'function', 'llhttp_get_errno is present')
t.strictEqual(instance.exports.llhttp_get_errno.length, 1, 'llhttp_get_errno has the right number of arguments')
})
// llhttp_get_error_reason
test('instance.exports.llhttp_get_error_reason', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_get_error_reason === 'function', 'llhttp_get_error_reason is present')
t.strictEqual(instance.exports.llhttp_get_error_reason.length, 1, 'llhttp_get_error_reason has the right number of arguments')
})
// llhttp_set_error_reason
test('instance.exports.llhttp_set_error_reason', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_set_error_reason === 'function', 'llhttp_set_error_reason is present')
t.strictEqual(instance.exports.llhttp_set_error_reason.length, 2, 'llhttp_set_error_reason has the right number of arguments')
})
// llhttp_get_error_pos
test('instance.exports.llhttp_get_error_pos', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_get_error_pos === 'function', 'llhttp_get_error_pos is present')
t.strictEqual(instance.exports.llhttp_get_error_pos.length, 1, 'llhttp_get_error_pos has the right number of arguments')
})
// llhttp_errno_name
test('instance.exports.llhttp_errno_name', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_errno_name === 'function', 'llhttp_errno_name is present')
t.strictEqual(instance.exports.llhttp_errno_name.length, 1, 'llhttp_errno_name has the right number of arguments')
})
// llhttp_method_name
test('instance.exports.llhttp_method_name', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_method_name === 'function', 'llhttp_method_name is present')
t.strictEqual(instance.exports.llhttp_method_name.length, 1, 'llhttp_method_name has the right number of arguments')
})
// llhttp_status_name
test('instance.exports.llhttp_status_name', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_status_name === 'function', 'llhttp_status_name is present')
t.strictEqual(instance.exports.llhttp_status_name.length, 1, 'llhttp_status_name has the right number of arguments')
})
// llhttp_set_lenient_headers
test('instance.exports.llhttp_set_lenient_headers', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_set_lenient_headers === 'function', 'llhttp_set_lenient_headers is present')
t.strictEqual(instance.exports.llhttp_set_lenient_headers.length, 2, 'llhttp_set_lenient_headers has the right number of arguments')
})
// llhttp_set_lenient_chunked_length
test('instance.exports.llhttp_set_lenient_chunked_length', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_set_lenient_chunked_length === 'function', 'llhttp_set_lenient_chunked_length is present')
t.strictEqual(instance.exports.llhttp_set_lenient_chunked_length.length, 2, 'llhttp_set_lenient_chunked_length has the right number of arguments')
})
// llhttp_set_lenient_keep_alive
test('instance.exports.llhttp_set_lenient_keep_alive', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_set_lenient_keep_alive === 'function', 'llhttp_set_lenient_keep_alive is present')
t.strictEqual(instance.exports.llhttp_set_lenient_keep_alive.length, 2, 'llhttp_set_lenient_keep_alive has the right number of arguments')
})
// llhttp_set_lenient_transfer_encoding
test('instance.exports.llhttp_set_lenient_transfer_encoding', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_set_lenient_transfer_encoding === 'function', 'llhttp_set_lenient_transfer_encoding is present')
t.strictEqual(instance.exports.llhttp_set_lenient_transfer_encoding.length, 2, 'llhttp_set_lenient_transfer_encoding has the right number of arguments')
})
// llhttp_message_needs_eof
test('instance.exports.llhttp_message_needs_eof', async (t) => {
t = tspl(t, { plan: 2 })
t.ok(typeof instance.exports.llhttp_message_needs_eof === 'function', 'llhttp_message_needs_eof is present')
t.strictEqual(instance.exports.llhttp_message_needs_eof.length, 1, 'llhttp_message_needs_eof has the right number of arguments')
})
})
})
})