github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/integration_test/spectest/v2/testdata/table_set.wast (about)

     1  (module
     2    (table $t2 1 externref)
     3    (table $t3 2 funcref)
     4    (elem (table $t3) (i32.const 1) func $dummy)
     5    (func $dummy)
     6  
     7    (func (export "get-externref") (param $i i32) (result externref)
     8      (table.get $t2 (local.get $i))
     9    )
    10    (func $f3 (export "get-funcref") (param $i i32) (result funcref)
    11      (table.get $t3 (local.get $i))
    12    )
    13  
    14    (func (export "set-externref") (param $i i32) (param $r externref)
    15      (table.set $t2 (local.get $i) (local.get $r))
    16    )
    17    (func (export "set-funcref") (param $i i32) (param $r funcref)
    18      (table.set $t3 (local.get $i) (local.get $r))
    19    )
    20    (func (export "set-funcref-from") (param $i i32) (param $j i32)
    21      (table.set $t3 (local.get $i) (table.get $t3 (local.get $j)))
    22    )
    23  
    24    (func (export "is_null-funcref") (param $i i32) (result i32)
    25      (ref.is_null (call $f3 (local.get $i)))
    26    )
    27  )
    28  
    29  (assert_return (invoke "get-externref" (i32.const 0)) (ref.null extern))
    30  (assert_return (invoke "set-externref" (i32.const 0) (ref.extern 1)))
    31  (assert_return (invoke "get-externref" (i32.const 0)) (ref.extern 1))
    32  (assert_return (invoke "set-externref" (i32.const 0) (ref.null extern)))
    33  (assert_return (invoke "get-externref" (i32.const 0)) (ref.null extern))
    34  
    35  (assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func))
    36  (assert_return (invoke "set-funcref-from" (i32.const 0) (i32.const 1)))
    37  (assert_return (invoke "is_null-funcref" (i32.const 0)) (i32.const 0))
    38  (assert_return (invoke "set-funcref" (i32.const 0) (ref.null func)))
    39  (assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func))
    40  
    41  (assert_trap (invoke "set-externref" (i32.const 2) (ref.null extern)) "out of bounds table access")
    42  (assert_trap (invoke "set-funcref" (i32.const 3) (ref.null func)) "out of bounds table access")
    43  (assert_trap (invoke "set-externref" (i32.const -1) (ref.null extern)) "out of bounds table access")
    44  (assert_trap (invoke "set-funcref" (i32.const -1) (ref.null func)) "out of bounds table access")
    45  
    46  (assert_trap (invoke "set-externref" (i32.const 2) (ref.extern 0)) "out of bounds table access")
    47  (assert_trap (invoke "set-funcref-from" (i32.const 3) (i32.const 1)) "out of bounds table access")
    48  (assert_trap (invoke "set-externref" (i32.const -1) (ref.extern 0)) "out of bounds table access")
    49  (assert_trap (invoke "set-funcref-from" (i32.const -1) (i32.const 1)) "out of bounds table access")
    50  
    51  
    52  ;; Type errors
    53  
    54  (assert_invalid
    55    (module
    56      (table $t 10 externref)
    57      (func $type-index-value-empty-vs-i32-externref
    58        (table.set $t)
    59      )
    60    )
    61    "type mismatch"
    62  )
    63  (assert_invalid
    64    (module
    65      (table $t 10 externref)
    66      (func $type-index-empty-vs-i32
    67        (table.set $t (ref.null extern))
    68      )
    69    )
    70    "type mismatch"
    71  )
    72  (assert_invalid
    73    (module
    74      (table $t 10 externref)
    75      (func $type-value-empty-vs-externref
    76        (table.set $t (i32.const 1))
    77      )
    78    )
    79    "type mismatch"
    80  )
    81  (assert_invalid
    82    (module
    83      (table $t 10 externref)
    84      (func $type-size-f32-vs-i32
    85        (table.set $t (f32.const 1) (ref.null extern))
    86      )
    87    )
    88    "type mismatch"
    89  )
    90  (assert_invalid
    91    (module
    92      (table $t 10 funcref)
    93      (func $type-value-externref-vs-funcref (param $r externref)
    94        (table.set $t (i32.const 1) (local.get $r))
    95      )
    96    )
    97    "type mismatch"
    98  )
    99  
   100  (assert_invalid
   101    (module
   102      (table $t1 1 externref)
   103      (table $t2 1 funcref)
   104      (func $type-value-externref-vs-funcref-multi (param $r externref)
   105        (table.set $t2 (i32.const 0) (local.get $r))
   106      )
   107    )
   108    "type mismatch"
   109  )
   110  
   111  (assert_invalid
   112    (module
   113      (table $t 10 externref)
   114      (func $type-result-empty-vs-num (result i32)
   115        (table.set $t (i32.const 0) (ref.null extern))
   116      )
   117    )
   118    "type mismatch"
   119  )