{"record":{"id":"c3335ec43efd5e8c","repo":"wasmerio/wasmer","slug":"cloning-javascript-shared-memory-should-not-fail","errorCode":null,"errorMessage":"cloning JavaScript shared memory should not fail","messagePattern":"cloning JavaScript shared memory should not fail","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/api/src/vm/impls.rs","lineNumber":80,"sourceCode":"            Self::V8(s) => s.as_shared().map(VMSharedMemory::V8),\n            #[cfg(feature = \"js\")]\n            Self::Js(s) => s.try_clone().map(VMSharedMemory::Js),\n        }\n    }\n}\n\nimpl VMSharedMemory {\n    /// Clones this shared memory handle.\n    pub(crate) fn clone(&self) -> Self {\n        match self {\n            #[cfg(feature = \"sys\")]\n            Self::Sys(s) => Self::Sys(s.clone()),\n            #[cfg(feature = \"v8\")]\n            Self::V8(s) => Self::V8(s.clone()),\n            #[cfg(feature = \"js\")]\n            Self::Js(s) => Self::Js(\n                s.try_clone()\n                    .expect(\"cloning JavaScript shared memory should not fail\"),\n            ),\n        }\n    }\n\n    pub(crate) fn into_vm_memory(self, store: &mut impl AsStoreMut) -> VMMemory {\n        match self {\n            #[cfg(feature = \"sys\")]\n            Self::Sys(s) => VMMemory::Sys(s.into()),\n            #[cfg(feature = \"v8\")]\n            Self::V8(s) => {\n                let mut store = store.as_store_mut();\n                VMMemory::V8(s.into_vm_memory(store.inner.store.as_v8_mut()))\n            }\n            #[cfg(feature = \"js\")]\n            Self::Js(s) => VMMemory::Js(s),\n        }\n    }\n}","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/api/src/vm/impls.rs#L62-L98","documentation":"This panic comes from a Clone impl for a VM memory wrapper (VMMemory). For the JavaScript backend, the underlying shared memory is backed by a JS object that cannot be Clone'd on all runtimes; if try_clone() fails the code deliberately panics because sharing cloned memory across VM instances is assumed to always work for JS shared memory. It indicates an internal invariant of the js feature's memory sharing broke.","triggerScenarios":"Cloning a VMMemory::Js variant via .clone() (e.g. when cloning a Store, Instance handle, or memory handle to share across VMs) when the underlying JS SharedArrayBuffer/typed array cannot be cloned in the current JS runtime (e.g. cross-realm object or missing SharedArrayBuffer support).","commonSituations":"Running wasmer compiled with feature=js inside a restricted WASM-in-browser environment where SharedArrayBuffer is unavailable (no COOP/COEP headers), or cloning memory handles across JS compartments.","solutions":["Enable cross-origin isolation (COOP/COEP headers) so SharedArrayBuffer is available in the browser runtime","Rebuild without the js feature (or with v8/sys backend) if you do not need JS shared memory","Upgrade wasmer; this is an internal invariant panic, so check for a newer version with a fallible clone","Avoid cloning memory handles across realms/VM instances; recreate the memory instead"],"exampleFix":"// before (panic path)\nlet mem2 = memory.clone();\n// after: create a fresh memory instead of cloning across runtimes\nlet mem2 = Memory::new(&store, memory_ty)?;","handlingStrategy":"validation","validationCode":"// Ensure the runtime supports SharedArrayBuffer before using the js backend\nif (typeof SharedArrayBuffer === 'undefined') {\n  throw new Error('SharedArrayBuffer unavailable; enable COOP/COEP or use a non-js backend');\n}","typeGuard":"fn is_js_memory(mem: &VMMemory) -> bool { matches!(mem, VMMemory::Js(_)) }","tryCatchPattern":"// Clone of VMMemory panics rather than returning Result; isolate it\nlet mem2 = std::panic::catch_unwind(|| mem.clone())\n    .map_err(|_| anyhow::anyhow!(\"JS shared memory clone failed\"))?;","preventionTips":["Enable COOP/COEP cross-origin isolation headers when running in browsers","Do not clone memory handles across JS realms or VM instances","Prefer creating a new Memory over cloning when sharing is not required","Pin/test against the runtime (browser/JS engine) you deploy to"],"tags":["panic","wasm","javascript","memory"],"backgroundTag":"js-shared-memory-clone-failed","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}