33using System . Collections . Generic ;
44using System . Runtime . InteropServices ;
55#endif
6+ using System . Text . RegularExpressions ;
67
78namespace MsieJavaScriptEngine . JsRt
89{
@@ -11,6 +12,13 @@ namespace MsieJavaScriptEngine.JsRt
1112 /// </summary>
1213 internal abstract class ChakraJsRtJsEngineBase : InnerJsEngineBase
1314 {
15+ /// <summary>
16+ /// Regular expression for working with the string representation of error
17+ /// </summary>
18+ private static readonly Regex _errorStringRegex =
19+ new Regex ( @"[ ]{3,5}at (?:[A-Za-z_\$][0-9A-Za-z_\$ ]* )?" +
20+ @"\([^\s*?""<>|][^\t\n\r*?""<>|]*?:(?<lineNumber>\d+):(?<columnNumber>\d+)\)" ) ;
21+
1422 /// <summary>
1523 /// JS source context
1624 /// </summary>
@@ -59,6 +67,31 @@ protected ChakraJsRtJsEngineBase(JsEngineMode engineMode, bool enableDebugging)
5967 }
6068
6169
70+ /// <summary>
71+ /// Gets a error coordinates from message
72+ /// </summary>
73+ /// <param name="message">Error message</param>
74+ /// <param name="lineNumber">Line number</param>
75+ /// <param name="columnNumber">Column number</param>
76+ protected static void GetErrorCoordinatesFromMessage ( string message , out int lineNumber ,
77+ out int columnNumber )
78+ {
79+ lineNumber = 0 ;
80+ columnNumber = 0 ;
81+
82+ if ( ! string . IsNullOrWhiteSpace ( message ) )
83+ {
84+ Match errorStringMatch = _errorStringRegex . Match ( message ) ;
85+ if ( errorStringMatch . Success )
86+ {
87+ GroupCollection errorStringGroups = errorStringMatch . Groups ;
88+
89+ lineNumber = int . Parse ( errorStringGroups [ "lineNumber" ] . Value ) ;
90+ columnNumber = int . Parse ( errorStringGroups [ "columnNumber" ] . Value ) ;
91+ }
92+ }
93+ }
94+
6295 /// <summary>
6396 /// Starts debugging
6497 /// </summary>
0 commit comments