public Promise(Function executor) { m_promiseTask = Task.Run(() => { if (executor != null) { var executorArguments = new Arguments(); executorArguments.Add(new ExternalFunction(Resolve)); executorArguments.Add(new ExternalFunction(Reject)); executor.Invoke(executorArguments); } return m_result; }, m_cancellationTokenSource.Token); }
private static JSC.JSValue ConvertDate(JSC.JSValue thisBind, JSC.Arguments args) { if(args.Length == 2 && args[1].ValueType == JSC.JSValueType.String) { // 2015-09-16T14:15:18.994Z var s = args[1].ToString(); if(s != null && s.Length == 24 && s[4] == '-' && s[7] == '-' && s[10] == 'T' && s[13] == ':' && s[16] == ':' && s[19] == '.') { var a = new JSC.Arguments(); a.Add(args[1]); var jdt = new JSL.Date(a); return JSC.JSValue.Wrap(jdt); } } return args[1]; }
public Promise then(Arguments args) { var onFullfilledFunction = args[0] as Function; if (onFullfilledFunction != null) { m_promiseTask.ContinueWith(t => { if (!t.IsCompleted) return; var innerArgs = new Arguments(); innerArgs.Add(m_promiseTask.Result); onFullfilledFunction.Invoke(innerArgs); }); } var onRejectedFunction = args[1] as Function; if (onRejectedFunction != null) { m_promiseTask.ContinueWith(t => { if (!t.IsCanceled) return; var innerArgs = new Arguments(); innerArgs.Add(m_promiseTask.Result); onRejectedFunction.Invoke(innerArgs); }); } return this; }
private JSObject Reject(JSObject thisBind, Arguments args) { m_result = args[0]; m_cancellationTokenSource.Cancel(); var errorArgs = new Arguments(); errorArgs.Add(m_result); throw new JSException(new Error(errorArgs)); }
protected override void SetProperty(JSValue name, JSValue value, PropertyScope propertyScope, bool throwOnError) { if (name.ToString() == "OnTick") { OnTick += (d) => { var arg = new Arguments(); arg.Add(Marshal(d)); var func = (value.Value as NiL.JS.BaseLibrary.Function); func.Call(arg); }; return; } base.SetProperty(name, value, propertyScope, throwOnError); }