Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared Array Buffer support #367

Open
stevefan1999-personal opened this issue Sep 30, 2024 · 0 comments
Open

Shared Array Buffer support #367

stevefan1999-personal opened this issue Sep 30, 2024 · 0 comments

Comments

@stevefan1999-personal
Copy link

I see that there is no support for shared buffer which is important for wasmtime integration in Den, because the user can mutate the underlying WebAssembly memory object inside Javascript, but right now all the API in rquickjs requires creating copied value from Rust, rather than from a slice. I tried to sidestep it by doing this:

    #[qjs(get, enumerable)]
    pub fn buffer<'js>(&self, ctx: Ctx<'js>) -> Result<ArrayBuffer<'js>> {
        let data = self.inner.data(self.store.lock().unwrap().as_context());

        let val = unsafe {
            let val = qjs::JS_NewArrayBuffer(
                ctx.as_raw().as_mut(),
                data.as_mut_ptr(),
                data.len().try_into().unwrap(), 
                None, // No need for deallocation
                ptr::null_mut(), // No opaque
                1, // True = Shared
            );
            if qjs::JS_VALUE_GET_NORM_TAG(val) == qjs::JS_TAG_EXCEPTION {
                return Err(rquickjs::Error::Exception);
            }
            Value::from_js_value(ctx.clone(), val)
        };

        let buffer = ArrayBuffer::from_object(Object::from_value(val)?).unwrap();
        Ok(buffer)
    }

But function from_js_value is private and there seems to be no way to create that Rust-based value wrapper as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant