test: added test for coerce_to_object on Array
This commit is contained in:
parent
36e808d2a6
commit
9a4f8cf32c
4 changed files with 12 additions and 0 deletions
|
@ -25,6 +25,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
/** Gets some numbers */␊
|
||||
export function getNums(): Array<number>␊
|
||||
export function sumNums(nums: Array<number>): number␊
|
||||
export function toJsObj(): object␊
|
||||
export function readFileAsync(path: string): Promise<Buffer>␊
|
||||
export function asyncMultiTwo(arg: number): Promise<number>␊
|
||||
export function bigintAdd(a: bigint, b: bigint): bigint␊
|
||||
|
|
Binary file not shown.
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -15,6 +15,7 @@ export function getWords(): Array<string>
|
|||
/** Gets some numbers */
|
||||
export function getNums(): Array<number>
|
||||
export function sumNums(nums: Array<number>): number
|
||||
export function toJsObj(): object
|
||||
export function readFileAsync(path: string): Promise<Buffer>
|
||||
export function asyncMultiTwo(arg: number): Promise<number>
|
||||
export function bigintAdd(a: bigint, b: bigint): bigint
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use napi::{Env, JsObject};
|
||||
|
||||
#[napi]
|
||||
pub fn get_words() -> Vec<&'static str> {
|
||||
vec!["foo", "bar"]
|
||||
|
@ -13,3 +15,11 @@ fn get_nums() -> Vec<u32> {
|
|||
fn sum_nums(nums: Vec<u32>) -> u32 {
|
||||
nums.iter().sum()
|
||||
}
|
||||
|
||||
#[napi]
|
||||
fn to_js_obj(env: Env) -> napi::Result<JsObject> {
|
||||
let mut arr = env.create_array(0)?;
|
||||
arr.insert("a string")?;
|
||||
arr.insert(42)?;
|
||||
arr.coerce_to_object()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue