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:
F001 2022-12-16 15:56:36 +08:00 committed by GitHub
parent 486ce35c82
commit d2531352aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()?;