Skip to content

Commit 81a6ca8

Browse files
committed
In ActiveScript modes now are uses the short names of error categories
1 parent f94863e commit 81a6ca8

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

NuGet/MsieJavaScriptEngine.nuspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of SassAndCoffee.JavaScript (http://github.com/paulcbetts/SassAndCoffee), Chakra Sample Hosts (http://github.com/panopticoncentral/chakra-host) and jsrt-dotnet (http://github.com/robpaveza/jsrt-dotnet).</description>
1414
<summary>This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine).</summary>
15-
<releaseNotes>1. Now during the rethrowing of exceptions are preserved the full call stack trace;
16-
2. Reduced a number of delegate-wrappers.</releaseNotes>
15+
<releaseNotes>In ActiveScript modes now are uses the short names of error categories.</releaseNotes>
1716
<copyright>Copyright (c) 2012-2017 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
1817
<language>en-US</language>
1918
<tags>JavaScript ECMAScript MSIE IE Edge Chakra</tags>

NuGet/readme.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
1. Now during the rethrowing of exceptions are preserved the full call stack
25-
trace;
26-
2. Reduced a number of delegate-wrappers.
24+
In ActiveScript modes now are uses the short names of error categories.
2725

2826
============
2927
PROJECT SITE

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.ScriptSite.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ private string GetErrorDetails(IActiveScriptError error)
4444
EXCEPINFO excepInfo;
4545
error.GetExceptionInfo(out excepInfo);
4646

47-
string errorDetails = excepInfo.bstrDescription;
47+
string errorDetails = string.Format("{0}: {1}",
48+
_jsEngine.ShortenErrorCategoryName(excepInfo.bstrSource), excepInfo.bstrDescription);
4849
if (_jsEngine._processDebugManagerWrapper != null)
4950
{
5051
string errorLocation = GetErrorLocation(error);

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ internal abstract partial class ActiveScriptJsEngineBase : InnerJsEngineBase
8585
/// </summary>
8686
private uint _nextSourceContext = 1;
8787

88+
/// <summary>
89+
/// Prefix of error category name
90+
/// </summary>
91+
private string _errorCategoryNamePrefix;
92+
8893

8994
/// <summary>
9095
/// Constructs an instance of the Active Script engine
@@ -106,12 +111,14 @@ protected ActiveScriptJsEngineBase(JsEngineMode engineMode, bool enableDebugging
106111
clsid = ClassId.Chakra;
107112
lowerIeVersion = "9";
108113
languageVersion = ScriptLanguageVersion.EcmaScript5;
114+
_errorCategoryNamePrefix = "JavaScript ";
109115
}
110116
else if (_engineMode == JsEngineMode.Classic)
111117
{
112118
clsid = ClassId.Classic;
113119
lowerIeVersion = "6";
114120
languageVersion = ScriptLanguageVersion.None;
121+
_errorCategoryNamePrefix = "Microsoft JScript ";
115122
}
116123
else
117124
{
@@ -254,7 +261,7 @@ private JsRuntimeException ConvertActiveScriptExceptionToJsRuntimeException(
254261
activeScriptException)
255262
{
256263
ErrorCode = activeScriptException.ErrorCode.ToString(CultureInfo.InvariantCulture),
257-
Category = activeScriptException.Subcategory,
264+
Category = ShortenErrorCategoryName(activeScriptException.Subcategory),
258265
LineNumber = (int)activeScriptException.LineNumber,
259266
ColumnNumber = activeScriptException.ColumnNumber,
260267
SourceFragment = activeScriptException.SourceError,
@@ -264,6 +271,33 @@ private JsRuntimeException ConvertActiveScriptExceptionToJsRuntimeException(
264271
return jsEngineException;
265272
}
266273

274+
/// <summary>
275+
/// Shortens a name of error category
276+
/// </summary>
277+
/// <param name="categoryName">Name of error category</param>
278+
/// <returns>Short name of error category</returns>
279+
private string ShortenErrorCategoryName(string categoryName)
280+
{
281+
if (categoryName == null)
282+
{
283+
throw new ArgumentNullException("categoryName");
284+
}
285+
286+
string shortCategoryName = categoryName;
287+
if (categoryName.StartsWith(_errorCategoryNamePrefix, StringComparison.Ordinal))
288+
{
289+
shortCategoryName = categoryName.Substring(_errorCategoryNamePrefix.Length);
290+
if (shortCategoryName.Length > 0)
291+
{
292+
char[] chars = shortCategoryName.ToCharArray();
293+
chars[0] = char.ToUpperInvariant(chars[0]);
294+
shortCategoryName = new string(chars);
295+
}
296+
}
297+
298+
return shortCategoryName;
299+
}
300+
267301
/// <summary>
268302
/// Starts debugging
269303
/// </summary>

0 commit comments

Comments
 (0)