feat(napi-derive): allow injecting this in class method

This commit is contained in:
LongYinan 2022-07-05 23:09:40 +08:00
parent c3b59c8a12
commit 87fd74cbb6
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
8 changed files with 51 additions and 24 deletions

View file

@ -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 {␊

View file

@ -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) => {

View file

@ -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 {

View file

@ -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")]