Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion proposals/reference-types/elem.wast
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

;; Passive
(elem funcref)
(elem funcref (ref.func $f) (ref.func $f) (ref.null) (ref.func $g))
(elem funcref (ref.func $f) (item ref.func $f) (item (ref.null)) (ref.func $g))
(elem func)
(elem func $f $f $g $g)

Expand Down Expand Up @@ -63,6 +63,17 @@
(elem $a24 (i32.const 0) funcref (ref.func $f) (ref.null))
(elem $a25 (i32.const 0) func $f $f)
(elem $a26 (i32.const 0) $f $f)

;; Declarative
(elem declare funcref)
(elem declare funcref (ref.func $f) (ref.func $f) (ref.null) (ref.func $g))
(elem declare func)
(elem declare func $f $f $g $g)

(elem $d1 declare funcref)
(elem $d2 declare funcref (ref.func $f) (ref.func $f) (ref.null) (ref.func $g))
(elem $d3 declare func)
(elem $d4 declare func $f $f $g $g)
)

(module
Expand All @@ -71,6 +82,8 @@

(table $t funcref (elem (ref.func $f) (ref.null) (ref.func $g)))
)


;; Basic use

(module
Expand Down Expand Up @@ -294,6 +307,28 @@
"out of bounds"
)

;; Implicitly dropped elements

(module
(table 10 funcref)
(elem $e (i32.const 0) func $f)
(func $f)
(func (export "init")
(table.init $e (i32.const 0) (i32.const 0) (i32.const 1))
)
)
(assert_trap (invoke "init") "out of bounds")

(module
(table 10 funcref)
(elem $e declare func $f)
(func $f)
(func (export "init")
(table.init $e (i32.const 0) (i32.const 0) (i32.const 1))
)
)
(assert_trap (invoke "init") "out of bounds")

;; Element without table

(assert_invalid
Expand Down
1 change: 1 addition & 0 deletions proposals/reference-types/linking.wast
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"incompatible import type"
)


(assert_unlinkable
(module (global (import "Mref_ex" "g-var-null") (mut funcref)))
"incompatible import type"
Expand Down
24 changes: 23 additions & 1 deletion proposals/reference-types/ref_func.wast
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@

(module
(func $f (import "M" "f") (param i32) (result i32))
(func $g (param $x i32) (result i32) (i32.add (local.get $x) (i32.const 1)))
(func $g (param $x i32) (result i32)
(i32.add (local.get $x) (i32.const 1))
)

(global anyref (ref.func $f))
(global anyref (ref.func $g))
(global funcref (ref.func $f))
(global funcref (ref.func $g))
(global $v (mut funcref) (ref.func $f))

(global funcref (ref.func $gf1))
(global funcref (ref.func $gf2))
(func (drop (ref.func $ff1)) (drop (ref.func $ff2)))
(elem declare func $gf1 $ff1)
(elem declare funcref (ref.func $gf2) (ref.func $ff2))
(func $gf1)
(func $gf2)
(func $ff1)
(func $ff2)

(func (export "is_null-f") (result i32)
(ref.is_null (ref.func $f))
)
Expand All @@ -27,6 +39,7 @@
(func (export "set-g") (global.set $v (ref.func $g)))

(table $t 1 funcref)
(elem declare func $f $g)

(func (export "call-f") (param $x i32) (result i32)
(table.set $t (i32.const 0) (ref.func $f))
Expand Down Expand Up @@ -62,3 +75,12 @@
)
"unknown function 7"
)

(assert_invalid
(module (func $f) (global funcref (ref.func $f)))
"undeclared function reference"
)
(assert_invalid
(module (func $f (drop (ref.func $f))))
"undeclared function reference"
)
2 changes: 2 additions & 0 deletions proposals/reference-types/table_grow.wast
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
;; Reject growing to size outside i32 value range
(module
(table $t 0x10 anyref)
(elem declare func $f)
(func $f (export "grow") (result i32)
(table.grow $t (ref.func $f) (i32.const 0xffff_fff0))
)
Expand Down Expand Up @@ -82,6 +83,7 @@
(func (export "grow") (param i32) (result i32)
(table.grow $t (ref.null) (local.get 0))
)
(elem declare func 1)
(func (export "check-table-null") (param i32 i32) (result anyref)
(local anyref)
(local.set 2 (ref.func 1))
Expand Down
Loading