feat(napi-derive): allow injecting this in class method
This commit is contained in:
parent
c3b59c8a12
commit
87fd74cbb6
8 changed files with 51 additions and 24 deletions
examples/napi
|
@ -254,6 +254,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
static newRaph(): NinjaTurtle␊
|
||||
getMaskColor(): string␊
|
||||
getName(): string␊
|
||||
returnThis(this: this): this␊
|
||||
}␊
|
||||
export type JsAssets = Assets␊
|
||||
export class Assets {␊
|
||||
|
|
Binary file not shown.
|
@ -21,6 +21,7 @@ import {
|
|||
getCwd,
|
||||
Animal,
|
||||
Kind,
|
||||
NinjaTurtle,
|
||||
ClassWithFactory,
|
||||
CustomNumEnum,
|
||||
Context,
|
||||
|
@ -173,6 +174,8 @@ test('class', (t) => {
|
|||
t.is(dog.type, Kind.Cat)
|
||||
const assets = new Assets()
|
||||
t.is(assets.get(1)?.filePath, 1)
|
||||
const turtle = NinjaTurtle.newRaph()
|
||||
t.is(turtle.returnThis(), turtle)
|
||||
})
|
||||
|
||||
test('class factory', (t) => {
|
||||
|
|
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -244,6 +244,7 @@ export class NinjaTurtle {
|
|||
static newRaph(): NinjaTurtle
|
||||
getMaskColor(): string
|
||||
getName(): string
|
||||
returnThis(this: this): this
|
||||
}
|
||||
export type JsAssets = Assets
|
||||
export class Assets {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use napi::{
|
||||
bindgen_prelude::{Buffer, ClassInstance},
|
||||
bindgen_prelude::{Buffer, ClassInstance, This},
|
||||
Env, Result,
|
||||
};
|
||||
|
||||
|
@ -229,6 +229,11 @@ impl NinjaTurtle {
|
|||
pub fn get_name(&self) -> &str {
|
||||
self.name.as_str()
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn return_this(&self, this: This) -> This {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(js_name = "Assets")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue