1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-12 00:54:02 -05:00
denoland-deno/ops/op2/test_cases/sync/add_options.out
Matt Mastracci 65d9bfb533
refactor(ops): Adding op2 macro and implementing in a couple of places (#19534)
This is a new op system that will eventually replace `#[op]`. 

Features
 - More maintainable, generally less-coupled code
 - More modern Rust proc-macro libraries
- Enforces correct `fast` labelling for fast ops, allowing for visual
scanning of fast ops
 - Explicit marking of `#[string]`, `#[serde]` and `#[smi]` parameters.

This first version of op2 supports integer and Option<integer>
parameters only, and allows us to start working on converting ops and
adding features.
2023-06-24 13:54:10 +02:00

44 lines
1.4 KiB
Text

#[allow(non_camel_case_types)]
pub struct op_test_add_option {}
impl op_test_add_option {
pub const fn name() -> &'static str {
stringify!(op_test_add_option)
}
pub const fn decl() -> crate::deno_core::_ops::OpDecl {
crate::deno_core::_ops::OpDecl {
name: stringify!(op_test_add_option),
v8_fn_ptr: Self::slow_function as _,
enabled: true,
fast_fn: None,
is_async: false,
is_unstable: false,
is_v8: false,
arg_count: 2usize as u8,
}
}
pub extern "C" fn slow_function(
info: *const crate::deno_core::v8::FunctionCallbackInfo,
) {
let mut rv = crate::deno_core::v8::ReturnValue::from_function_callback_info(unsafe {
&*info
});
let args = crate::deno_core::v8::FunctionCallbackArguments::from_function_callback_info(unsafe {
&*info
});
let arg0 = args.get(0usize as i32);
let arg0 = crate::deno_core::_ops::to_u32(&arg0) as _;
let arg1 = args.get(1usize as i32);
let arg1 = if arg1.is_null_or_undefined() {
None
} else {
let arg1 = crate::deno_core::_ops::to_u32(&arg1) as _;
Some(arg1)
};
let result = Self::call(arg0, arg1);
rv.set_uint32(result as u32);
}
#[inline(always)]
pub fn call(a: u32, b: Option<u32>) -> u32 {
a + b.unwrap_or(100)
}
}