summaryrefslogtreecommitdiff
path: root/ext/web/lib.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-10-26 18:28:25 +0530
committerGitHub <noreply@github.com>2022-10-26 18:28:25 +0530
commit6cd9343e8b6f6ede22ec56b06e6918a80c9a3ddd (patch)
treeadc7eeb02f2cdc21903e71ee6b6aeded4955ec04 /ext/web/lib.rs
parent046ab7dc8aa9cc343bd7de2e5efc2e40d73e4998 (diff)
perf(ext/web): optimize transferArrayBuffer (#16294)
Avoid copying enqueued data + misc optimizations to skip webidl converter.
Diffstat (limited to 'ext/web/lib.rs')
-rw-r--r--ext/web/lib.rs18
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)