Skip to content

Commit ff58b54

Browse files
committed
doc: Add an example for JSValue::new_array.
1 parent 8c2254a commit ff58b54

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/value.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,17 @@ impl JSValue {
150150
/// * `ctx`: The execution context to use.
151151
/// * `items`: The array items as [`JSValue`]s.
152152
///
153-
/// Returns a `JSValue` of the `array` type, other an exception.
153+
/// Returns a `JSValue` of the `array` type, otherwise an exception.
154+
///
155+
/// ```
156+
/// # use javascriptcore::{JSContext, JSValue};
157+
/// let ctx = JSContext::default();
158+
/// let value = JSValue::new_array(
159+
/// &ctx,
160+
/// &[JSValue::new_number(&ctx, 1.), JSValue::new_number(&ctx, 2.)]
161+
/// ).unwrap();
162+
/// assert!(value.is_array());
163+
/// ```
154164
pub fn new_array(ctx: &JSContext, items: &[JSValue]) -> Result<Self, JSException> {
155165
let items = items
156166
.iter()

0 commit comments

Comments
 (0)