summaryrefslogtreecommitdiff
path: root/core/runtime/ops.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-06-24 23:30:04 +0200
committerGitHub <noreply@github.com>2023-06-24 15:30:04 -0600
commita181ceb0e3791c842db6e8e6f528cf9ce320642a (patch)
tree0714537d8b91013f9253e65202e2dc596e977d01 /core/runtime/ops.rs
parent4a18c761351dccb146973793cf22e6efffff18bf (diff)
refactor(ops): op2 supports Result in slow call path (#19602)
Diffstat (limited to 'core/runtime/ops.rs')
-rw-r--r--core/runtime/ops.rs72
1 files changed, 71 insertions, 1 deletions
diff --git a/core/runtime/ops.rs b/core/runtime/ops.rs
index fb71de8cb..85708b24b 100644
--- a/core/runtime/ops.rs
+++ b/core/runtime/ops.rs
@@ -208,12 +208,25 @@ pub fn to_i64(number: &v8::Value) -> i32 {
#[cfg(test)]
mod tests {
+ use crate::error::generic_error;
+ use crate::error::AnyError;
+ use crate::error::JsError;
use crate::FastString;
use crate::JsRuntime;
use crate::RuntimeOptions;
use deno_ops::op2;
- crate::extension!(testing, ops = [op_test_add, op_test_add_option]);
+ crate::extension!(
+ testing,
+ ops = [
+ op_test_add,
+ op_test_add_option,
+ op_test_result_void_ok,
+ op_test_result_void_err,
+ op_test_result_primitive_ok,
+ op_test_result_primitive_err
+ ]
+ );
/// Run a test for a single op.
fn run_test(
@@ -281,4 +294,61 @@ mod tests {
);
Ok(())
}
+
+ #[op2(core)]
+ pub fn op_test_result_void_err() -> Result<(), AnyError> {
+ Err(generic_error("failed!!!"))
+ }
+
+ #[op2(core)]
+ pub fn op_test_result_void_ok() -> Result<(), AnyError> {
+ Ok(())
+ }
+
+ #[tokio::test]
+ pub async fn test_op_result_void() -> Result<(), Box<dyn std::error::Error>> {
+ run_test(
+ "op_test_result_void_err",
+ "op_test_result_void_err()",
+ |value, _scope| {
+ let js_error = value.err().unwrap().downcast::<JsError>().unwrap();
+ assert_eq!(js_error.message, Some("failed!!!".to_owned()));
+ },
+ );
+ run_test(
+ "op_test_result_void_ok",
+ "op_test_result_void_ok()",
+ |value, _scope| assert!(value.unwrap().is_null_or_undefined()),
+ );
+ Ok(())
+ }
+
+ #[op2(core)]
+ pub fn op_test_result_primitive_err() -> Result<u32, AnyError> {
+ Err(generic_error("failed!!!"))
+ }
+
+ #[op2(core)]
+ pub fn op_test_result_primitive_ok() -> Result<u32, AnyError> {
+ Ok(123)
+ }
+
+ #[tokio::test]
+ pub async fn test_op_result_primitive(
+ ) -> Result<(), Box<dyn std::error::Error>> {
+ run_test(
+ "op_test_result_primitive_err",
+ "op_test_result_primitive_err()",
+ |value, _scope| {
+ let js_error = value.err().unwrap().downcast::<JsError>().unwrap();
+ assert_eq!(js_error.message, Some("failed!!!".to_owned()));
+ },
+ );
+ run_test(
+ "op_test_result_primitive_ok",
+ "op_test_result_primitive_ok()",
+ |value, scope| assert_eq!(value.unwrap().int32_value(scope), Some(123)),
+ );
+ Ok(())
+ }
}