Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(napi-derive): implement instance_of for Class #1272

Merged
merged 1 commit into from Aug 17, 2022

Conversation

Brooooooklyn
Copy link
Sponsor Member

@Brooooooklyn Brooooooklyn commented Aug 17, 2022

#[napi]
pub struct ClassA {
  name: String
}

#[napi]
pub fn verify_and_return_name(env: Env, a: Unknown) -> Result<String> {
  if ClassA::instance_of(env, a)? {
    let a: &ClassA = unsafe { FromNapiRef::from_napi_ref(env.raw(), a.raw()) }?;
    Ok(a.name.clone())
  } else {
    Err(Error::new(Status::InvalidArg, "Object is not instance of ClassA".to_owned()))
  }
}

@Brooooooklyn Brooooooklyn merged commit 5030cfb into main Aug 17, 2022
@Brooooooklyn Brooooooklyn deleted the support-instanceof branch August 17, 2022 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant