MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / read_js_string

Method read_js_string

crates/tinywasm/src/reference.rs:316–326  ·  view source on GitHub ↗

Reads a JavaScript-style utf-16 string from memory.

(&self, store: &Store, offset: usize, len: usize)

Source from the content-addressed store, hash-verified

314
315 /// Reads a JavaScript-style utf-16 string from memory.
316 pub fn read_js_string(&self, store: &Store, offset: usize, len: usize) -> Result<String> {
317 let bytes = self.read_vec(store, offset, len)?;
318 let mut string = String::new();
319 for i in 0..(len / 2) {
320 let c = u16::from_le_bytes([bytes[i * 2], bytes[i * 2 + 1]]);
321 string.push(
322 char::from_u32(u32::from(c)).ok_or_else(|| crate::Error::Other("Invalid UTF-16 string".to_string()))?,
323 );
324 }
325 Ok(string)
326 }
327}
328
329fn table_element_to_value(element_type: WasmType, element: TableElement) -> WasmValue {

Callers

nothing calls this directly

Calls 2

read_vecMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected