Skip to content

Commit

Permalink
Doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dherman committed Mar 4, 2022
1 parent 06d95ea commit 9baa676
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ mod traits {

/// The trait of all object types.
pub trait Object: Value {
/// Gets a property from a JavaScript object that may be `undefined` and
/// attempts to downcast the value if it existed.
fn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
Expand All @@ -251,6 +253,10 @@ mod traits {
v.downcast_or_throw(cx).map(Some)
}

/// Gets a property from a JavaScript object as a [`JsValue`].
///
/// If a [`getter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get)
/// is defined on the object, it will be called.
fn get_value<'a, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
Expand All @@ -261,6 +267,10 @@ mod traits {
})
}

/// Gets a property from a JavaScript object and attempts to downcast as a specific type.
/// Equivalent to calling `obj.get(&mut cx)?.downcast_or_throw(&mut cx)`.
///
/// Throws an exception if the value is a different type.
fn get<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
Expand Down

0 comments on commit 9baa676

Please sign in to comment.