Skip to content

Commit

Permalink
feat(napi): add "run_script" for "Env" (#1393)
Browse files Browse the repository at this point in the history
* add "run_script" for "Env"

* Apply suggestions from code review

use `AsRef<str>` instead of `&str`

Co-authored-by: LongYinan <lynweklm@gmail.com>

* use `AsRef<str>` instead of `&str`

Co-authored-by: LongYinan <lynweklm@gmail.com>
  • Loading branch information
F001 and Brooooooklyn committed Dec 16, 2022
1 parent 486ce35 commit d253135
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/napi/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,13 @@ impl Env {
check_status!(unsafe { sys::napi_close_handle_scope(self.0, handle_scope) })?;
result
}

pub fn run_script<S: AsRef<str>>(&self, script: S)->Result<JsObject> {
let s = self.create_string(script.as_ref())?;
let mut raw_value = ptr::null_mut();
check_status!(unsafe { sys::napi_run_script(self.0, s.raw(), &mut raw_value) })?;
Ok(unsafe { JsObject::from_raw_unchecked(self.0, raw_value) })
}

pub fn get_napi_version(&self) -> Result<u32> {
let global = self.get_global()?;
Expand Down

0 comments on commit d253135

Please sign in to comment.