github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/integration_test/spectest/v2/testdata/table_grow.wast (about)

     1  (module
     2    (table $t 0 externref)
     3  
     4    (func (export "get") (param $i i32) (result externref) (table.get $t (local.get $i)))
     5    (func (export "set") (param $i i32) (param $r externref) (table.set $t (local.get $i) (local.get $r)))
     6  
     7    (func (export "grow") (param $sz i32) (param $init externref) (result i32)
     8      (table.grow $t (local.get $init) (local.get $sz))
     9    )
    10    (func (export "grow-abbrev") (param $sz i32) (param $init externref) (result i32)
    11      (table.grow (local.get $init) (local.get $sz))
    12    )
    13    (func (export "size") (result i32) (table.size $t))
    14  )
    15  
    16  (assert_return (invoke "size") (i32.const 0))
    17  (assert_trap (invoke "set" (i32.const 0) (ref.extern 2)) "out of bounds table access")
    18  (assert_trap (invoke "get" (i32.const 0)) "out of bounds table access")
    19  
    20  (assert_return (invoke "grow" (i32.const 1) (ref.null extern)) (i32.const 0))
    21  (assert_return (invoke "size") (i32.const 1))
    22  (assert_return (invoke "get" (i32.const 0)) (ref.null extern))
    23  (assert_return (invoke "set" (i32.const 0) (ref.extern 2)))
    24  (assert_return (invoke "get" (i32.const 0)) (ref.extern 2))
    25  (assert_trap (invoke "set" (i32.const 1) (ref.extern 2)) "out of bounds table access")
    26  (assert_trap (invoke "get" (i32.const 1)) "out of bounds table access")
    27  
    28  (assert_return (invoke "grow-abbrev" (i32.const 4) (ref.extern 3)) (i32.const 1))
    29  (assert_return (invoke "size") (i32.const 5))
    30  (assert_return (invoke "get" (i32.const 0)) (ref.extern 2))
    31  (assert_return (invoke "set" (i32.const 0) (ref.extern 2)))
    32  (assert_return (invoke "get" (i32.const 0)) (ref.extern 2))
    33  (assert_return (invoke "get" (i32.const 1)) (ref.extern 3))
    34  (assert_return (invoke "get" (i32.const 4)) (ref.extern 3))
    35  (assert_return (invoke "set" (i32.const 4) (ref.extern 4)))
    36  (assert_return (invoke "get" (i32.const 4)) (ref.extern 4))
    37  (assert_trap (invoke "set" (i32.const 5) (ref.extern 2)) "out of bounds table access")
    38  (assert_trap (invoke "get" (i32.const 5)) "out of bounds table access")
    39  
    40  
    41  ;; Reject growing to size outside i32 value range
    42  (module
    43    (table $t 0x10 funcref)
    44    (elem declare func $f)
    45    (func $f (export "grow") (result i32)
    46      (table.grow $t (ref.func $f) (i32.const 0xffff_fff0))
    47    )
    48  )
    49  
    50  (assert_return (invoke "grow") (i32.const -1))
    51  
    52  
    53  (module
    54    (table $t 0 externref)
    55    (func (export "grow") (param i32) (result i32)
    56      (table.grow $t (ref.null extern) (local.get 0))
    57    )
    58  )
    59  
    60  (assert_return (invoke "grow" (i32.const 0)) (i32.const 0))
    61  (assert_return (invoke "grow" (i32.const 1)) (i32.const 0))
    62  (assert_return (invoke "grow" (i32.const 0)) (i32.const 1))
    63  (assert_return (invoke "grow" (i32.const 2)) (i32.const 1))
    64  (assert_return (invoke "grow" (i32.const 800)) (i32.const 3))
    65  
    66  
    67  (module
    68    (table $t 0 10 externref)
    69    (func (export "grow") (param i32) (result i32)
    70      (table.grow $t (ref.null extern) (local.get 0))
    71    )
    72  )
    73  
    74  (assert_return (invoke "grow" (i32.const 0)) (i32.const 0))
    75  (assert_return (invoke "grow" (i32.const 1)) (i32.const 0))
    76  (assert_return (invoke "grow" (i32.const 1)) (i32.const 1))
    77  (assert_return (invoke "grow" (i32.const 2)) (i32.const 2))
    78  (assert_return (invoke "grow" (i32.const 6)) (i32.const 4))
    79  (assert_return (invoke "grow" (i32.const 0)) (i32.const 10))
    80  (assert_return (invoke "grow" (i32.const 1)) (i32.const -1))
    81  (assert_return (invoke "grow" (i32.const 0x10000)) (i32.const -1))
    82  
    83  
    84  (module
    85    (table $t 10 funcref)
    86    (func (export "grow") (param i32) (result i32)
    87      (table.grow $t (ref.null func) (local.get 0))
    88    )
    89    (elem declare func 1)
    90    (func (export "check-table-null") (param i32 i32) (result funcref)
    91      (local funcref)
    92      (local.set 2 (ref.func 1))
    93      (block
    94        (loop
    95          (local.set 2 (table.get $t (local.get 0)))
    96          (br_if 1 (i32.eqz (ref.is_null (local.get 2))))
    97          (br_if 1 (i32.ge_u (local.get 0) (local.get 1)))
    98          (local.set 0 (i32.add (local.get 0) (i32.const 1)))
    99          (br_if 0 (i32.le_u (local.get 0) (local.get 1)))
   100        )
   101      )
   102      (local.get 2)
   103    )
   104  )
   105  
   106  (assert_return (invoke "check-table-null" (i32.const 0) (i32.const 9)) (ref.null func))
   107  (assert_return (invoke "grow" (i32.const 10)) (i32.const 10))
   108  (assert_return (invoke "check-table-null" (i32.const 0) (i32.const 19)) (ref.null func))
   109  
   110  
   111  ;; Type errors
   112  
   113  (assert_invalid
   114    (module
   115      (table $t 0 externref)
   116      (func $type-init-size-empty-vs-i32-externref (result i32)
   117        (table.grow $t)
   118      )
   119    )
   120    "type mismatch"
   121  )
   122  (assert_invalid
   123    (module
   124      (table $t 0 externref)
   125      (func $type-size-empty-vs-i32 (result i32)
   126        (table.grow $t (ref.null extern))
   127      )
   128    )
   129    "type mismatch"
   130  )
   131  (assert_invalid
   132    (module
   133      (table $t 0 externref)
   134      (func $type-init-empty-vs-externref (result i32)
   135        (table.grow $t (i32.const 1))
   136      )
   137    )
   138    "type mismatch"
   139  )
   140  (assert_invalid
   141    (module
   142      (table $t 0 externref)
   143      (func $type-size-f32-vs-i32 (result i32)
   144        (table.grow $t (ref.null extern) (f32.const 1))
   145      )
   146    )
   147    "type mismatch"
   148  )
   149  (assert_invalid
   150    (module
   151      (table $t 0 funcref)
   152      (func $type-init-externref-vs-funcref (param $r externref) (result i32)
   153        (table.grow $t (local.get $r) (i32.const 1))
   154      )
   155    )
   156    "type mismatch"
   157  )
   158  
   159  (assert_invalid
   160    (module
   161      (table $t 1 externref)
   162      (func $type-result-i32-vs-empty
   163        (table.grow $t (ref.null extern) (i32.const 0))
   164      )
   165    )
   166    "type mismatch"
   167  )
   168  (assert_invalid
   169    (module
   170      (table $t 1 externref)
   171      (func $type-result-i32-vs-f32 (result f32)
   172        (table.grow $t (ref.null extern) (i32.const 0))
   173      )
   174    )
   175    "type mismatch"
   176  )