2020-08-10 13:37:58 +09:00
|
|
|
use napi::{CallContext, JsFunction, JsNull, JsObject, Result};
|
2020-07-03 01:36:45 +09:00
|
|
|
|
|
|
|
#[js_function(1)]
|
|
|
|
pub fn call_function(ctx: CallContext) -> Result<JsNull> {
|
|
|
|
let js_func = ctx.get::<JsFunction>(0)?;
|
|
|
|
let js_string_hello = ctx.env.create_string("hello".as_ref())?.into_unknown()?;
|
|
|
|
let js_string_world = ctx.env.create_string("world".as_ref())?.into_unknown()?;
|
|
|
|
|
|
|
|
js_func.call(None, &[js_string_hello, js_string_world])?;
|
|
|
|
|
2020-07-03 01:31:50 +09:00
|
|
|
ctx.env.get_null()
|
2020-07-03 01:36:45 +09:00
|
|
|
}
|
|
|
|
|
2020-07-03 01:31:50 +09:00
|
|
|
#[js_function(1)]
|
|
|
|
pub fn call_function_with_this(ctx: CallContext<JsObject>) -> Result<JsNull> {
|
2020-08-10 13:37:58 +09:00
|
|
|
let js_this = &ctx.this;
|
2020-07-03 01:31:50 +09:00
|
|
|
let js_func = ctx.get::<JsFunction>(0)?;
|
2020-07-03 01:36:45 +09:00
|
|
|
|
2020-08-10 13:37:58 +09:00
|
|
|
js_func.call(Some(js_this), &[])?;
|
2020-07-03 01:36:45 +09:00
|
|
|
|
2020-07-03 01:31:50 +09:00
|
|
|
ctx.env.get_null()
|
2020-07-03 01:36:45 +09:00
|
|
|
}
|