feat(napi): add "run_script" for "Env" (#1393)
* 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>
This commit is contained in:
parent
486ce35c82
commit
d2531352aa
1 changed files with 7 additions and 0 deletions
|
@ -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()?;
|
||||
|
|
Loading…
Reference in a new issue