summaryrefslogtreecommitdiff
path: root/test/spec/array-new-elem.wast
blob: e5089b69cd429dce84f814a983040fd121666d7e (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
(module
  (type $vec (array funcref))
  (type $mvec (array (mut funcref)))
  (type $f (func (result i32)))

  (elem func $ret0 $ret1 $ret2 $ret3 $ret4)

  (func $ret0 (type $f) (i32.const 0))
  (func $ret1 (type $f) (i32.const 1))
  (func $ret2 (type $f) (i32.const 2))
  (func $ret3 (type $f) (i32.const 3))
  (func $ret4 (type $f) (i32.const 4))

  (func $new (export "new") (result (ref $vec))
    (array.new_elem $vec 0 (i32.const 1) (i32.const 3))
  )

  (func $get (param $i i32) (param $v (ref $vec)) (result i32)
    (call_ref $f (ref.cast (ref null $f) (array.get $vec (local.get $v) (local.get $i))))
  )
  (func (export "get") (param $i i32) (result i32)
    (call $get (local.get $i) (call $new))
  )

  (func $set_get (param $i i32) (param $v (ref $mvec)) (param $y i32) (result i32)
    (array.set $mvec (local.get $v) (local.get $i) (array.get $mvec (local.get $v) (local.get $y)))
    (call_ref $f (ref.cast (ref null $f) (array.get $mvec (local.get $v) (local.get $i))))
  )
  (func (export "set_get") (param $i i32) (param $y i32) (result i32)
    (call $set_get
      (local.get $i)
      (array.new_elem $mvec 0 (i32.const 1) (i32.const 3))
      (local.get $y)
    )
  )

  (func $len (param $v (ref array)) (result i32)
    (array.len (local.get $v))
  )
  (func (export "len") (result i32)
    (call $len (call $new))
  )
)

(assert_return (invoke "get" (i32.const 0)) (i32.const 1))
(assert_return (invoke "get" (i32.const 1)) (i32.const 2))
(assert_return (invoke "set_get" (i32.const 0) (i32.const 2)) (i32.const 3))
(assert_return (invoke "len") (i32.const 3))

(module
  (type $vec (array funcref))

  (elem func)

  (func $new-huge (export "new-huge") (result (ref $vec))
    (array.new_elem $vec 0 (i32.const 1) (i32.const -1))
  )
)

(assert_trap (invoke "new-huge") "out of bounds segment access in array.new_data")