Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more utility functions around modules and exports #3937

Merged
merged 8 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
clippies and fmt
  • Loading branch information
hansl committed Jul 31, 2024
commit 8af5fa57e036d3a4c51667b3f237ffbae39b38db
1 change: 0 additions & 1 deletion core/engine/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ impl Module {

/// Get an exported value from the module.
#[inline]
#[must_use]
pub fn get_value<K>(&self, name: K, context: &mut Context) -> JsResult<JsValue>
where
K: Into<PropertyKey>,
Expand Down
11 changes: 5 additions & 6 deletions core/engine/src/object/builtins/jsfunction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
value::TryFromJs, Context, JsNativeError, JsResult, JsValue, NativeFunction, TryIntoJsResult,
};
use boa_gc::{Finalize, Trace};
use std::marker::PhantomData;
use std::ops::Deref;

/// A trait for converting a tuple of Rust values into a vector of `JsValue`,
Expand Down Expand Up @@ -42,8 +43,8 @@ impl_try_into_js_args!(a: A, b: B, c: C, d: D, e: E);
#[derive(Debug, Clone, Trace, Finalize)]
pub struct TypedJsFunction<A: TryIntoJsArguments, R: TryFromJs> {
inner: JsFunction,
_args: std::marker::PhantomData<A>,
_ret: std::marker::PhantomData<R>,
_args: PhantomData<A>,
_ret: PhantomData<R>,
}

impl<A: TryIntoJsArguments, R: TryFromJs> TypedJsFunction<A, R> {
Expand All @@ -55,14 +56,12 @@ impl<A: TryIntoJsArguments, R: TryFromJs> TypedJsFunction<A, R> {

/// Call the function with the given arguments.
#[inline]
#[must_use]
pub fn call(&self, context: &mut Context, args: A) -> JsResult<R> {
self.call_with_this(&JsValue::undefined(), context, args)
}

/// Call the function with the given argument and `this`.
#[inline]
#[must_use]
pub fn call_with_this(&self, this: &JsValue, context: &mut Context, args: A) -> JsResult<R> {
let arguments = args.into_js_args(context)?;
let result = self.inner.call(this, &arguments, context)?;
Expand Down Expand Up @@ -117,8 +116,8 @@ impl JsFunction {
pub fn typed<A: TryIntoJsArguments, R: TryFromJs>(self) -> TypedJsFunction<A, R> {
TypedJsFunction {
inner: self,
_args: Default::default(),
_ret: Default::default(),
_args: PhantomData,
_ret: PhantomData,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/engine/tests/gcd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unused_crate_dependencies)]
//! A test that mimics the GCD example from wasmtime.
//! See: https://docs.wasmtime.dev/examples-rust-gcd.html#gcdrs
//! See: <https://docs.wasmtime.dev/examples-rust-gcd.html#gcdrs>.
//! This is a good point to discuss and improve on the usability
//! of the [`boa_engine`] API.

Expand Down
Loading