-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ops): support SMI in return types (#86)
- Loading branch information
1 parent
39edde8
commit 482ffcf
Showing
12 changed files
with
223 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#[allow(non_camel_case_types)] | ||
pub struct op_async { | ||
_unconstructable: ::std::marker::PhantomData<()>, | ||
} | ||
impl deno_core::_ops::Op for op_async { | ||
const NAME: &'static str = stringify!(op_async); | ||
const DECL: deno_core::_ops::OpDecl = deno_core::_ops::OpDecl::new_internal( | ||
stringify!(op_async), | ||
true, | ||
false, | ||
false, | ||
2usize as u8, | ||
Self::v8_fn_ptr as _, | ||
None, | ||
); | ||
} | ||
impl op_async { | ||
pub const fn name() -> &'static str { | ||
stringify!(op_async) | ||
} | ||
#[deprecated(note = "Use the const op::DECL instead")] | ||
pub const fn decl() -> deno_core::_ops::OpDecl { | ||
<Self as deno_core::_ops::Op>::DECL | ||
} | ||
extern "C" fn v8_fn_ptr(info: *const deno_core::v8::FunctionCallbackInfo) { | ||
let mut scope = unsafe { deno_core::v8::CallbackScope::new(&*info) }; | ||
let mut rv = deno_core::v8::ReturnValue::from_function_callback_info(unsafe { | ||
&*info | ||
}); | ||
let args = deno_core::v8::FunctionCallbackArguments::from_function_callback_info(unsafe { | ||
&*info | ||
}); | ||
let opctx = unsafe { | ||
&*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value() | ||
as *const deno_core::_ops::OpCtx) | ||
}; | ||
let result = { | ||
let arg0 = args.get(1usize as i32); | ||
let Some(arg0) = deno_core::_ops::to_i32_option(&arg0) else { | ||
let mut scope = unsafe { deno_core::v8::CallbackScope::new(&*info) }; | ||
let msg = deno_core::v8::String::new_from_one_byte( | ||
&mut scope, | ||
"expected i32".as_bytes(), | ||
deno_core::v8::NewStringType::Normal, | ||
) | ||
.unwrap(); | ||
let exc = deno_core::v8::Exception::type_error(&mut scope, msg); | ||
scope.throw_exception(exc); | ||
return; | ||
}; | ||
let arg0 = arg0 as _; | ||
Self::call(arg0) | ||
}; | ||
let promise_id = deno_core::_ops::to_i32_option(&args.get(0)) | ||
.unwrap_or_default(); | ||
if let Some(result) | ||
= deno_core::_ops::map_async_op_fallible( | ||
opctx, | ||
promise_id, | ||
result, | ||
|scope, result| { | ||
Ok(deno_core::v8::Integer::new(scope, result as i32).into()) | ||
}, | ||
) { | ||
match result { | ||
Ok(result) => { | ||
rv.set_int32(result as i32); | ||
} | ||
Err(err) => { | ||
let err = err.into(); | ||
let opstate = ::std::cell::RefCell::borrow(&*opctx.state); | ||
let exception = deno_core::error::to_v8_error( | ||
&mut scope, | ||
opstate.get_error_class_fn, | ||
&err, | ||
); | ||
scope.throw_exception(exception); | ||
return; | ||
} | ||
}; | ||
} | ||
} | ||
#[inline(always)] | ||
pub async fn call(rid: ResourceId) -> std::io::Result<ResourceId> { | ||
Ok(rid as _) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
#![deny(warnings)] | ||
deno_ops_compile_test_runner::prelude!(); | ||
|
||
pub type ResourceId = i16; | ||
|
||
#[op2(async)] | ||
#[smi] | ||
pub async fn op_async(#[smi] rid: ResourceId) -> std::io::Result<ResourceId> { | ||
Ok(rid as _) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters