Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ pub(crate) mod win32_callback;
#[cfg(feature = "classic")]
pub(crate) mod win32_fast;
#[cfg(feature = "classic")]
pub(crate) mod winrt_fast;
#[cfg(feature = "classic")]
pub(crate) mod win32_known_fns;
mod websocket;
mod winhttp;
Expand Down Expand Up @@ -1426,6 +1428,9 @@ pub(crate) struct DeclarationFFI {
pub(crate) prepared_method: std::cell::OnceCell<crate::method_call::PreparedCall>,
#[cfg(feature = "classic")]
pub(crate) prepared_property: std::cell::OnceCell<crate::property_call::PreparedProperty>,
/// Method callbacks with a simple signature: the V8 fast API overload's plan.
#[cfg(feature = "classic")]
pub(crate) fast: Option<std::rc::Rc<crate::winrt_fast::FastMethod>>,
}

unsafe impl Sync for DeclarationFFI {}
Expand All @@ -1444,6 +1449,7 @@ impl DeclarationFFI {
qi: crate::method_call::QiCache::new(),
prepared_method: std::cell::OnceCell::new(),
prepared_property: std::cell::OnceCell::new(),
fast: None,
}
}

Expand All @@ -1461,6 +1467,7 @@ impl DeclarationFFI {
qi: crate::method_call::QiCache::new(),
prepared_method: std::cell::OnceCell::new(),
prepared_property: std::cell::OnceCell::new(),
fast: None,
}
}

Expand Down Expand Up @@ -4317,14 +4324,18 @@ fn create_ns_ctor_instance_object<'a>(

let name = v8::String::new(scope, method_name.as_str());

let declaration = DeclarationFFI::new_with_instance(
let mut declaration = DeclarationFFI::new_with_instance(
Arc::new(RwLock::new(method.clone())),
if is_static {
factory.clone()
} else {
instance.clone()
},
);
// Optimized callers of a simple signature skip the generic marshalling.
let fast = crate::winrt_fast::plan(method, !is_static);
let cfn = fast.as_ref().map(|f| crate::winrt_fast::cfunction(f));
declaration.fast = fast.map(std::rc::Rc::new);

let declaration = Box::into_raw(Box::new(declaration));

Expand Down Expand Up @@ -4409,9 +4420,11 @@ fn create_ns_ctor_instance_object<'a>(
retval.set(v);
}

let func = FunctionTemplate::builder_raw(callback)
.data(ext.into())
.build(scope);
let builder = FunctionTemplate::builder_raw(callback).data(ext.into());
let func = match cfn {
Some(cfn) => builder.build_fast(scope, &[cfn]),
None => builder.build(scope),
};

if is_static {
tmpl.set_with_attr(
Expand Down Expand Up @@ -7049,8 +7062,17 @@ fn create_ns_ctor_object<'a>(
.collect();

let func = if let [dec] = decs.as_slice() {
// Optimized callers of a simple signature skip the generic marshalling.
let fast = {
let lock = unsafe { &**dec }.read();
lock.as_any()
.downcast_ref::<MethodDeclaration>()
.and_then(|method| crate::winrt_fast::plan(method, false))
};
let cfn = fast.as_ref().map(|f| crate::winrt_fast::cfunction(f));
unsafe { (**dec).fast = fast.map(std::rc::Rc::new) };
let ext = v8::External::new(scope, *dec as _);
v8::FunctionTemplate::builder(
let builder = v8::FunctionTemplate::builder(
|scope: &mut v8::PinScope<'_, '_>,
args: v8::FunctionCallbackArguments,
mut retval: v8::ReturnValue| {
Expand All @@ -7059,8 +7081,11 @@ fn create_ns_ctor_object<'a>(
call_static_method(scope, &args, &mut retval, dec);
},
)
.data(ext.into())
.build(scope)
.data(ext.into());
match cfn {
Some(cfn) => builder.build_fast(scope, &[cfn]),
None => builder.build(scope),
}
} else {
let ext = v8::External::new(scope, Box::into_raw(Box::new(decs)) as _);
v8::FunctionTemplate::builder(
Expand Down
24 changes: 24 additions & 0 deletions runtime/src/method_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,30 @@ pub(crate) struct PreparedCall {
is_initializer: bool,
}

impl MethodCall {
pub(crate) fn raw_interface(&self) -> *mut c_void {
self.interface.as_raw()
}

pub(crate) fn vtable_func(&self) -> *mut c_void {
self.func
}

pub(crate) fn init_failed(&self) -> bool {
self.init_error.is_some()
}
}

impl PreparedCall {
pub(crate) fn raw_interface(&self) -> *mut c_void {
self.interface.as_raw()
}

pub(crate) fn func(&self) -> *mut c_void {
self.func
}
}

impl MethodCall {
/// Static info for a method already seen on this thread, if any.
fn cached_static_info(
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/win32_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ impl Prepared {
// x64: a variadic call puts floats at positions 1 to 3 in both the integer and XMM register,
// so one type fits any callee; position 0 is fixed and needs two variants.
#[cfg(target_arch = "x86_64")]
unsafe fn call_registers(address: usize, args: &[Kind], words: &[u64], float_ret: bool) -> u64 {
pub(crate) unsafe fn call_registers(address: usize, args: &[Kind], words: &[u64], float_ret: bool) -> u64 {
type IntInt = unsafe extern "C" fn(i64, ...) -> i64;
type IntFloat = unsafe extern "C" fn(i64, ...) -> f64;
type FloatInt = unsafe extern "C" fn(f64, ...) -> i64;
Expand Down Expand Up @@ -381,7 +381,7 @@ unsafe fn call_registers(address: usize, args: &[Kind], words: &[u64], float_ret

// arm64: X0-X7 and D0-D7 are separate, so one type taking both covers every signature.
#[cfg(target_arch = "aarch64")]
unsafe fn call_registers(address: usize, args: &[Kind], words: &[u64], float_ret: bool) -> u64 {
pub(crate) unsafe fn call_registers(address: usize, args: &[Kind], words: &[u64], float_ret: bool) -> u64 {
type IntFn = unsafe extern "C" fn(
i64,
i64,
Expand Down
Loading