feat(napi-derive): catch_unwind attribute (#1280)
This commit is contained in:
parent
bc69e15efb
commit
b7a3103f0c
14 changed files with 64 additions and 8 deletions
examples/napi
|
@ -103,6 +103,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
}␊
|
||||
export function enumToI32(e: CustomNumEnum): number␊
|
||||
export function throwError(): void␊
|
||||
export function panic(): void␊
|
||||
export function createExternal(size: number): ExternalObject<number>␊
|
||||
export function createExternalString(content: string): ExternalObject<string>␊
|
||||
export function getExternal(external: ExternalObject<number>): number␊
|
||||
|
|
Binary file not shown.
|
@ -31,6 +31,7 @@ import {
|
|||
mapOption,
|
||||
readFile,
|
||||
throwError,
|
||||
panic,
|
||||
readPackageJson,
|
||||
getPackageJsonName,
|
||||
getBuffer,
|
||||
|
@ -163,7 +164,7 @@ test('enum', (t) => {
|
|||
t.is(enumToI32(CustomNumEnum.Eight), 8)
|
||||
})
|
||||
|
||||
test.only('class', (t) => {
|
||||
test('class', (t) => {
|
||||
const dog = new Animal(Kind.Dog, '旺财')
|
||||
|
||||
t.is(dog.name, '旺财')
|
||||
|
@ -371,6 +372,9 @@ test('Option', (t) => {
|
|||
|
||||
test('Result', (t) => {
|
||||
t.throws(() => throwError(), void 0, 'Manual Error')
|
||||
if (!process.env.SKIP_UNWIND_TEST) {
|
||||
t.throws(() => panic(), void 0, `Don't panic`)
|
||||
}
|
||||
})
|
||||
|
||||
test('function ts type override', (t) => {
|
||||
|
|
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -93,6 +93,7 @@ export const enum CustomNumEnum {
|
|||
}
|
||||
export function enumToI32(e: CustomNumEnum): number
|
||||
export function throwError(): void
|
||||
export function panic(): void
|
||||
export function createExternal(size: number): ExternalObject<number>
|
||||
export function createExternalString(content: string): ExternalObject<string>
|
||||
export function getExternal(external: ExternalObject<number>): number
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
use napi::bindgen_prelude::*;
|
||||
|
||||
#[napi]
|
||||
fn throw_error() -> Result<()> {
|
||||
pub fn throw_error() -> Result<()> {
|
||||
Err(Error::new(Status::InvalidArg, "Manual Error".to_owned()))
|
||||
}
|
||||
|
||||
#[napi(catch_unwind)]
|
||||
pub fn panic() {
|
||||
panic!("Don't panic");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(dead_code)]
|
||||
#![allow(unreachable_code)]
|
||||
#![allow(clippy::blacklisted_name)]
|
||||
#![allow(clippy::disallowed_names)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate napi_derive;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue