summaryrefslogtreecommitdiff
path: root/ext/ffi/lib.rs
diff options
context:
space:
mode:
authorAapo Alasuutari <aapo.alasuutari@gmail.com>2022-06-21 05:50:33 +0300
committerGitHub <noreply@github.com>2022-06-21 08:20:33 +0530
commita38a1f91cf4e0b298bf166ae0ef63166fe7c67fe (patch)
tree43e1c0ab2484645485514922a2e3c7d54e2e988c /ext/ffi/lib.rs
parentac2cf2cb3ea36388437aab17d31e1c5e984d9693 (diff)
chore(ext/ffi): simplify FFI types (#14920)
This commit simplifies the TypeScript types used for interacting with Deno FFI. The basis is that types are now first grouped into logical wholes, NativeNumberType, NativeBigIntType etc. These wholes are combined into the NativeType and NativeResultType general types. Additionally, this PR removes the { function: { parameters: [], result: "void" } } type declaration from parameters (and result types. Now functions are merely passed and returned as "function".
Diffstat (limited to 'ext/ffi/lib.rs')
-rw-r--r--ext/ffi/lib.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs
index 691d44460..f380546b0 100644
--- a/ext/ffi/lib.rs
+++ b/ext/ffi/lib.rs
@@ -228,7 +228,7 @@ enum NativeType {
F32,
F64,
Pointer,
- Function {},
+ Function,
}
impl From<NativeType> for libffi::middle::Type {
@@ -248,7 +248,7 @@ impl From<NativeType> for libffi::middle::Type {
NativeType::F32 => libffi::middle::Type::f32(),
NativeType::F64 => libffi::middle::Type::f64(),
NativeType::Pointer => libffi::middle::Type::pointer(),
- NativeType::Function {} => libffi::middle::Type::pointer(),
+ NativeType::Function => libffi::middle::Type::pointer(),
}
}
}
@@ -289,7 +289,7 @@ impl NativeValue {
NativeType::ISize => Arg::new(&self.isize_value),
NativeType::F32 => Arg::new(&self.f32_value),
NativeType::F64 => Arg::new(&self.f64_value),
- NativeType::Pointer | NativeType::Function {} => Arg::new(&self.pointer),
+ NativeType::Pointer | NativeType::Function => Arg::new(&self.pointer),
}
}
@@ -317,7 +317,7 @@ impl NativeValue {
}
NativeType::F32 => Value::from(self.f32_value),
NativeType::F64 => Value::from(self.f64_value),
- NativeType::Pointer | NativeType::Function {} => {
+ NativeType::Pointer | NativeType::Function => {
json!(U32x2::from(self.pointer as u64))
}
}
@@ -394,7 +394,7 @@ impl NativeValue {
v8::Number::new(scope, self.f64_value).into();
local_value.into()
}
- NativeType::Pointer | NativeType::Function {} => {
+ NativeType::Pointer | NativeType::Function => {
let local_value: v8::Local<v8::Value> =
v8::BigInt::new_from_u64(scope, self.pointer as u64).into();
local_value.into()
@@ -702,7 +702,7 @@ where
return Err(type_error("Invalid FFI pointer type, expected null, BigInt, ArrayBuffer, or ArrayBufferView"));
}
}
- NativeType::Function {} => {
+ NativeType::Function => {
if value.is_null() {
let value: *const u8 = ptr::null();
ffi_args.push(NativeValue { pointer: value })
@@ -777,7 +777,7 @@ fn ffi_call(
NativeType::F64 => NativeValue {
f64_value: unsafe { cif.call::<f64>(fun_ptr, &call_args) },
},
- NativeType::Pointer | NativeType::Function {} => NativeValue {
+ NativeType::Pointer | NativeType::Function => NativeValue {
pointer: unsafe { cif.call::<*const u8>(fun_ptr, &call_args) },
},
})
@@ -1245,7 +1245,7 @@ fn op_ffi_get_static<'scope>(
let number = v8::Number::new(scope, result as f64);
serde_v8::from_v8(scope, number.into())?
}
- NativeType::Pointer | NativeType::Function {} => {
+ NativeType::Pointer | NativeType::Function => {
let result = data_ptr as *const u8 as u64;
let big_int = v8::BigInt::new_from_u64(scope, result);
serde_v8::from_v8(scope, big_int.into())?