1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

perf(serde_v8): serde_v8::StringOrBuffer return JS ArrayBuffer instead of Uint8Array (#16360)

Towards #16315
This commit is contained in:
Divy Srivastava 2022-10-20 16:03:57 +05:30 committed by GitHub
parent d3736f12b5
commit bfc1fb8d68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -440,7 +440,7 @@
if (this.binaryType === "blob") {
data = new Blob([value]);
} else {
data = value.buffer;
data = value;
}
const event = new MessageEvent("message", {

View file

@ -29,7 +29,24 @@ impl ToV8 for StringOrBuffer {
scope: &mut v8::HandleScope<'a>,
) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
match self {
Self::Buffer(buf) => crate::to_v8(scope, buf),
Self::Buffer(buf) => {
let buf: Box<[u8]> = match buf {
ZeroCopyBuf::FromV8(buf) => {
let value: &[u8] = buf;
value.into()
}
ZeroCopyBuf::Temp(_) => unreachable!(),
ZeroCopyBuf::ToV8(ref mut x) => {
x.take().expect("ZeroCopyBuf was empty")
}
};
let backing_store =
v8::ArrayBuffer::new_backing_store_from_boxed_slice(buf);
Ok(
v8::ArrayBuffer::with_backing_store(scope, &backing_store.into())
.into(),
)
}
Self::String(s) => crate::to_v8(scope, s),
}
}