fix(napi): remove useless FromNapiValue bound check for ValidateNapiValue (#1999)
This commit is contained in:
parent
b03edafaff
commit
d962e34d3a
7 changed files with 38 additions and 1 deletions
|
@ -126,7 +126,7 @@ pub trait FromNapiMutRef {
|
|||
) -> Result<&'static mut Self>;
|
||||
}
|
||||
|
||||
pub trait ValidateNapiValue: FromNapiValue + TypeName {
|
||||
pub trait ValidateNapiValue: TypeName {
|
||||
/// # Safety
|
||||
///
|
||||
/// this function called to validate whether napi value passed to rust is valid type
|
||||
|
|
|
@ -522,6 +522,11 @@ Generated by [AVA](https://avajs.dev).
|
|||
callback: (err: Error | null, arg: number) => any␊
|
||||
}␊
|
||||
␊
|
||||
export interface ObjectOnlyToJs {␊
|
||||
name: number␊
|
||||
dependencies: any␊
|
||||
}␊
|
||||
␊
|
||||
export function optionEnd(callback: (arg0: string, arg1?: string | undefined | null) => void): void␊
|
||||
␊
|
||||
export function optionOnly(callback: (arg0?: string | undefined | null) => void): void␊
|
||||
|
@ -584,6 +589,8 @@ Generated by [AVA](https://avajs.dev).
|
|||
␊
|
||||
export function returnNull(): null␊
|
||||
␊
|
||||
export function returnObjectOnlyToJs(): ObjectOnlyToJs␊
|
||||
␊
|
||||
export function returnUndefined(): void␊
|
||||
␊
|
||||
export function returnUndefinedIfInvalid(input: boolean): boolean␊
|
||||
|
|
Binary file not shown.
|
@ -169,6 +169,7 @@ import {
|
|||
getModuleFileName,
|
||||
throwSyntaxError,
|
||||
type AliasedStruct,
|
||||
returnObjectOnlyToJs,
|
||||
} from '../index.cjs'
|
||||
|
||||
import { test } from './test.framework.js'
|
||||
|
@ -518,6 +519,13 @@ test('object', (t) => {
|
|||
bar: '3',
|
||||
}),
|
||||
)
|
||||
t.deepEqual(returnObjectOnlyToJs(), {
|
||||
name: 42,
|
||||
dependencies: {
|
||||
'@napi-rs/cli': '^3.0.0',
|
||||
rollup: '^4.0.0',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('get str from object', (t) => {
|
||||
|
|
|
@ -501,6 +501,7 @@ module.exports.returnEitherClass = nativeBinding.returnEitherClass
|
|||
module.exports.returnFromSharedCrate = nativeBinding.returnFromSharedCrate
|
||||
module.exports.returnJsFunction = nativeBinding.returnJsFunction
|
||||
module.exports.returnNull = nativeBinding.returnNull
|
||||
module.exports.returnObjectOnlyToJs = nativeBinding.returnObjectOnlyToJs
|
||||
module.exports.returnUndefined = nativeBinding.returnUndefined
|
||||
module.exports.returnUndefinedIfInvalid = nativeBinding.returnUndefinedIfInvalid
|
||||
module.exports.returnUndefinedIfInvalidPromise = nativeBinding.returnUndefinedIfInvalidPromise
|
||||
|
|
|
@ -512,6 +512,11 @@ export interface ObjectOnlyFromJs {
|
|||
callback: (err: Error | null, arg: number) => any
|
||||
}
|
||||
|
||||
export interface ObjectOnlyToJs {
|
||||
name: number
|
||||
dependencies: any
|
||||
}
|
||||
|
||||
export function optionEnd(callback: (arg0: string, arg1?: string | undefined | null) => void): void
|
||||
|
||||
export function optionOnly(callback: (arg0?: string | undefined | null) => void): void
|
||||
|
@ -574,6 +579,8 @@ export function returnJsFunction(): (...args: any[]) => any
|
|||
|
||||
export function returnNull(): null
|
||||
|
||||
export function returnObjectOnlyToJs(): ObjectOnlyToJs
|
||||
|
||||
export function returnUndefined(): void
|
||||
|
||||
export function returnUndefinedIfInvalid(input: boolean): boolean
|
||||
|
|
|
@ -131,3 +131,17 @@ fn object_get_named_property_should_perform_typecheck(obj: Object) -> Result<()>
|
|||
obj.get_named_property::<String>("bar")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[napi(object, object_from_js = false)]
|
||||
struct ObjectOnlyToJs {
|
||||
pub name: u32,
|
||||
pub dependencies: serde_json::Value,
|
||||
}
|
||||
|
||||
#[napi]
|
||||
fn return_object_only_to_js() -> ObjectOnlyToJs {
|
||||
ObjectOnlyToJs {
|
||||
name: 42,
|
||||
dependencies: serde_json::json!({ "@napi-rs/cli": "^3.0.0", "rollup": "^4.0.0" }),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue