summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/spec/imports.wast
blob: 51b5066bdb9fd4c255495055e7df2e3156cb96cc (plain)
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
;; Auxiliary module to import from

(module
  (func (export "func"))
  (func (export "func-i32") (param i32))
  (func (export "func-f32") (param f32))
  (func (export "func->i32") (result i32) (i32.const 22))
  (func (export "func->f32") (result f32) (f32.const 11))
  (func (export "func-i32->i32") (param i32) (result i32) (get_local 0))
  (global (export "global-i32") i32 (i32.const 55))
  (global (export "global-f32") f32 (f32.const 44))
  (table (export "table-10-inf") 10 anyfunc)
  ;; (table (export "table-10-20") 10 20 anyfunc)
  (memory (export "memory-2-inf") 2)
  ;; (memory (export "memory-2-4") 2 4)
)

(register "test")


;; Functions

(module
  (type $func_i32 (func (param i32)))
  (type $func_i64 (func (param i64)))

  (import "spectest" "print" (func (param i32)))
  (func (import "spectest" "print") (param i64))
  (import "spectest" "print" (func $print_i32 (param i32)))
  (import "spectest" "print" (func $print_i64 (param i64)))
  (import "spectest" "print" (func $print_i32_f32 (param i32 f32)))
  (import "spectest" "print" (func $print_i64_f64 (param i64 f64)))
  (func $print_i32-2 (import "spectest" "print") (param i32))
  (func $print_i64-2 (import "spectest" "print") (param i64))

  (table anyfunc (elem $print_i32 $print_i64))

  (func (export "print32") (param $i i32)
    (call 0 (get_local $i))
    (call $print_i32_f32
      (i32.add (get_local $i) (i32.const 1))
      (f32.const 42)
    )
    (call $print_i32 (get_local $i))
    (call $print_i32-2 (get_local $i))
    (call_indirect $func_i32 (get_local $i) (i32.const 0))
  )

  (func (export "print64") (param $i i64)
    (call 1 (get_local $i))
    (call $print_i64_f64
      (i64.add (get_local $i) (i64.const 1))
      (f64.const 53)
    )
    (call $print_i64 (get_local $i))
    (call $print_i64-2 (get_local $i))
    (call_indirect $func_i64 (get_local $i) (i32.const 1))
  )
)

(assert_return (invoke "print32" (i32.const 13)))
(assert_return (invoke "print64" (i64.const 24)))

(module (import "test" "func" (func)))
(module (import "test" "func-i32" (func (param i32))))
(module (import "test" "func-f32" (func (param f32))))
(module (import "test" "func->i32" (func (result i32))))
(module (import "test" "func->f32" (func (result f32))))
(module (import "test" "func-i32->i32" (func (param i32) (result i32))))

(assert_unlinkable
  (module (import "test" "unknown" (func)))
  "unknown import"
)
(assert_unlinkable
  (module (import "spectest" "unknown" (func)))
  "unknown import"
)

(assert_unlinkable
  (module (import "test" "func" (func (param i32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func" (func (result i32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func" (func (param i32) (result i32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func-i32" (func)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func-i32" (func (result i32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func-i32" (func (param f32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func-i32" (func (param i64))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func-i32" (func (param i32) (result i32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func->i32" (func)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func->i32" (func (param i32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func->i32" (func (result f32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func->i32" (func (result i64))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func->i32" (func (param i32) (result i32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func-i32->i32" (func)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func-i32->i32" (func (param i32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "func-i32->i32" (func (result i32))))
  "type mismatch"
)

(assert_unlinkable
  (module (import "test" "global-i32" (func (result i32))))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "table-10-inf" (func)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "memory-2-inf" (func)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "spectest" "global" (func)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "spectest" "table" (func)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "spectest" "memory" (func)))
  "type mismatch"
)


;; Globals

(module
  (import "spectest" "global" (global i32))
  (global (import "spectest" "global") i32)

  (import "spectest" "global" (global $x i32))
  (global $y (import "spectest" "global") i32)

  ;; limitation of the spidermonkey testing mode (an imported global can't be both a number and i64).
  ;;(import "spectest" "global" (global i64))
  (import "spectest" "global" (global f32))
  (import "spectest" "global" (global f64))

  (func (export "get-0") (result i32) (get_global 0))
  (func (export "get-1") (result i32) (get_global 1))
  (func (export "get-x") (result i32) (get_global $x))
  (func (export "get-y") (result i32) (get_global $y))
)

(assert_return (invoke "get-0") (i32.const 666))
(assert_return (invoke "get-1") (i32.const 666))
(assert_return (invoke "get-x") (i32.const 666))
(assert_return (invoke "get-y") (i32.const 666))

(module (import "test" "global-i32" (global i32)))
(module (import "test" "global-f32" (global f32)))

(assert_unlinkable
  (module (import "test" "unknown" (global i32)))
  "unknown import"
)
(assert_unlinkable
  (module (import "spectest" "unknown" (global i32)))
  "unknown import"
)

(assert_unlinkable
  (module (import "test" "func" (global i32)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "table-10-inf" (global i32)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "memory-2-inf" (global i32)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "spectest" "print" (global i32)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "spectest" "table" (global i32)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "spectest" "memory" (global i32)))
  "type mismatch"
)


;; Tables

(module
  (type (func (result i32)))
  (import "spectest" "table" (table 10 20 anyfunc))
  (elem 0 (i32.const 1) $f $g)

  (func (export "call") (param i32) (result i32) (call_indirect 0 (get_local 0)))
  (func $f (result i32) (i32.const 11))
  (func $g (result i32) (i32.const 22))
)

(assert_trap (invoke "call" (i32.const 0)) "uninitialized element")
(assert_return (invoke "call" (i32.const 1)) (i32.const 11))
(assert_return (invoke "call" (i32.const 2)) (i32.const 22))
(assert_trap (invoke "call" (i32.const 3)) "uninitialized element")
(assert_trap (invoke "call" (i32.const 100)) "undefined element")


(module
  (type (func (result i32)))
  (table (import "spectest" "table") 10 20 anyfunc)
  (elem 0 (i32.const 1) $f $g)

  (func (export "call") (param i32) (result i32) (call_indirect 0 (get_local 0)))
  (func $f (result i32) (i32.const 11))
  (func $g (result i32) (i32.const 22))
)

(assert_trap (invoke "call" (i32.const 0)) "uninitialized element")
(assert_return (invoke "call" (i32.const 1)) (i32.const 11))
(assert_return (invoke "call" (i32.const 2)) (i32.const 22))
(assert_trap (invoke "call" (i32.const 3)) "uninitialized element")
(assert_trap (invoke "call" (i32.const 100)) "undefined element")


(assert_invalid
  (module (import "" "" (table 10 anyfunc)) (import "" "" (table 10 anyfunc)))
  "multiple tables"
)
(assert_invalid
  (module (import "" "" (table 10 anyfunc)) (table 10 anyfunc))
  "multiple tables"
)
(assert_invalid
  (module (table 10 anyfunc) (table 10 anyfunc))
  "multiple tables"
)

(module (import "test" "table-10-inf" (table 10 anyfunc)))
(module (import "test" "table-10-inf" (table 5 anyfunc)))
(module (import "test" "table-10-inf" (table 0 anyfunc)))
(module (import "spectest" "table" (table 10 anyfunc)))
(module (import "spectest" "table" (table 5 anyfunc)))
(module (import "spectest" "table" (table 0 anyfunc)))
(module (import "spectest" "table" (table 10 20 anyfunc)))
(module (import "spectest" "table" (table 5 20 anyfunc)))
(module (import "spectest" "table" (table 0 20 anyfunc)))
(module (import "spectest" "table" (table 10 25 anyfunc)))
(module (import "spectest" "table" (table 5 25 anyfunc)))

(assert_unlinkable
  (module (import "test" "unknown" (table 10 anyfunc)))
  "unknown import"
)
(assert_unlinkable
  (module (import "spectest" "unknown" (table 10 anyfunc)))
  "unknown import"
)

(assert_unlinkable
  (module (import "test" "table-10-inf" (table 12 anyfunc)))
  "actual size smaller than declared"
)
(assert_unlinkable
  (module (import "test" "table-10-inf" (table 10 20 anyfunc)))
  "maximum size larger than declared"
)
(assert_unlinkable
  (module (import "spectest" "table" (table 12 anyfunc)))
  "actual size smaller than declared"
)
(assert_unlinkable
  (module (import "spectest" "table" (table 10 15 anyfunc)))
  "maximum size larger than declared"
)

(assert_unlinkable
  (module (import "test" "func" (table 10 anyfunc)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "global-i32" (table 10 anyfunc)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "memory-2-inf" (table 10 anyfunc)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "spectest" "print" (table 10 anyfunc)))
  "type mismatch"
)



;; Memories

(module
  (import "spectest" "memory" (memory 1 2))
  (data 0 (i32.const 10) "\10")

  (func (export "load") (param i32) (result i32) (i32.load (get_local 0)))
)

(assert_return (invoke "load" (i32.const 0)) (i32.const 0))
(assert_return (invoke "load" (i32.const 10)) (i32.const 16))
(assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000))
(assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access")

(module
  (memory (import "spectest" "memory") 1 2)
  (data 0 (i32.const 10) "\10")

  (func (export "load") (param i32) (result i32) (i32.load (get_local 0)))
)
(assert_return (invoke "load" (i32.const 0)) (i32.const 0))
(assert_return (invoke "load" (i32.const 10)) (i32.const 16))
(assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000))
(assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access")

(assert_invalid
  (module (import "" "" (memory 1)) (import "" "" (memory 1)))
  "multiple memories"
)
(assert_invalid
  (module (import "" "" (memory 1)) (memory 0))
  "multiple memories"
)
(assert_invalid
  (module (memory 0) (memory 0))
  "multiple memories"
)

(module (import "test" "memory-2-inf" (memory 2)))
(module (import "test" "memory-2-inf" (memory 1)))
(module (import "test" "memory-2-inf" (memory 0)))
(module (import "spectest" "memory" (memory 1)))
(module (import "spectest" "memory" (memory 0)))
(module (import "spectest" "memory" (memory 1 2)))
(module (import "spectest" "memory" (memory 0 2)))
(module (import "spectest" "memory" (memory 1 3)))
(module (import "spectest" "memory" (memory 0 3)))

(assert_unlinkable
  (module (import "test" "unknown" (memory 1)))
  "unknown import"
)
(assert_unlinkable
  (module (import "spectest" "unknown" (memory 1)))
  "unknown import"
)

(assert_unlinkable
  (module (import "test" "memory-2-inf" (memory 3)))
  "actual size smaller than declared"
)
(assert_unlinkable
  (module (import "test" "memory-2-inf" (memory 2 3)))
  "maximum size larger than declared"
)
(assert_unlinkable
  (module (import "spectest" "memory" (memory 2)))
  "actual size smaller than declared"
)
(assert_unlinkable
  (module (import "spectest" "memory" (memory 1 1)))
  "maximum size larger than declared"
)

(assert_unlinkable
  (module (import "test" "func-i32" (memory 1)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "global-i32" (memory 1)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "test" "table-10-inf" (memory 1)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "spectest" "print" (memory 1)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "spectest" "global" (memory 1)))
  "type mismatch"
)
(assert_unlinkable
  (module (import "spectest" "table" (memory 1)))
  "type mismatch"
)

(assert_unlinkable
  (module (import "spectest" "memory" (memory 2)))
  "actual size smaller than declared"
)
(assert_unlinkable
  (module (import "spectest" "memory" (memory 1 1)))
  "maximum size larger than declared"
)

(module
  (import "spectest" "memory" (memory 0 3))  ;; actual has max size 2
  (func (export "grow") (param i32) (result i32) (grow_memory (get_local 0)))
)
(assert_return (invoke "grow" (i32.const 0)) (i32.const 1))
(assert_return (invoke "grow" (i32.const 1)) (i32.const 1))
(assert_return (invoke "grow" (i32.const 0)) (i32.const 2))
(assert_return (invoke "grow" (i32.const 1)) (i32.const -1))
(assert_return (invoke "grow" (i32.const 0)) (i32.const 2))