static void PlatformInit() { RenderEngines["svg"] = () => new FontSvgCanvas(); RenderEngines["default"] = () => new FontSvgCanvas(); RenderEngines["html5"] = () => new Platform.JavaScript.Html5Canvas(); FileLoaders["default"] = () => new Platform.JavaScript.JsFileLoader(); // check whether webfont is loaded CheckFontLoad(); JsContext.JsCode("Math.log2 = Math.log2 || function(x) { return Math.log(x) * Math.LOG2E; };"); // try to build the find the alphaTab script url in case we are not in the webworker already if (HtmlContext.self.document.As <bool>()) { var scriptElement = HtmlContext.document.Member("currentScript").As <HtmlScriptElement>(); if (!scriptElement.As <bool>()) { // try to get javascript from exception stack try { var error = new JsError(); var stack = error.Member("stack"); if (!stack.As <bool>()) { throw error; } ScriptFile = ScriptFileFromStack(stack.As <JsString>()); } catch (JsError e) { var stack = e.Member("stack"); if (!stack.As <bool>()) { scriptElement = HtmlContext.document.querySelector("script[data-alphatab]").As <HtmlScriptElement>(); } else { ScriptFile = ScriptFileFromStack(stack.As <JsString>()); } } } // failed to automatically resolve if (string.IsNullOrEmpty(ScriptFile)) { if (!scriptElement.As <bool>()) { HtmlContext.console.warn( "Could not automatically find alphaTab script file for worker, please add the data-alphatab attribute to the script tag that includes alphaTab or provide it when initializing alphaTab"); } else { ScriptFile = scriptElement.src; } } } }
private static Exception ParseResponseException(JavascriptResponse response) { var jsErrorJSON = response.Message; // try parse js exception jsErrorJSON = jsErrorJSON.Substring(Math.Max(0, jsErrorJSON.IndexOf("{"))); jsErrorJSON = jsErrorJSON.Substring(0, jsErrorJSON.LastIndexOf("}") + 1); if (!string.IsNullOrEmpty(jsErrorJSON)) { JsError jsError = null; try { jsError = DeserializeJSON <JsError>(jsErrorJSON); } catch { // ignore will throw error at the end } if (jsError != null) { jsError.Name = jsError.Name ?? ""; jsError.Message = jsError.Message ?? ""; jsError.Stack = jsError.Stack ?? ""; var jsStack = jsError.Stack.Substring(Math.Min(jsError.Stack.Length, (jsError.Name + ": " + jsError.Message).Length)).Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); jsStack = jsStack.Select(l => l.Substring(1)).ToArray(); // " at" -> " at" return(new JavascriptException(jsError.Name, jsError.Message, jsStack)); } } return(new JavascriptException("Javascript Error", response.Message, new string[0])); }
internal JsException(JsError errorNumber, JsContext context) { Value = null; m_context = (context == null ? null : context.Clone()); FileContext = (context == null ? null : context.Document.FileContext); ErrorCode = errorNumber; CanRecover = true; }
private JsScannerException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { throw new ArgumentNullException("info"); } m_errorId = (JsError)Enum.Parse(typeof(JsError), info.GetString("errorid")); }
private static Exception ParseResponseException(JavascriptResponse response, IEnumerable <string> evaluatedScriptFunctions) { var jsErrorJSON = response.Message; // try parse js exception jsErrorJSON = jsErrorJSON.Substring(Math.Max(0, jsErrorJSON.IndexOf("{"))); jsErrorJSON = jsErrorJSON.Substring(0, jsErrorJSON.LastIndexOf("}") + 1); var evaluatedStackFrames = evaluatedScriptFunctions.Where(f => !string.IsNullOrEmpty(f)) .Select(f => new JavascriptStackFrame() { FunctionName = f, SourceName = "eval" }); if (!string.IsNullOrEmpty(jsErrorJSON)) { JsError jsError = null; try { jsError = DeserializeJSON <JsError>(jsErrorJSON); } catch { // ignore will throw error at the end } if (jsError != null) { jsError.Name = jsError.Name ?? ""; jsError.Message = jsError.Message ?? ""; jsError.Stack = jsError.Stack ?? ""; var jsStack = jsError.Stack.Substring(Math.Min(jsError.Stack.Length, (jsError.Name + ": " + jsError.Message).Length)) .Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); var parsedStack = new List <JavascriptStackFrame>(); parsedStack.AddRange(evaluatedStackFrames); foreach (var stackFrame in jsStack) { var frameParts = StackFrameRegex.Match(stackFrame); if (frameParts.Success) { parsedStack.Add(new JavascriptStackFrame() { FunctionName = frameParts.Groups["method"].Value, SourceName = frameParts.Groups["location"].Value, LineNumber = int.Parse(frameParts.Groups["line"].Value), ColumnNumber = int.Parse(frameParts.Groups["column"].Value) }); } } return(new JavascriptException(jsError.Name, jsError.Message, parsedStack)); } } return(new JavascriptException("Javascript Error", response.Message, evaluatedStackFrames)); }
public virtual Exception InternalInit(JsError error) { if (stacktrace != null) { return(this); } stacktrace = error.stack; toStringSaved = toString(); return(this); }
private static void PlatformInit() { // try to build the find the alphaTab script url in case we are not in the webworker already if (HtmlContext.self.document.As <bool>()) { var scriptElement = HtmlContext.document.Member("currentScript").As <HtmlScriptElement>(); if (!scriptElement.As <bool>()) { // try to get javascript from exception stack try { var error = new JsError(); var stack = error.Member("stack"); if (!stack.As <bool>()) { throw error; } ScriptFile = ScriptFileFromStack(stack.As <JsString>()); } catch (JsError e) { var stack = e.Member("stack"); if (!stack.As <bool>()) { scriptElement = HtmlContext.document.querySelector("script[data-alphasynth]").As <HtmlScriptElement>(); } else { ScriptFile = ScriptFileFromStack(stack.As <JsString>()); } } } // failed to automatically resolve if (string.IsNullOrEmpty(ScriptFile)) { if (!scriptElement.As <bool>()) { HtmlContext.console.warn( "Could not automatically find alphaSynth script file for worker, please add the data-alphasynth attribute to the script tag that includes alphaSynth or provide it when initializing alphaSynth"); } else { ScriptFile = scriptElement.src; } } } }
/// <summary> /// Return the default severity for a given JSError value /// guide: 0 == there will be a run-time error if this code executes /// 1 == the programmer probably did not intend to do this /// 2 == this can lead to cross-browser of future problems. /// 3 == this can lead to performance problems /// 4 == this is just not right /// </summary> /// <param name="errorCode">error code</param> /// <returns>severity</returns> public static int GetSeverity(JsError errorCode) { switch (errorCode) { case JsError.AmbiguousCatchVar: case JsError.AmbiguousNamedFunctionExpression: case JsError.NumericOverflow: case JsError.StrictComparisonIsAlwaysTrueOrFalse: return(1); case JsError.ArrayLiteralTrailingComma: case JsError.DuplicateCatch: case JsError.DuplicateConstantDeclaration: case JsError.DuplicateLexicalDeclaration: case JsError.KeywordUsedAsIdentifier: case JsError.MisplacedFunctionDeclaration: case JsError.ObjectLiteralKeyword: return(2); case JsError.ArgumentNotReferenced: case JsError.DuplicateName: case JsError.FunctionNotReferenced: case JsError.UndeclaredFunction: case JsError.UndeclaredVariable: case JsError.VariableDefinedNotReferenced: return(3); case JsError.StatementBlockExpected: case JsError.SuspectAssignment: case JsError.SuspectSemicolon: case JsError.SuspectEquality: case JsError.WithNotRecommended: case JsError.ObjectConstructorTakesNoArguments: case JsError.NumericMaximum: case JsError.NumericMinimum: case JsError.OctalLiteralsDeprecated: case JsError.FunctionNameMustBeIdentifier: case JsError.SemicolonInsertion: return(4); default: // all others return(0); } }
internal void HandleError(JsError errorId, bool forceToError) { if ((errorId != JsError.UndeclaredVariable && errorId != JsError.UndeclaredFunction) || !Document.HasAlreadySeenErrorFor(Code)) { var error = new JsException(errorId, this); if (forceToError) { error.IsError = true; } else { error.IsError = error.Severity < 2; } Document.HandleError(error); } }
private static Exception ParseException(Exception exception, IEnumerable<string> evaluatedScriptFunctions) { var jsErrorJSON = ((exception is AggregateException aggregateException) ? aggregateException.InnerExceptions.FirstOrDefault(e => IsInternalException(e.Message))?.Message : exception.Message) ?? ""; // try parse js exception jsErrorJSON = jsErrorJSON.Substring(Math.Max(0, jsErrorJSON.IndexOf("{"))); jsErrorJSON = jsErrorJSON.Substring(0, jsErrorJSON.LastIndexOf("}") + 1); var evaluatedStackFrames = evaluatedScriptFunctions.Where(f => !string.IsNullOrEmpty(f)) .Select(f => new JavascriptStackFrame(f, "eval", 0, 0)); if (!string.IsNullOrEmpty(jsErrorJSON)) { JsError jsError = null; try { jsError = DeserializeJSON<JsError>(jsErrorJSON); } catch { // ignore will throw error at the end } if (jsError != null) { jsError.Name = jsError.Name ?? ""; jsError.Message = jsError.Message ?? ""; jsError.Stack = jsError.Stack ?? ""; var jsStack = jsError.Stack.Substring(Math.Min(jsError.Stack.Length, (jsError.Name + ": " + jsError.Message).Length)) .Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); var parsedStack = new List<JavascriptStackFrame>(); parsedStack.AddRange(evaluatedStackFrames); foreach (var stackFrame in jsStack) { var frameParts = StackFrameRegex.Match(stackFrame); if (frameParts.Success) { parsedStack.Add(new JavascriptStackFrame(frameParts.Groups["method"].Value, frameParts.Groups["location"].Value, int.Parse(frameParts.Groups["column"].Value), int.Parse(frameParts.Groups["line"].Value))); } } return new JavascriptException(jsError.Name, jsError.Message, parsedStack); } } return new JavascriptException(exception.Message, evaluatedStackFrames, exception.StackTrace); }
protected void onRequestFailed(JsError jsError, JsString jsString, jqXHR arg3) { jsUtils.inst.hideLoading(); }
public static string GetStackTraceFromError(JsError error) { throw new NotImplementedException(); }
public JsScannerException() { m_errorId = JsError.SyntaxError; }
static void PlatformInit() { RenderEngines["svg"] = () => new CssFontSvgCanvas(); RenderEngines["default"] = () => new CssFontSvgCanvas(); RenderEngines["html5"] = () => new Platform.JavaScript.Html5Canvas(); // check whether webfont is loaded CheckFontLoad(); JsContext.JsCode("Math.log2 = Math.log2 || function(x) { return Math.log(x) * Math.LOG2E; };"); // try to build the find the alphaTab script url in case we are not in the webworker already if (HtmlContext.self.document.As <bool>()) { /** * VB Loader For IE * This code is based on the code of * http://nagoon97.com/reading-binary-files-using-ajax/ * Copyright (c) 2008 Andy G.P. Na <*****@*****.**> * The source code is freely distributable under the terms of an MIT-style license. */ var vbAjaxLoader = new StringBuilder(); vbAjaxLoader.AppendLine("<script type=\"text/vbscript\">"); vbAjaxLoader.AppendLine("Function VbAjaxLoader(method, fileName)"); vbAjaxLoader.AppendLine(" Dim xhr"); vbAjaxLoader.AppendLine(" Set xhr = CreateObject(\"Microsoft.XMLHTTP\")"); vbAjaxLoader.AppendLine(" xhr.Open method, fileName, False"); vbAjaxLoader.AppendLine(" xhr.setRequestHeader \"Accept-Charset\", \"x-user-defined\""); vbAjaxLoader.AppendLine(" xhr.send"); vbAjaxLoader.AppendLine(" Dim byteArray()"); vbAjaxLoader.AppendLine(" if xhr.Status = 200 Then"); vbAjaxLoader.AppendLine(" Dim byteString"); vbAjaxLoader.AppendLine(" Dim i"); vbAjaxLoader.AppendLine(" byteString=xhr.responseBody"); vbAjaxLoader.AppendLine(" ReDim byteArray(LenB(byteString))"); vbAjaxLoader.AppendLine(" For i = 1 To LenB(byteString)"); vbAjaxLoader.AppendLine(" byteArray(i-1) = AscB(MidB(byteString, i, 1))"); vbAjaxLoader.AppendLine(" Next"); vbAjaxLoader.AppendLine(" End If"); vbAjaxLoader.AppendLine(" VbAjaxLoader=byteArray"); vbAjaxLoader.AppendLine("End Function"); vbAjaxLoader.AppendLine("</script>"); HtmlContext.document.write(vbAjaxLoader.ToString()); var scriptElement = HtmlContext.document.Member("currentScript").As <HtmlScriptElement>(); if (!scriptElement.As <bool>()) { // try to get javascript from exception stack try { var error = new JsError(); var stack = error.Member("stack"); if (!stack.As <bool>()) { throw error; } ScriptFile = ScriptFileFromStack(stack.As <JsString>()); } catch (JsError e) { var stack = e.Member("stack"); if (!stack.As <bool>()) { scriptElement = HtmlContext.document.querySelector("script[data-alphatab]").As <HtmlScriptElement>(); } else { ScriptFile = ScriptFileFromStack(stack.As <JsString>()); } } } // failed to automatically resolve if (string.IsNullOrEmpty(ScriptFile)) { if (!scriptElement.As <bool>()) { HtmlContext.console.warn( "Could not automatically find alphaTab script file for worker, please add the data-alphatab attribute to the script tag that includes alphaTab or provide it when initializing alphaTab"); } else { ScriptFile = scriptElement.src; } } } }
internal void HandleError(JsError errorId) { HandleError(errorId, false); }
/// <summary> /// Assertion to test if a callback throws an exception when run. /// </summary> /// <param name="block"></param> /// <param name="expected"></param> /// <param name="message"></param> /// <remarks> /// throws( block: Function(), expected: Error, message: String ) /// When testing code that is expected to throw an exception based on a specific set of circumstances, use throws() to catch the error object for testing and comparison. /// </remarks> public static void throws(JsAction block, JsError expected, JsString message) { }
public LoggingEvent(Logger logger, JsDate timeStamp, Level level, JsArray messages, JsError exception) { }
internal JsScannerException(JsError errorId) : base(s_syntaxErrorMsg) { m_errorId = errorId; }
//--------------------------------------------------------------------------------------- // ReportError // // Generate a parser error. // The function is told whether or not next call to GetToken() should return the same // token or not //--------------------------------------------------------------------------------------- private void ReportError(JsError errorId, JsContext context, bool skipToken) { Debug.Assert(context != null); int previousSeverity = m_severity; m_severity = JsException.GetSeverity(errorId); // EOF error is special and it's the last error we can possibly get if (JsToken.EndOfFile == context.Token) EOFError(errorId); // EOF context is special else { // report the error if not in error condition and the // error for this token is not worse than the one for the // previous token if (m_goodTokensProcessed > 0 || m_severity < previousSeverity) context.HandleError(errorId); // reset proper info if (skipToken) m_goodTokensProcessed = -1; else { m_useCurrentForNext = true; m_goodTokensProcessed = 0; } } }
//--------------------------------------------------------------------------------------- // EOFError // // Create a context for EOF error. The created context points to the end of the source // code. Assume the the scanner actually reached the end of file //--------------------------------------------------------------------------------------- private void EOFError(JsError errorId) { JsContext eofCtx = m_currentToken.Clone(); eofCtx.StartLineNumber = m_scanner.CurrentLine; eofCtx.StartLinePosition = m_scanner.StartLinePosition; eofCtx.EndLineNumber = eofCtx.StartLineNumber; eofCtx.EndLinePosition = eofCtx.StartLinePosition; eofCtx.StartPosition = m_document.Source.Length; eofCtx.EndPosition++; eofCtx.HandleError(errorId); }
//--------------------------------------------------------------------------------------- // ReportError // // Generate a parser error. // When no context is provided the token is missing so the context is the current position // The function is told whether or not next call to GetToken() should return the same // token or not //--------------------------------------------------------------------------------------- private void ReportError(JsError errorId, bool skipToken) { // get the current position token JsContext context = m_currentToken.Clone(); ReportError(errorId, context, skipToken); }
//--------------------------------------------------------------------------------------- // ReportError // // Generate a parser error. // When no context is provided the token is missing so the context is the current position //--------------------------------------------------------------------------------------- private void ReportError(JsError errorId) { ReportError(errorId, false); }
protected void onRequestFailed(JsError jsError, JsString jsString, jqXHR arg3) { }
public JsScannerException(string message, Exception innerException) : base(message, innerException) { m_errorId = JsError.SyntaxError; }
public override Exception InternalInit(JsError error) { return(base.InternalInit(nativeException)); }
/// <param name="exc">source exception</param> /// <param name="args">arguments</param> public GlobalError(JsError exc, JsArray args) { throw new NotImplementedException(); }
public void AssertException(Action<object> callback, JsError exception = null, object re = null, string msg = null) { throw new NotImplementedException(); }
public JsException(JsError nativeException) { this.nativeException = nativeException; }
private static void PlatformInit() { // try to build the find the alphaTab script url in case we are not in the webworker already if (HtmlContext.self.document.As<bool>()) { var scriptElement = HtmlContext.document.Member("currentScript").As<HtmlScriptElement>(); if (!scriptElement.As<bool>()) { // try to get javascript from exception stack try { var error = new JsError(); var stack = error.Member("stack"); if (!stack.As<bool>()) { throw error; } ScriptFile = ScriptFileFromStack(stack.As<JsString>()); } catch (JsError e) { var stack = e.Member("stack"); if (!stack.As<bool>()) { scriptElement = HtmlContext.document.querySelector("script[data-alphasynth]").As<HtmlScriptElement>(); } else { ScriptFile = ScriptFileFromStack(stack.As<JsString>()); } } } // failed to automatically resolve if (!string.IsNullOrEmpty(ScriptFile)) { if (!scriptElement.As<bool>()) { HtmlContext.console.warn( "Could not automatically find alphaSynth script file for worker, please add the data-alphasynth attribute to the script tag that includes alphaSynth or provide it when initializing alphaSynth"); } else { ScriptFile = scriptElement.src; } } } }
/// <summary> /// Returns whether the logger is enabled for the specified level /// </summary> /// <param name="level"></param> /// <param name="exception"></param> /// <returns></returns> public JsBoolean isEnabledFor(Level level, JsError exception) { return(false); }
static void PlatformInit() { RenderEngines["svg"] = () => new FontSvgCanvas(); RenderEngines["default"] = () => new FontSvgCanvas(); RenderEngines["html5"] = () => new Platform.JavaScript.Html5Canvas(); FileLoaders["default"] = () => new Platform.JavaScript.JsFileLoader(); // check whether webfont is loaded CheckFontLoad(); JsContext.JsCode("Math.log2 = Math.log2 || function(x) { return Math.log(x) * Math.LOG2E; };"); // try to build the find the alphaTab script url in case we are not in the webworker already if (HtmlContext.self.document.As<bool>()) { var scriptElement = HtmlContext.document.Member("currentScript").As<HtmlScriptElement>(); if (!scriptElement.As<bool>()) { // try to get javascript from exception stack try { var error = new JsError(); var stack = error.Member("stack"); if (!stack.As<bool>()) { throw error; } ScriptFile = ScriptFileFromStack(stack.As<JsString>()); } catch (JsError e) { var stack = e.Member("stack"); if (!stack.As<bool>()) { scriptElement = HtmlContext.document.querySelector("script[data-alphatab]").As<HtmlScriptElement>(); } else { ScriptFile = ScriptFileFromStack(stack.As<JsString>()); } } } // failed to automatically resolve if (string.IsNullOrEmpty(ScriptFile)) { if (!scriptElement.As<bool>()) { HtmlContext.console.warn( "Could not automatically find alphaTab script file for worker, please add the data-alphatab attribute to the script tag that includes alphaTab or provide it when initializing alphaTab"); } else { ScriptFile = scriptElement.src; } } } }
public void AssertException(Action <object> callback, JsError exception = null, object re = null, string msg = null) { throw new NotImplementedException(); }
/// <summary> /// Returns whether the logger is enabled for the specified level /// </summary> /// <param name="level"></param> /// <param name="exception"></param> /// <returns></returns> public JsBoolean isEnabledFor(Level level, JsError exception) { return false; }
public Exception InternalInit(JsError error) { stacktrace = error.stack; toStringSaved = toString(); return(this); }
/// <summary> /// Return the default severity for a given JSError value /// guide: 0 == there will be a run-time error if this code executes /// 1 == the programmer probably did not intend to do this /// 2 == this can lead to cross-browser of future problems. /// 3 == this can lead to performance problems /// 4 == this is just not right /// </summary> /// <param name="errorCode">error code</param> /// <returns>severity</returns> public static int GetSeverity(JsError errorCode) { switch (errorCode) { case JsError.AmbiguousCatchVar: case JsError.AmbiguousNamedFunctionExpression: case JsError.NumericOverflow: case JsError.StrictComparisonIsAlwaysTrueOrFalse: return 1; case JsError.ArrayLiteralTrailingComma: case JsError.DuplicateCatch: case JsError.DuplicateConstantDeclaration: case JsError.DuplicateLexicalDeclaration: case JsError.KeywordUsedAsIdentifier: case JsError.MisplacedFunctionDeclaration: case JsError.ObjectLiteralKeyword: return 2; case JsError.ArgumentNotReferenced: case JsError.DuplicateName: case JsError.FunctionNotReferenced: case JsError.UndeclaredFunction: case JsError.UndeclaredVariable: case JsError.VariableDefinedNotReferenced: return 3; case JsError.StatementBlockExpected: case JsError.SuspectAssignment: case JsError.SuspectSemicolon: case JsError.SuspectEquality: case JsError.WithNotRecommended: case JsError.ObjectConstructorTakesNoArguments: case JsError.NumericMaximum: case JsError.NumericMinimum: case JsError.OctalLiteralsDeprecated: case JsError.FunctionNameMustBeIdentifier: case JsError.SemicolonInsertion: return 4; default: // all others return 0; } }