diff options
Diffstat (limited to 'ext/web/lib.rs')
-rw-r--r-- | ext/web/lib.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ext/web/lib.rs b/ext/web/lib.rs index 8a9d3e18c..588a3adfd 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -112,6 +112,7 @@ pub fn init<P: TimersPermission + 'static>( op_timer_handle::decl(), op_cancel_handle::decl(), op_sleep::decl(), + op_transfer_arraybuffer::decl(), ]) .state(move |state| { state.put(blob_store.clone()); @@ -338,6 +339,23 @@ fn op_encoding_encode_into( Ok(()) } +#[op(v8)] +fn op_transfer_arraybuffer<'a>( + scope: &mut v8::HandleScope<'a>, + input: serde_v8::Value<'a>, +) -> Result<serde_v8::Value<'a>, AnyError> { + let ab = v8::Local::<v8::ArrayBuffer>::try_from(input.v8_value)?; + if !ab.is_detachable() { + return Err(type_error("ArrayBuffer is not detachable")); + } + let bs = ab.get_backing_store(); + ab.detach(); + let ab = v8::ArrayBuffer::with_backing_store(scope, &bs); + Ok(serde_v8::Value { + v8_value: ab.into(), + }) +} + #[op] fn op_encode_binary_string(s: &[u8]) -> ByteString { ByteString::from(s) |