public object CallFunction(JsFunction function, params object[] args) { try { visitor.ExecuteFunction(function, null, JsClr.ConvertParametersBack(visitor, args)); return(JsClr.ConvertParameter(visitor.Returned)); } catch (TargetInvocationException e) { string message = String.Format("{0}\n{1}: {2} in {3}" , e.InnerException.Message, moduleName, CurrentString, CurrentLine); throw new BitMobile.Utilities.Exceptions.JSException(message, e); } catch (BitMobile.Utilities.Exceptions.JsGlobalException e) { string message = String.Format("Error occured in script function:\n{0}\n{1}: {2} in {3}" , e.Message, moduleName, CurrentString, CurrentLine); throw new BitMobile.Utilities.Exceptions.JSException(message, e); } catch (Exception e) { string message = String.Format("{0}\n{1}: {2} in {3}" , e.Message, moduleName, CurrentString, CurrentLine); throw new BitMobile.Utilities.Exceptions.JSException(message, e); } }
public object CallFunction(JsFunction function, params object[] args) { visitor.ExecuteFunction(function, null, JsClr.ConvertParametersBack(visitor, args)); return(JsClr.ConvertParameter(visitor.Returned)); }
/// <summary> /// Runs a set of JavaScript statements and optionally returns a value if return is called /// </summary> /// <param name="program">The expression tree to execute</param> /// <param name="unwrap">Whether to unwrap the returned value to a CLR instance. <value>True</value> by default.</param> /// <returns>Optionaly, returns a value from the scripts</returns> /// <exception cref="System.ArgumentException" /> /// <exception cref="System.Security.SecurityException" /> /// <exception cref="Jint.JintException" /> public object Run(Program program, bool unwrap) { if (program == null) { throw new ArgumentException("Script can't be null", "script"); } visitor.DebugMode = this.DebugMode; //visitor.PermissionSet = permissionSet; if (DebugMode) { visitor.Step += OnStep; } try { visitor.Visit(program); } catch (SecurityException) { throw; } catch (JsException e) { string message = e.Message; if (e.Value.Class == JsError.TYPEOF) { message = ((JsError)e.Value).Value.ToString(); } StringBuilder stackTrace = new StringBuilder(); string source = String.Empty; if (DebugMode) { while (visitor.CallStack.Count > 0) { stackTrace.AppendLine(visitor.CallStack.Pop()); } if (stackTrace.Length > 0) { stackTrace.Insert(0, Environment.NewLine + "------ Stack Trace:" + Environment.NewLine); } } if (visitor.CurrentStatement.Source != null) { source = Environment.NewLine + visitor.CurrentStatement.Source.ToString() + Environment.NewLine + visitor.CurrentStatement.Source.Code; } throw new JintException(message + source + stackTrace, e); } catch (Exception e) { StringBuilder stackTrace = new StringBuilder(); string source = String.Empty; if (DebugMode) { while (visitor.CallStack.Count > 0) { stackTrace.AppendLine(visitor.CallStack.Pop()); } if (stackTrace.Length > 0) { stackTrace.Insert(0, Environment.NewLine + "------ Stack Trace:" + Environment.NewLine); } } if (visitor.CurrentStatement.Source != null) { source = Environment.NewLine + visitor.CurrentStatement.Source.ToString() + Environment.NewLine + visitor.CurrentStatement.Source.Code; } throw new JintException(e.Message + source + stackTrace, e.InnerException); } finally { visitor.Step -= OnStep; } return(visitor.Result == null ? null : unwrap?JsClr.ConvertParameter(visitor.Result) : visitor.Result); }