private ClrFunctionInstance WrapDelegate(EchoDelegate _delegate) { return(Engine.AsJsFunction(new Func <JsValue, JsValue[], JsValue>((thisObject, args) => { _delegate(((args[0].IsNull() || args[0].IsUndefined()) ? null : ManticoreException.NativeInstanceForObject(args[0].AsObject())), Engine.Converter.AsNativeString(args[1])); return JsValue.Undefined; }))); }
/** * Echo the argument via the callback */ public void Echo(String arg, EchoDelegate callback) { JsValue[] args = new JsValue[] { Engine.Converter.AsJsString(arg), WrapDelegate(callback) }; var func = this.impl.Get("echo").As <FunctionInstance>(); Engine.Js(() => { func.Call(this.impl, args); }); } /**
/** * Echo the argument via the callback after setTimeout(10) */ public void EchoWithSetTimeout(String arg, EchoDelegate callback) { Engine.Js(() => { this.impl.echoWithSetTimeout(Engine.Converter.AsJsString(arg), WrapDelegate(callback)); }); }
private Action <dynamic, dynamic> WrapDelegate(EchoDelegate _delegate) { return(new Action <dynamic, dynamic>((error, arg) => { _delegate((Engine.IsNullOrUndefined(error) ? null : ManticoreException.NativeInstanceForObject(error)), Engine.Converter.AsNativeString(arg)); })); }