Skip to content

GC Casts

Test if a reference is null or of a specific type.

Signature: (param ref) (result i32)

Example:

(ref.test (ref null $type) (local.get $ref))

Cast a reference to a specific type (traps on failure).

Signature: (param ref) (result ref)

Example:

(ref.cast (ref null $type) (local.get $ref))

Cast a reference to a specific type (returns null on failure).

Signature: (param ref) (result ref)

Example:

(ref.cast_null (ref null $type) (local.get $ref))

Branch if a reference can be cast to a type.

Signature: (param ref) (result ref?)

Example:

(br_on_cast $label (ref null $target_type) (local.get $ref))

Branch if a reference cannot be cast to a type.

Signature: (param ref) (result ref)

Example:

(br_on_cast_fail $label (ref null $target_type) (local.get $ref))

Compare two references for equality. Both references must be of type eqref or a subtype.

Signature: (param eqref eqref) (result i32)

Example:

(ref.eq (local.get $ref1) (local.get $ref2)) ;; Returns 1 if equal, 0 otherwise