Debian Codegraph @

js/src/jit-test/tests/wasm/spec/exception-handling/memory_grow.wast.js

raw
1 /* Copyright 2021 Mozilla Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 // ./test/core/memory_grow.wast
17
18 // ./test/core/memory_grow.wast:1
19 let $0 = instantiate(`(module
20 (memory 0)
21
22 (func (export "load_at_zero") (result i32) (i32.load (i32.const 0)))
23 (func (export "store_at_zero") (i32.store (i32.const 0) (i32.const 2)))
24
25 (func (export "load_at_page_size") (result i32) (i32.load (i32.const 0x10000)))
26 (func (export "store_at_page_size") (i32.store (i32.const 0x10000) (i32.const 3)))
27
28 (func (export "grow") (param $$sz i32) (result i32) (memory.grow (local.get $$sz)))
29 (func (export "size") (result i32) (memory.size))
30 )`);
31
32 // ./test/core/memory_grow.wast:14
33 assert_return(() => invoke($0, `size`, []), [value("i32", 0)]);
34
35 // ./test/core/memory_grow.wast:15
36 assert_trap(() => invoke($0, `store_at_zero`, []), `out of bounds memory access`);
37
38 // ./test/core/memory_grow.wast:16
39 assert_trap(() => invoke($0, `load_at_zero`, []), `out of bounds memory access`);
40
41 // ./test/core/memory_grow.wast:17
42 assert_trap(() => invoke($0, `store_at_page_size`, []), `out of bounds memory access`);
43
44 // ./test/core/memory_grow.wast:18
45 assert_trap(() => invoke($0, `load_at_page_size`, []), `out of bounds memory access`);
46
47 // ./test/core/memory_grow.wast:19
48 assert_return(() => invoke($0, `grow`, [1]), [value("i32", 0)]);
49
50 // ./test/core/memory_grow.wast:20
51 assert_return(() => invoke($0, `size`, []), [value("i32", 1)]);
52
53 // ./test/core/memory_grow.wast:21
54 assert_return(() => invoke($0, `load_at_zero`, []), [value("i32", 0)]);
55
56 // ./test/core/memory_grow.wast:22
57 assert_return(() => invoke($0, `store_at_zero`, []), []);
58
59 // ./test/core/memory_grow.wast:23
60 assert_return(() => invoke($0, `load_at_zero`, []), [value("i32", 2)]);
61
62 // ./test/core/memory_grow.wast:24
63 assert_trap(() => invoke($0, `store_at_page_size`, []), `out of bounds memory access`);
64
65 // ./test/core/memory_grow.wast:25
66 assert_trap(() => invoke($0, `load_at_page_size`, []), `out of bounds memory access`);
67
68 // ./test/core/memory_grow.wast:26
69 assert_return(() => invoke($0, `grow`, [4]), [value("i32", 1)]);
70
71 // ./test/core/memory_grow.wast:27
72 assert_return(() => invoke($0, `size`, []), [value("i32", 5)]);
73
74 // ./test/core/memory_grow.wast:28
75 assert_return(() => invoke($0, `load_at_zero`, []), [value("i32", 2)]);
76
77 // ./test/core/memory_grow.wast:29
78 assert_return(() => invoke($0, `store_at_zero`, []), []);
79
80 // ./test/core/memory_grow.wast:30
81 assert_return(() => invoke($0, `load_at_zero`, []), [value("i32", 2)]);
82
83 // ./test/core/memory_grow.wast:31
84 assert_return(() => invoke($0, `load_at_page_size`, []), [value("i32", 0)]);
85
86 // ./test/core/memory_grow.wast:32
87 assert_return(() => invoke($0, `store_at_page_size`, []), []);
88
89 // ./test/core/memory_grow.wast:33
90 assert_return(() => invoke($0, `load_at_page_size`, []), [value("i32", 3)]);
91
92 // ./test/core/memory_grow.wast:36
93 let $1 = instantiate(`(module
94 (memory 0)
95 (func (export "grow") (param i32) (result i32) (memory.grow (local.get 0)))
96 )`);
97
98 // ./test/core/memory_grow.wast:41
99 assert_return(() => invoke($1, `grow`, [0]), [value("i32", 0)]);
100
101 // ./test/core/memory_grow.wast:42
102 assert_return(() => invoke($1, `grow`, [1]), [value("i32", 0)]);
103
104 // ./test/core/memory_grow.wast:43
105 assert_return(() => invoke($1, `grow`, [0]), [value("i32", 1)]);
106
107 // ./test/core/memory_grow.wast:44
108 assert_return(() => invoke($1, `grow`, [2]), [value("i32", 1)]);
109
110 // ./test/core/memory_grow.wast:45
111 assert_return(() => invoke($1, `grow`, [800]), [value("i32", 3)]);
112
113 // ./test/core/memory_grow.wast:46
114 assert_return(() => invoke($1, `grow`, [65536]), [value("i32", -1)]);
115
116 // ./test/core/memory_grow.wast:47
117 assert_return(() => invoke($1, `grow`, [64736]), [value("i32", -1)]);
118
119 // ./test/core/memory_grow.wast:48
120 assert_return(() => invoke($1, `grow`, [1]), [value("i32", 803)]);
121
122 // ./test/core/memory_grow.wast:50
123 let $2 = instantiate(`(module
124 (memory 0 10)
125 (func (export "grow") (param i32) (result i32) (memory.grow (local.get 0)))
126 )`);
127
128 // ./test/core/memory_grow.wast:55
129 assert_return(() => invoke($2, `grow`, [0]), [value("i32", 0)]);
130
131 // ./test/core/memory_grow.wast:56
132 assert_return(() => invoke($2, `grow`, [1]), [value("i32", 0)]);
133
134 // ./test/core/memory_grow.wast:57
135 assert_return(() => invoke($2, `grow`, [1]), [value("i32", 1)]);
136
137 // ./test/core/memory_grow.wast:58
138 assert_return(() => invoke($2, `grow`, [2]), [value("i32", 2)]);
139
140 // ./test/core/memory_grow.wast:59
141 assert_return(() => invoke($2, `grow`, [6]), [value("i32", 4)]);
142
143 // ./test/core/memory_grow.wast:60
144 assert_return(() => invoke($2, `grow`, [0]), [value("i32", 10)]);
145
146 // ./test/core/memory_grow.wast:61
147 assert_return(() => invoke($2, `grow`, [1]), [value("i32", -1)]);
148
149 // ./test/core/memory_grow.wast:62
150 assert_return(() => invoke($2, `grow`, [65536]), [value("i32", -1)]);
151
152 // ./test/core/memory_grow.wast:66
153 let $3 = instantiate(`(module
154 (memory 1)
155 (func (export "grow") (param i32) (result i32)
156 (memory.grow (local.get 0))
157 )
158 (func (export "check-memory-zero") (param i32 i32) (result i32)
159 (local i32)
160 (local.set 2 (i32.const 1))
161 (block
162 (loop
163 (local.set 2 (i32.load8_u (local.get 0)))
164 (br_if 1 (i32.ne (local.get 2) (i32.const 0)))
165 (br_if 1 (i32.ge_u (local.get 0) (local.get 1)))
166 (local.set 0 (i32.add (local.get 0) (i32.const 1)))
167 (br_if 0 (i32.le_u (local.get 0) (local.get 1)))
168 )
169 )
170 (local.get 2)
171 )
172 )`);
173
174 // ./test/core/memory_grow.wast:87
175 assert_return(() => invoke($3, `check-memory-zero`, [0, 65535]), [value("i32", 0)]);
176
177 // ./test/core/memory_grow.wast:88
178 assert_return(() => invoke($3, `grow`, [1]), [value("i32", 1)]);
179
180 // ./test/core/memory_grow.wast:89
181 assert_return(() => invoke($3, `check-memory-zero`, [65536, 131071]), [value("i32", 0)]);
182
183 // ./test/core/memory_grow.wast:90
184 assert_return(() => invoke($3, `grow`, [1]), [value("i32", 2)]);
185
186 // ./test/core/memory_grow.wast:91
187 assert_return(() => invoke($3, `check-memory-zero`, [131072, 196607]), [value("i32", 0)]);
188
189 // ./test/core/memory_grow.wast:92
190 assert_return(() => invoke($3, `grow`, [1]), [value("i32", 3)]);
191
192 // ./test/core/memory_grow.wast:93
193 assert_return(() => invoke($3, `check-memory-zero`, [196608, 262143]), [value("i32", 0)]);
194
195 // ./test/core/memory_grow.wast:94
196 assert_return(() => invoke($3, `grow`, [1]), [value("i32", 4)]);
197
198 // ./test/core/memory_grow.wast:95
199 assert_return(() => invoke($3, `check-memory-zero`, [262144, 327679]), [value("i32", 0)]);
200
201 // ./test/core/memory_grow.wast:96
202 assert_return(() => invoke($3, `grow`, [1]), [value("i32", 5)]);
203
204 // ./test/core/memory_grow.wast:97
205 assert_return(() => invoke($3, `check-memory-zero`, [327680, 393215]), [value("i32", 0)]);
206
207 // ./test/core/memory_grow.wast:101
208 let $4 = instantiate(`(module
209 (memory 1)
210
211 (func (export "as-br-value") (result i32)
212 (block (result i32) (br 0 (memory.grow (i32.const 0))))
213 )
214
215 (func (export "as-br_if-cond")
216 (block (br_if 0 (memory.grow (i32.const 0))))
217 )
218 (func (export "as-br_if-value") (result i32)
219 (block (result i32)
220 (drop (br_if 0 (memory.grow (i32.const 0)) (i32.const 1))) (i32.const 7)
221 )
222 )
223 (func (export "as-br_if-value-cond") (result i32)
224 (block (result i32)
225 (drop (br_if 0 (i32.const 6) (memory.grow (i32.const 0)))) (i32.const 7)
226 )
227 )
228
229 (func (export "as-br_table-index")
230 (block (br_table 0 0 0 (memory.grow (i32.const 0))))
231 )
232 (func (export "as-br_table-value") (result i32)
233 (block (result i32)
234 (br_table 0 0 0 (memory.grow (i32.const 0)) (i32.const 1)) (i32.const 7)
235 )
236 )
237 (func (export "as-br_table-value-index") (result i32)
238 (block (result i32)
239 (br_table 0 0 (i32.const 6) (memory.grow (i32.const 0))) (i32.const 7)
240 )
241 )
242
243 (func (export "as-return-value") (result i32)
244 (return (memory.grow (i32.const 0)))
245 )
246
247 (func (export "as-if-cond") (result i32)
248 (if (result i32) (memory.grow (i32.const 0))
249 (then (i32.const 0)) (else (i32.const 1))
250 )
251 )
252 (func (export "as-if-then") (result i32)
253 (if (result i32) (i32.const 1)
254 (then (memory.grow (i32.const 0))) (else (i32.const 0))
255 )
256 )
257 (func (export "as-if-else") (result i32)
258 (if (result i32) (i32.const 0)
259 (then (i32.const 0)) (else (memory.grow (i32.const 0)))
260 )
261 )
262
263 (func (export "as-select-first") (param i32 i32) (result i32)
264 (select (memory.grow (i32.const 0)) (local.get 0) (local.get 1))
265 )
266 (func (export "as-select-second") (param i32 i32) (result i32)
267 (select (local.get 0) (memory.grow (i32.const 0)) (local.get 1))
268 )
269 (func (export "as-select-cond") (result i32)
270 (select (i32.const 0) (i32.const 1) (memory.grow (i32.const 0)))
271 )
272
273 (func $$f (param i32 i32 i32) (result i32) (i32.const -1))
274 (func (export "as-call-first") (result i32)
275 (call $$f (memory.grow (i32.const 0)) (i32.const 2) (i32.const 3))
276 )
277 (func (export "as-call-mid") (result i32)
278 (call $$f (i32.const 1) (memory.grow (i32.const 0)) (i32.const 3))
279 )
280 (func (export "as-call-last") (result i32)
281 (call $$f (i32.const 1) (i32.const 2) (memory.grow (i32.const 0)))
282 )
283
284 (type $$sig (func (param i32 i32 i32) (result i32)))
285 (table funcref (elem $$f))
286 (func (export "as-call_indirect-first") (result i32)
287 (call_indirect (type $$sig)
288 (memory.grow (i32.const 0)) (i32.const 2) (i32.const 3) (i32.const 0)
289 )
290 )
291 (func (export "as-call_indirect-mid") (result i32)
292 (call_indirect (type $$sig)
293 (i32.const 1) (memory.grow (i32.const 0)) (i32.const 3) (i32.const 0)
294 )
295 )
296 (func (export "as-call_indirect-last") (result i32)
297 (call_indirect (type $$sig)
298 (i32.const 1) (i32.const 2) (memory.grow (i32.const 0)) (i32.const 0)
299 )
300 )
301 (func (export "as-call_indirect-index") (result i32)
302 (call_indirect (type $$sig)
303 (i32.const 1) (i32.const 2) (i32.const 3) (memory.grow (i32.const 0))
304 )
305 )
306
307 (func (export "as-local.set-value") (local i32)
308 (local.set 0 (memory.grow (i32.const 0)))
309 )
310 (func (export "as-local.tee-value") (result i32) (local i32)
311 (local.tee 0 (memory.grow (i32.const 0)))
312 )
313 (global $$g (mut i32) (i32.const 0))
314 (func (export "as-global.set-value") (local i32)
315 (global.set $$g (memory.grow (i32.const 0)))
316 )
317
318 (func (export "as-load-address") (result i32)
319 (i32.load (memory.grow (i32.const 0)))
320 )
321 (func (export "as-loadN-address") (result i32)
322 (i32.load8_s (memory.grow (i32.const 0)))
323 )
324
325 (func (export "as-store-address")
326 (i32.store (memory.grow (i32.const 0)) (i32.const 7))
327 )
328 (func (export "as-store-value")
329 (i32.store (i32.const 2) (memory.grow (i32.const 0)))
330 )
331
332 (func (export "as-storeN-address")
333 (i32.store8 (memory.grow (i32.const 0)) (i32.const 7))
334 )
335 (func (export "as-storeN-value")
336 (i32.store16 (i32.const 2) (memory.grow (i32.const 0)))
337 )
338
339 (func (export "as-unary-operand") (result i32)
340 (i32.clz (memory.grow (i32.const 0)))
341 )
342
343 (func (export "as-binary-left") (result i32)
344 (i32.add (memory.grow (i32.const 0)) (i32.const 10))
345 )
346 (func (export "as-binary-right") (result i32)
347 (i32.sub (i32.const 10) (memory.grow (i32.const 0)))
348 )
349
350 (func (export "as-test-operand") (result i32)
351 (i32.eqz (memory.grow (i32.const 0)))
352 )
353
354 (func (export "as-compare-left") (result i32)
355 (i32.le_s (memory.grow (i32.const 0)) (i32.const 10))
356 )
357 (func (export "as-compare-right") (result i32)
358 (i32.ne (i32.const 10) (memory.grow (i32.const 0)))
359 )
360
361 (func (export "as-memory.grow-size") (result i32)
362 (memory.grow (memory.grow (i32.const 0)))
363 )
364 )`);
365
366 // ./test/core/memory_grow.wast:259
367 assert_return(() => invoke($4, `as-br-value`, []), [value("i32", 1)]);
368
369 // ./test/core/memory_grow.wast:261
370 assert_return(() => invoke($4, `as-br_if-cond`, []), []);
371
372 // ./test/core/memory_grow.wast:262
373 assert_return(() => invoke($4, `as-br_if-value`, []), [value("i32", 1)]);
374
375 // ./test/core/memory_grow.wast:263
376 assert_return(() => invoke($4, `as-br_if-value-cond`, []), [value("i32", 6)]);
377
378 // ./test/core/memory_grow.wast:265
379 assert_return(() => invoke($4, `as-br_table-index`, []), []);
380
381 // ./test/core/memory_grow.wast:266
382 assert_return(() => invoke($4, `as-br_table-value`, []), [value("i32", 1)]);
383
384 // ./test/core/memory_grow.wast:267
385 assert_return(() => invoke($4, `as-br_table-value-index`, []), [value("i32", 6)]);
386
387 // ./test/core/memory_grow.wast:269
388 assert_return(() => invoke($4, `as-return-value`, []), [value("i32", 1)]);
389
390 // ./test/core/memory_grow.wast:271
391 assert_return(() => invoke($4, `as-if-cond`, []), [value("i32", 0)]);
392
393 // ./test/core/memory_grow.wast:272
394 assert_return(() => invoke($4, `as-if-then`, []), [value("i32", 1)]);
395
396 // ./test/core/memory_grow.wast:273
397 assert_return(() => invoke($4, `as-if-else`, []), [value("i32", 1)]);
398
399 // ./test/core/memory_grow.wast:275
400 assert_return(() => invoke($4, `as-select-first`, [0, 1]), [value("i32", 1)]);
401
402 // ./test/core/memory_grow.wast:276
403 assert_return(() => invoke($4, `as-select-second`, [0, 0]), [value("i32", 1)]);
404
405 // ./test/core/memory_grow.wast:277
406 assert_return(() => invoke($4, `as-select-cond`, []), [value("i32", 0)]);
407
408 // ./test/core/memory_grow.wast:279
409 assert_return(() => invoke($4, `as-call-first`, []), [value("i32", -1)]);
410
411 // ./test/core/memory_grow.wast:280
412 assert_return(() => invoke($4, `as-call-mid`, []), [value("i32", -1)]);
413
414 // ./test/core/memory_grow.wast:281
415 assert_return(() => invoke($4, `as-call-last`, []), [value("i32", -1)]);
416
417 // ./test/core/memory_grow.wast:283
418 assert_return(() => invoke($4, `as-call_indirect-first`, []), [value("i32", -1)]);
419
420 // ./test/core/memory_grow.wast:284
421 assert_return(() => invoke($4, `as-call_indirect-mid`, []), [value("i32", -1)]);
422
423 // ./test/core/memory_grow.wast:285
424 assert_return(() => invoke($4, `as-call_indirect-last`, []), [value("i32", -1)]);
425
426 // ./test/core/memory_grow.wast:286
427 assert_trap(() => invoke($4, `as-call_indirect-index`, []), `undefined element`);
428
429 // ./test/core/memory_grow.wast:288
430 assert_return(() => invoke($4, `as-local.set-value`, []), []);
431
432 // ./test/core/memory_grow.wast:289
433 assert_return(() => invoke($4, `as-local.tee-value`, []), [value("i32", 1)]);
434
435 // ./test/core/memory_grow.wast:290
436 assert_return(() => invoke($4, `as-global.set-value`, []), []);
437
438 // ./test/core/memory_grow.wast:292
439 assert_return(() => invoke($4, `as-load-address`, []), [value("i32", 0)]);
440
441 // ./test/core/memory_grow.wast:293
442 assert_return(() => invoke($4, `as-loadN-address`, []), [value("i32", 0)]);
443
444 // ./test/core/memory_grow.wast:294
445 assert_return(() => invoke($4, `as-store-address`, []), []);
446
447 // ./test/core/memory_grow.wast:295
448 assert_return(() => invoke($4, `as-store-value`, []), []);
449
450 // ./test/core/memory_grow.wast:296
451 assert_return(() => invoke($4, `as-storeN-address`, []), []);
452
453 // ./test/core/memory_grow.wast:297
454 assert_return(() => invoke($4, `as-storeN-value`, []), []);
455
456 // ./test/core/memory_grow.wast:299
457 assert_return(() => invoke($4, `as-unary-operand`, []), [value("i32", 31)]);
458
459 // ./test/core/memory_grow.wast:301
460 assert_return(() => invoke($4, `as-binary-left`, []), [value("i32", 11)]);
461
462 // ./test/core/memory_grow.wast:302
463 assert_return(() => invoke($4, `as-binary-right`, []), [value("i32", 9)]);
464
465 // ./test/core/memory_grow.wast:304
466 assert_return(() => invoke($4, `as-test-operand`, []), [value("i32", 0)]);
467
468 // ./test/core/memory_grow.wast:306
469 assert_return(() => invoke($4, `as-compare-left`, []), [value("i32", 1)]);
470
471 // ./test/core/memory_grow.wast:307
472 assert_return(() => invoke($4, `as-compare-right`, []), [value("i32", 1)]);
473
474 // ./test/core/memory_grow.wast:309
475 assert_return(() => invoke($4, `as-memory.grow-size`, []), [value("i32", 1)]);
476
477 // ./test/core/memory_grow.wast:312
478 assert_invalid(
479 () => instantiate(`(module
480 (memory 0)
481 (func $$type-size-empty-vs-i32 (result i32)
482 (memory.grow)
483 )
484 )`),
485 `type mismatch`,
486 );
487
488 // ./test/core/memory_grow.wast:321
489 assert_invalid(
490 () => instantiate(`(module
491 (memory 0)
492 (func $$type-size-empty-vs-i32-in-block (result i32)
493 (i32.const 0)
494 (block (result i32) (memory.grow))
495 )
496 )`),
497 `type mismatch`,
498 );
499
500 // ./test/core/memory_grow.wast:331
501 assert_invalid(
502 () => instantiate(`(module
503 (memory 0)
504 (func $$type-size-empty-vs-i32-in-loop (result i32)
505 (i32.const 0)
506 (loop (result i32) (memory.grow))
507 )
508 )`),
509 `type mismatch`,
510 );
511
512 // ./test/core/memory_grow.wast:341
513 assert_invalid(
514 () => instantiate(`(module
515 (memory 0)
516 (func $$type-size-empty-vs-i32-in-then (result i32)
517 (i32.const 0) (i32.const 0)
518 (if (result i32) (then (memory.grow)))
519 )
520 )`),
521 `type mismatch`,
522 );
523
524 // ./test/core/memory_grow.wast:352
525 assert_invalid(
526 () => instantiate(`(module
527 (memory 1)
528 (func $$type-size-f32-vs-i32 (result i32)
529 (memory.grow (f32.const 0))
530 )
531 )`),
532 `type mismatch`,
533 );
534
535 // ./test/core/memory_grow.wast:362
536 assert_invalid(
537 () => instantiate(`(module
538 (memory 1)
539 (func $$type-result-i32-vs-empty
540 (memory.grow (i32.const 0))
541 )
542 )`),
543 `type mismatch`,
544 );
545
546 // ./test/core/memory_grow.wast:371
547 assert_invalid(
548 () => instantiate(`(module
549 (memory 1)
550 (func $$type-result-i32-vs-f32 (result f32)
551 (memory.grow (i32.const 0))
552 )
553 )`),
554 `type mismatch`,
555 );