{"record":{"id":"24fa51048ac4bab4","repo":"wasmerio/wasmer","slug":"direct-data-pointer-access-is-not-possible-in-java","errorCode":null,"errorMessage":"direct data pointer access is not possible in JavaScript","messagePattern":"direct data pointer access is not possible in JavaScript","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/api/src/backend/js/entities/memory/view.rs","lineNumber":49,"sourceCode":"        // This also works for SharedArrayBuffer.\n        let size = buffer\n            .unchecked_ref::<js_sys::ArrayBuffer>()\n            .byte_length()\n            .into();\n\n        let view = js_sys::Uint8Array::new(&buffer);\n\n        Self {\n            view,\n            size,\n            marker: PhantomData,\n        }\n    }\n\n    /// Returns the pointer to the raw bytes of the `Memory`.\n    #[doc(hidden)]\n    pub fn data_ptr(&self) -> *mut u8 {\n        unimplemented!(\"direct data pointer access is not possible in JavaScript\");\n    }\n\n    /// Returns the size (in bytes) of the `Memory`.\n    pub fn data_size(&self) -> u64 {\n        self.size\n    }\n\n    // TODO: do we want a proper implementation here instead?\n    /// Retrieve a slice of the memory contents.\n    ///\n    /// # Safety\n    ///\n    /// Until the returned slice is dropped, it is undefined behaviour to\n    /// modify the memory contents in any way including by calling a wasm\n    /// function that writes to the memory or by resizing the memory.\n    #[doc(hidden)]\n    pub unsafe fn data_unchecked(&self) -> &[u8] {\n        unimplemented!(\"direct data pointer access is not possible in JavaScript\");","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/api/src/backend/js/entities/memory/view.rs#L31-L67","documentation":"On the JS backend a Memory lives in WebAssembly.Memory, whose buffer is not exposed as a native pointer; MemoryView::data_ptr therefore panics with `unimplemented!`. Direct raw-pointer access to wasm memory is impossible in JavaScript, by design of the platform.","triggerScenarios":"Calling memory.data_ptr() (doc-hidden, but reachable via the view API) on a Memory backed by the js backend — e.g. embedder code or generated glue that assumes sys-backend raw pointers, such as C-ABI style pointer passing in a browser.","commonSituations":"Porting native wasmer embedders to wasmer-js; Emscripten-style code that reads/writes linear memory via pointer arithmetic; code sharing a single memory-view implementation across sys and js backends.","solutions":["Use memory.view::<u8>() typed views (or the ArrayBuffer via memory.buffer) to read/write JS-backed wasm memory instead of data_ptr","Gate pointer-based code with cfg(feature = \"sys\") / backend checks and provide a js-specific access path","Copy data across the boundary explicitly (e.g. via exported wasm functions or DataView) rather than by pointer","Restrict data_ptr usage to the native backend only"],"exampleFix":"// before\nlet ptr = memory.data_ptr();\nunsafe { std::slice::from_raw_parts(ptr, len) }\n// after (js backend)\nlet view: MemoryView<u8> = memory.view();\nlet bytes: Vec<u8> = (0..len).map(|i| view[i].get()).collect();","handlingStrategy":"type-guard","validationCode":"// gate pointer access behind backend feature\n#[cfg(feature = \"sys\")]\nfn raw_ptr(mem: &Memory) -> *mut u8 { mem.data_ptr() }\n#[cfg(feature = \"js\")]\nfn raw_ptr(_mem: &Memory) -> ! { panic!(\"use memory.view::<u8>() on js backend\") }","typeGuard":null,"tryCatchPattern":"// on js, catch the panic at the FFI boundary and use views\nmatch catch_unwind(|| unsafe { slice_from_ptr(mem.data_ptr(), len) }) {\n    Ok(s) => use_slice(s),\n    Err(_) => use_view_copy(mem),\n}","preventionTips":["Never call data_ptr on js-backed memories; use memory.view::<u8>()","Split sys-only pointer code behind cargo features","Copy data across the JS boundary via TypedArrays or exported functions","Document that doc-hidden pointer APIs are sys-backend-only"],"tags":["javascript","memory","unimplemented"],"backgroundTag":"js-backend-unsupported-feature","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}