fix(napi): TypedArray is not ArrayBuffer in Deno (#2314)

This commit is contained in:
LongYinan 2024-10-17 16:36:21 +08:00 committed by GitHub
parent 383b5d023c
commit 161758393f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -129,6 +129,11 @@ impl<'x, 'de, 'env> serde::de::Deserializer<'x> for &'de mut De<'env> {
return visitor.visit_byte_buf(
unsafe { BufferSlice::from_napi_value(self.0.env, self.0.value)? }.to_vec(),
);
} else if js_object.is_typedarray()? {
return visitor.visit_byte_buf(unsafe {
let u8_slice: &[u8] = FromNapiValue::from_napi_value(self.0.env, self.0.value)?;
u8_slice.to_vec()
});
} else if js_object.is_arraybuffer()? {
let array_buf =
unsafe { JsArrayBuffer::from_napi_value(self.0.env, self.0.value)?.into_value()? };

View File

@ -610,7 +610,7 @@ test('create object from Property', (t) => {
})
test('global', (t) => {
t.is(getGlobal(), global)
t.is(getGlobal(), typeof global === 'undefined' ? globalThis : global)
})
test('get undefined', (t) => {