This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
wasm-micro-runtime/doc/ref_types.md
Wenyong Huang 260d36a62d
Refactor externref related APIs of reference types feature (#971)
Currently when calling wasm_runtime_call_wasm() to invoke wasm function
with externref type argument from runtime embedder, developer needs to
use wasm_externref_obj2ref() to convert externref obj into an internal ref
index firstly, which is not convenient to developer.
To align with GC feature in which all the references passed to
wasm_runtime_call_wasm() can be object pointers directly, we change the
interface of wasm_runtime_call_wasm() to allow to pass object pointer
directly for the externref argument, and refactor the related codes, update
the related samples and the document.
2022-01-19 11:25:08 +08:00

1010 B

WAMR reference-types introduction

WebAssembly reference-types proposal introduces two new types funcref and externref. With externref, It is easier and more efficient to interoperate with host environment. Host references are able to be represented directly by type externref.

WAMR has implemented the reference-types proposal. WAMR allows a native method to pass a host object to a WASM application as an externref parameter or receives a host object from a WASM application as an externref result. Internally, WAMR won't try to parse or dereference externref. It is an opaque type.

The restriction of using externref in a native method is the host object has to be the value of a unintptr_t variable. In other words, it takes 8 bytes on 64-bit machine and 4 bytes on 32-bit machines. Please keep that in mind especially when calling wasm_runtime_call_wasm.

Please ref to the sample for more details.