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
|
@ -1021,6 +1021,13 @@ impl Env {
|
|||
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()?;
|
||||
let process: JsObject = global.get_named_property("process")?;
|
||||
|
|
Loading…
Reference in a new issue