示例#1
0
文件: JistEngine.cs 项目: Enerdy/Jist
		/// <summary>
		/// Calls a javascript function encapsulated by JsValue
		/// and returns it's result.
		/// </summary>
		public JsValue CallFunction(JsValue function, object thisObject, params object[] args) {
			object t = thisObject ?? (object)this;
			try {
				return function.Invoke(JsValue.FromObject(jsEngine, t), args.ToJsValueArray(jsEngine));
			} catch (JavaScriptException jex) {
				StringBuilder sb = new StringBuilder("JavaScript error: " + jex.Message + "\r\n");

				sb.AppendLine(string.Format(" at line {0} column {1}", jex.LineNumber, jex.Column));
				sb.AppendLine(jex.Location.Source);
				sb.AppendLine(jex.StackTrace);

				TShock.Log.ConsoleError(sb.ToString());

			} catch (ParserException pex) {
				StringBuilder sb = new StringBuilder("JavaScript parser error: " + pex.Message + "\r\n");

				sb.AppendLine(string.Format(" at line {0} column {1}", pex.LineNumber, pex.Column));
				sb.AppendLine(pex.Source);
				sb.AppendLine(pex.StackTrace);

				TShock.Log.ConsoleError(sb.ToString());
			} catch (Exception ex) {
				TShock.Log.ConsoleError(ex.ToString());
			}

			return JsValue.Undefined;
		}