Skip to content

Commit

Permalink
Fix clippies and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl committed Sep 5, 2024
1 parent e665b35 commit ba1e384
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion core/engine/src/object/builtins/jsfunction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl<A: TryIntoJsArguments, R: TryFromJs> TypedJsFunction<A, R> {
}

/// Get the inner `JsFunction` without consuming this object.
#[must_use]
pub fn to_js_function(&self) -> JsFunction {
self.inner.clone()
}
Expand Down Expand Up @@ -83,7 +84,7 @@ impl<A: TryIntoJsArguments, R: TryFromJs> TryFromJs for TypedJsFunction<A, R> {
.with_message("object is not a function")
.into()
})
.and_then(|f| Ok(f.typed())),
.map(JsFunction::typed),
_ => Err(JsNativeError::typ()
.with_message("value is not a Function object")
.into()),
Expand Down
25 changes: 13 additions & 12 deletions core/interop/tests/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use boa_engine::{js_error, js_str, Context, JsResult, Module, Source};
use boa_interop::IntoJsFunctionCopied;
use std::path::PathBuf;

fn fibonacci_rs(
#[allow(clippy::needless_pass_by_value)]
fn fibonacci(
a: usize,
cb_a: TypedJsFunction<(usize, JsFunction, JsFunction), usize>,
cb_b: TypedJsFunction<(usize, JsFunction, JsFunction), usize>,
Expand All @@ -17,13 +18,13 @@ fn fibonacci_rs(
if a <= 1 {
Ok(a)
} else {
let cb_a1 = cb_a.to_js_function();
let cb_b1 = cb_b.to_js_function();
let cb_a2 = cb_a1.clone();
let cb_b2 = cb_b1.clone();

Ok(cb_a.call(context, (a - 1, cb_b1, cb_a1))?
+ cb_b.call(context, (a - 2, cb_b2, cb_a2))?)
Ok(cb_a.call(
context,
(a - 1, cb_b.to_js_function(), cb_a.to_js_function()),
)? + cb_b.call(
context,
(a - 2, cb_b.to_js_function(), cb_a.to_js_function()),
)?)
}
}

Expand All @@ -36,12 +37,12 @@ fn fibonacci_throw(
if a < 5 {
Err(js_error!("a is too small"))
} else {
fibonacci_rs(a, cb_a, cb_b, context)
fibonacci(a, cb_a, cb_b, context)
}
}

#[test]
fn fibonacci() {
fn fibonacci_test() {
let assets_dir =
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("tests/assets");

Expand All @@ -61,15 +62,15 @@ fn fibonacci() {
.get_typed_fn::<(usize, JsFunction, JsFunction), usize>(js_str!("fibonacci"), context)
.unwrap();

let fibonacci_rs = fibonacci_rs
let fibonacci_rust = fibonacci
.into_js_function_copied(context)
.to_js_function(context.realm());

assert_eq!(
fibonacci_js
.call(
context,
(10, fibonacci_rs.clone(), fibonacci_js.to_js_function())
(10, fibonacci_rust.clone(), fibonacci_js.to_js_function())
)
.unwrap(),
55
Expand Down
2 changes: 1 addition & 1 deletion core/interop/tests/gcd_callback.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(unused_crate_dependencies)]
//! A test that mimics the boa_engine's GCD test with a typed callback.
//! A test that mimics the `boa_engine`'s GCD test with a typed callback.

use boa_engine::object::builtins::JsFunction;
use boa_engine::{js_str, Context, Module, Source};
Expand Down

0 comments on commit ba1e384

Please sign in to comment.