Skip to content

Reference

Create a null reference.

Signature: (result reftype)

Example:

(ref.null func)
(ref.null extern)

Create a function reference.

Signature: (result funcref)

Example:

(func $my_func (result i32) (i32.const 42))
(ref.func $my_func)

Check if reference is null.

Signature: (param reftype) (result i32)

Example:

(ref.is_null (ref.null func)) ;; Returns 1

Assert that a reference is not null and convert it to a non-nullable type. Traps if the reference is null.

Signature: (param (ref null ht)) (result (ref ht))

Example:

(ref.as_non_null (local.get $nullable_ref)) ;; Traps if null, otherwise returns non-null ref

Convert an externref to anyref. This allows external references to be used with GC reference operations.

Signature: (param externref) (result anyref)

Example:

(any.convert_extern (local.get $ext_ref))

Convert an anyref to externref. This allows any GC reference to be passed out as an external reference.

Signature: (param anyref) (result externref)

Example:

(extern.convert_any (local.get $any_ref))