{"record":{"id":"bcb4be0446fcdf1d","repo":"wasmerio/wasmer","slug":"externref-is-not-yet-supported-with-wasm-c-api","errorCode":null,"errorMessage":"ExternRef is not yet supported with wasm_c_api","messagePattern":"ExternRef is not yet supported with wasm_c_api","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/api/src/backend/v8/entities/external.rs","lineNumber":18,"sourceCode":"//! Data types, functions and traits for `v8` runtime's `ExternRef` implementation.\nuse crate::{\n    store::{AsStoreMut, AsStoreRef},\n    v8::vm::VMExternRef,\n};\nuse std::any::Any;\n\n#[derive(Debug, Clone)]\n#[repr(transparent)]\n/// A WebAssembly `extern ref` in the `v8` runtime.\npub struct ExternRef;\n\nimpl ExternRef {\n    pub fn new<T>(_store: &mut impl AsStoreMut, _value: T) -> Self\n    where\n        T: Any + Send + Sync + 'static + Sized,\n    {\n        unimplemented!(\"ExternRef is not yet supported with wasm_c_api\");\n    }\n\n    pub fn downcast<'a, T>(&self, _store: &'a impl AsStoreRef) -> Option<&'a T>\n    where\n        T: Any + Send + Sync + 'static + Sized,\n    {\n        unimplemented!(\"ExternRef is not yet supported in wasm_c_api\");\n    }\n\n    pub(crate) fn vm_externref(&self) -> VMExternRef {\n        unimplemented!(\"ExternRef is not yet supported in wasm_c_api\");\n    }\n\n    pub(crate) unsafe fn from_vm_externref(\n        _store: &mut impl AsStoreMut,\n        _vm_externref: VMExternRef,\n    ) -> Self {\n        unimplemented!(\"ExternRef is not yet supported in wasm_c_api\");","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/api/src/backend/v8/entities/external.rs#L1-L36","documentation":"On the v8 backend (built atop wasm_c_api), `ExternRef::new` is not implemented: host-defined externref values cannot be wrapped. Calling it panics with this message; `downcast` is likewise a no-op stub.","triggerScenarios":"Calling `ExternRef::new(&mut store, value)` in any binary built with the v8 backend, for any value type.","commonSituations":"Passing opaque host objects (Rust structs) into wasm via externref globals/function params; code shared across sys/js/v8 backends where only v8 lacks support.","solutions":["Use the sys or js backend where externrefs are supported","Represent host values as i32 handles into a global registry instead of externrefs when targeting v8","Guard externref usage behind a backend capability check"],"exampleFix":"// before\nlet ext = ExternRef::new(&mut store, MyValue { .. }); // panics on v8\n// after\nlet handle = REGISTRY.with(|r| r.borrow_mut().insert(MyValue { .. }));\nValue::I32(handle)","handlingStrategy":"fallback","validationCode":"fn externref_supported() -> bool {\n    !cfg!(feature = \"v8\") // v8/wasm_c_api lacks ExternRef::new\n}","typeGuard":"fn externref_supported() -> bool {\n    !cfg!(feature = \"v8\")\n}","tryCatchPattern":"if !externref_supported() {\n    return Err(anyhow!(\"ExternRef unavailable on v8 backend; use handle registry\"));\n}\nlet ext = ExternRef::new(&mut store, value);","preventionTips":["Use i32 registry handles instead of ExternRef on v8 builds","Gate externref usage per backend with cargo features","Keep a backend-capability table in docs/tests for ExternRef, Exception, Table::copy"],"tags":["wasm","v8-backend","externref","unimplemented"],"backgroundTag":"unimplemented-backend-feature","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}