protected override object InnerCallFunction(string functionName, params object[] args) { object result = _dispatcher.Invoke(() => { using (CreateJsScope()) { try { JsValue globalObj = JsValue.GlobalObject; JsPropertyId functionId = JsPropertyId.FromString(functionName); bool functionExist = globalObj.HasProperty(functionId); if (!functionExist) { throw new JsRuntimeException( string.Format(CoreStrings.Runtime_FunctionNotExist, functionName)); } JsValue resultValue; JsValue functionValue = globalObj.GetProperty(functionId); if (args.Length > 0) { JsValue[] processedArgs = MapToScriptType(args); foreach (JsValue processedArg in processedArgs) { AddReferenceToValue(processedArg); } JsValue[] allProcessedArgs = new[] { globalObj } .Concat(processedArgs) .ToArray() ; resultValue = functionValue.CallFunction(allProcessedArgs); foreach (JsValue processedArg in processedArgs) { RemoveReferenceToValue(processedArg); } } else { resultValue = functionValue.CallFunction(globalObj); } return(MapToHostType(resultValue)); } catch (OriginalJsException e) { throw ConvertJsExceptionToJsRuntimeException(e); } } }); return(result); }
protected override object InnerCallFunction(string functionName, params object[] args) { object result = InvokeScript(() => { JsValue globalObj = JsValue.GlobalObject; JsPropertyId functionId = JsPropertyId.FromString(functionName); bool functionExist = globalObj.HasProperty(functionId); if (!functionExist) { throw new JsRuntimeException( string.Format(CoreStrings.Runtime_FunctionNotExist, functionName)); } JsValue resultValue; JsValue functionValue = globalObj.GetProperty(functionId); if (args.Length > 0) { JsValue[] processedArgs = MapToScriptType(args); foreach (JsValue processedArg in processedArgs) { AddReferenceToValue(processedArg); } JsValue[] allProcessedArgs = new[] { globalObj }.Concat(processedArgs).ToArray(); resultValue = functionValue.CallFunction(allProcessedArgs); foreach (JsValue processedArg in processedArgs) { RemoveReferenceToValue(processedArg); } } else { resultValue = functionValue.CallFunction(globalObj); } //modified by chuan.yin in 2017/4/29 //return MapToHostType(resultValue); return(ConvertJsObjectToNetObject(resultValue)); }); return(result); }
private void FreezeObject(JsValue objValue) { JsValue freezeMethodValue = JsValue.GlobalObject .GetProperty("Object") .GetProperty("freeze") ; freezeMethodValue.CallFunction(objValue); }
/// <summary> /// The promise continuation callback /// </summary> /// <param name="task">The task, represented as a JavaScript function</param> /// <param name="callbackState">The data argument to be passed to the callback</param> private static void PromiseContinuationCallback(JsValue task, IntPtr callbackState) { task.AddRef(); try { task.CallFunction(JsValue.GlobalObject); } finally { task.Release(); } }
private void PromiseContinuationCallback(JsValue task, IntPtr callbackState) { task.AddRef(); JsContext context = JsContext.Current; TimedFunction(DEFAULT_PROMISE_TIMEOUT, () => { using (new JsContext.Scope(context)) { task.CallFunction(JsValue.GlobalObject); task.Release(); } }, priority: JsTaskPriority.PROMISE); }
public static Task <JsValue> CallFunctionAsync(this JsValue value, object thisArg, params object[] args) { return(value.Context.RequestScopeAsync(_ => value.CallFunction(JsValue.FromObject(thisArg), args.Select(JsValue.FromObject).ToArray()))); }
protected override object InnerCallFunction(string functionName, params object[] args) { object result = _dispatcher.Invoke(() => { using (new JsScope(_jsContext)) { try { JsValue globalObj = JsValue.GlobalObject; JsPropertyId functionId = JsPropertyId.FromString(functionName); bool functionExist = globalObj.HasProperty(functionId); if (!functionExist) { throw new WrapperRuntimeException( string.Format(CoreStrings.Runtime_FunctionNotExist, functionName), EngineName, EngineVersion ); } JsValue resultValue; JsValue functionValue = globalObj.GetProperty(functionId); int argCount = args.Length; if (argCount > 0) { int processedArgCount = argCount + 1; var processedArgs = new JsValue[processedArgCount]; processedArgs[0] = globalObj; for (int argIndex = 0; argIndex < argCount; argIndex++) { JsValue processedArg = _typeMapper.MapToScriptType(args[argIndex]); AddReferenceToValue(processedArg); processedArgs[argIndex + 1] = processedArg; } try { resultValue = functionValue.CallFunction(processedArgs); } finally { for (int argIndex = 1; argIndex < processedArgCount; argIndex++) { RemoveReferenceToValue(processedArgs[argIndex]); } } } else { resultValue = functionValue.CallFunction(globalObj); } return(_typeMapper.MapToHostType(resultValue)); } catch (OriginalException e) { throw WrapJsException(e); } } }); return(result); }