feat(napi-derive): implement instance_of for Class
This commit is contained in:
parent
8d0045f5b6
commit
711372e175
6 changed files with 39 additions and 3 deletions
examples/napi
|
@ -267,6 +267,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
}␊
|
||||
export class NinjaTurtle {␊
|
||||
name: string␊
|
||||
static isInstanceOf(value: unknown): boolean␊
|
||||
/** Create your ninja turtle! 🐢 */␊
|
||||
static newRaph(): NinjaTurtle␊
|
||||
getMaskColor(): string␊
|
||||
|
|
Binary file not shown.
|
@ -191,6 +191,7 @@ test('class', (t) => {
|
|||
t.is(assets.get(1)?.filePath, 1)
|
||||
const turtle = NinjaTurtle.newRaph()
|
||||
t.is(turtle.returnThis(), turtle)
|
||||
t.is(NinjaTurtle.isInstanceOf(turtle), true)
|
||||
})
|
||||
|
||||
test('class factory', (t) => {
|
||||
|
|
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -257,6 +257,7 @@ export class AnimalWithDefaultConstructor {
|
|||
}
|
||||
export class NinjaTurtle {
|
||||
name: string
|
||||
static isInstanceOf(value: unknown): boolean
|
||||
/** Create your ninja turtle! 🐢 */
|
||||
static newRaph(): NinjaTurtle
|
||||
getMaskColor(): string
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use napi::{
|
||||
bindgen_prelude::{Buffer, ClassInstance, ObjectFinalize, This, Uint8Array},
|
||||
bindgen_prelude::{Buffer, ClassInstance, ObjectFinalize, This, Uint8Array, Unknown},
|
||||
Env, Result,
|
||||
};
|
||||
|
||||
|
@ -214,6 +214,11 @@ pub struct NinjaTurtle {
|
|||
|
||||
#[napi]
|
||||
impl NinjaTurtle {
|
||||
#[napi]
|
||||
pub fn is_instance_of(env: Env, value: Unknown) -> Result<bool> {
|
||||
Self::instance_of(env, value)
|
||||
}
|
||||
|
||||
/// Create your ninja turtle! 🐢
|
||||
#[napi(factory)]
|
||||
pub fn new_raph() -> Self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue