1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

refactor(ext/ffi): don't go through serde_v8::Value (#23034)

Removes unnecessary indirection - after creating `serde_v8::Value` it
was immediately unwrapped to `v8::Value` by the caller.
This commit is contained in:
Bartek Iwańczuk 2024-03-22 19:05:06 +00:00 committed by GitHub
parent b688b61036
commit 85236576b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 55 deletions

View file

@ -291,7 +291,7 @@ fn make_sync_fn<'s>(
let result = let result =
// SAFETY: Same return type declared to libffi; trust user to have it right beyond that. // SAFETY: Same return type declared to libffi; trust user to have it right beyond that.
unsafe { result.to_v8(scope, symbol.result_type.clone()) }; unsafe { result.to_v8(scope, symbol.result_type.clone()) };
rv.set(result.v8_value); rv.set(result);
} }
} }
} }

View file

@ -5,7 +5,6 @@ use crate::MAX_SAFE_INTEGER;
use crate::MIN_SAFE_INTEGER; use crate::MIN_SAFE_INTEGER;
use deno_core::error::type_error; use deno_core::error::type_error;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::serde_v8;
use deno_core::v8; use deno_core::v8;
use libffi::middle::Arg; use libffi::middle::Arg;
use std::ffi::c_void; use std::ffi::c_void;
@ -85,47 +84,22 @@ impl NativeValue {
&self, &self,
scope: &mut v8::HandleScope<'scope>, scope: &mut v8::HandleScope<'scope>,
native_type: NativeType, native_type: NativeType,
) -> serde_v8::Value<'scope> { ) -> v8::Local<'scope, v8::Value> {
match native_type { match native_type {
NativeType::Void => { NativeType::Void => v8::undefined(scope).into(),
let local_value: v8::Local<v8::Value> = v8::undefined(scope).into(); NativeType::Bool => v8::Boolean::new(scope, self.bool_value).into(),
local_value.into()
}
NativeType::Bool => {
let local_value: v8::Local<v8::Value> =
v8::Boolean::new(scope, self.bool_value).into();
local_value.into()
}
NativeType::U8 => { NativeType::U8 => {
let local_value: v8::Local<v8::Value> = v8::Integer::new_from_unsigned(scope, self.u8_value as u32).into()
v8::Integer::new_from_unsigned(scope, self.u8_value as u32).into();
local_value.into()
}
NativeType::I8 => {
let local_value: v8::Local<v8::Value> =
v8::Integer::new(scope, self.i8_value as i32).into();
local_value.into()
} }
NativeType::I8 => v8::Integer::new(scope, self.i8_value as i32).into(),
NativeType::U16 => { NativeType::U16 => {
let local_value: v8::Local<v8::Value> = v8::Integer::new_from_unsigned(scope, self.u16_value as u32).into()
v8::Integer::new_from_unsigned(scope, self.u16_value as u32).into();
local_value.into()
}
NativeType::I16 => {
let local_value: v8::Local<v8::Value> =
v8::Integer::new(scope, self.i16_value as i32).into();
local_value.into()
} }
NativeType::I16 => v8::Integer::new(scope, self.i16_value as i32).into(),
NativeType::U32 => { NativeType::U32 => {
let local_value: v8::Local<v8::Value> = v8::Integer::new_from_unsigned(scope, self.u32_value).into()
v8::Integer::new_from_unsigned(scope, self.u32_value).into();
local_value.into()
}
NativeType::I32 => {
let local_value: v8::Local<v8::Value> =
v8::Integer::new(scope, self.i32_value).into();
local_value.into()
} }
NativeType::I32 => v8::Integer::new(scope, self.i32_value).into(),
NativeType::U64 => { NativeType::U64 => {
let value = self.u64_value; let value = self.u64_value;
let local_value: v8::Local<v8::Value> = let local_value: v8::Local<v8::Value> =
@ -134,7 +108,7 @@ impl NativeValue {
} else { } else {
v8::Number::new(scope, value as f64).into() v8::Number::new(scope, value as f64).into()
}; };
local_value.into() local_value
} }
NativeType::I64 => { NativeType::I64 => {
let value = self.i64_value; let value = self.i64_value;
@ -145,7 +119,7 @@ impl NativeValue {
} else { } else {
v8::Number::new(scope, value as f64).into() v8::Number::new(scope, value as f64).into()
}; };
local_value.into() local_value
} }
NativeType::USize => { NativeType::USize => {
let value = self.usize_value; let value = self.usize_value;
@ -155,7 +129,7 @@ impl NativeValue {
} else { } else {
v8::Number::new(scope, value as f64).into() v8::Number::new(scope, value as f64).into()
}; };
local_value.into() local_value
} }
NativeType::ISize => { NativeType::ISize => {
let value = self.isize_value; let value = self.isize_value;
@ -165,30 +139,19 @@ impl NativeValue {
} else { } else {
v8::Number::new(scope, value as f64).into() v8::Number::new(scope, value as f64).into()
}; };
local_value.into() local_value
}
NativeType::F32 => {
let local_value: v8::Local<v8::Value> =
v8::Number::new(scope, self.f32_value as f64).into();
local_value.into()
}
NativeType::F64 => {
let local_value: v8::Local<v8::Value> =
v8::Number::new(scope, self.f64_value).into();
local_value.into()
} }
NativeType::F32 => v8::Number::new(scope, self.f32_value as f64).into(),
NativeType::F64 => v8::Number::new(scope, self.f64_value).into(),
NativeType::Pointer | NativeType::Buffer | NativeType::Function => { NativeType::Pointer | NativeType::Buffer | NativeType::Function => {
let local_value: v8::Local<v8::Value> = if self.pointer.is_null() { let local_value: v8::Local<v8::Value> = if self.pointer.is_null() {
v8::null(scope).into() v8::null(scope).into()
} else { } else {
v8::External::new(scope, self.pointer).into() v8::External::new(scope, self.pointer).into()
}; };
local_value.into() local_value
}
NativeType::Struct(_) => {
let local_value: v8::Local<v8::Value> = v8::null(scope).into();
local_value.into()
} }
NativeType::Struct(_) => v8::null(scope).into(),
} }
} }
} }