Skip to content

Commit 2df6ec9

Browse files
committed
Now during the rethrowing of exceptions are preserved the full call stack trace
1 parent 5593946 commit 2df6ec9

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

NuGet/MsieJavaScriptEngine.nuspec

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +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. Switched to Apache license;
16-
2. In JsRT modes fixed a problems in calculation of error locations;
17-
3. An attempt was made to prevent occurrence of the access violation exception;
18-
4. Now the original exception is added to instance of the `JsRuntimeException` class as an inner exception;
19-
5. An attempt was made to prevent a blocking of finalizer's thread;
20-
6. Added support of identifier names compliant with ECMAScript 5.</releaseNotes>
15+
<releaseNotes>Now during the rethrowing of exceptions are preserved the full call stack trace.</releaseNotes>
2116
<copyright>Copyright (c) 2012-2017 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
2217
<language>en-US</language>
2318
<tags>JavaScript ECMAScript MSIE IE Edge Chakra</tags>

NuGet/readme.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
1. Switched to Apache license;
25-
2. In JsRT modes fixed a problems in calculation of error locations;
26-
3. An attempt was made to prevent occurrence of the access violation exception;
27-
4. Now the original exception is added to instance of the `JsRuntimeException`
28-
class as an inner exception;
29-
5. An attempt was made to prevent a blocking of finalizer's thread;
30-
6. Added support of identifier names compliant with ECMAScript 5.
24+
Now during the rethrowing of exceptions are preserved the full call stack trace.
3125

3226
============
3327
PROJECT SITE

src/MsieJavaScriptEngine.Net4/MsieJavaScriptEngine.Net40.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@
511511
<Link>Utilities\Utils.cs</Link>
512512
</Compile>
513513
<Compile Include="Utilities\DelegateExtensions.cs" />
514+
<Compile Include="Utilities\ExceptionExtensions.cs" />
514515
<Compile Include="Utilities\TypeInfo.cs" />
515516
</ItemGroup>
516517
<ItemGroup>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#if NET40
2+
using System;
3+
using System.Reflection;
4+
5+
namespace MsieJavaScriptEngine.Utilities
6+
{
7+
/// <summary>
8+
/// Exception extensions
9+
/// </summary>
10+
public static class ExceptionExtensions
11+
{
12+
/// <summary>
13+
/// Preserves a stack trace of exception
14+
/// </summary>
15+
/// <param name="source">The exception</param>
16+
public static void PreserveStackTrace(this Exception source)
17+
{
18+
if (source == null)
19+
{
20+
throw new ArgumentNullException("source");
21+
}
22+
23+
MethodInfo preserveStackTraceMethodInfo = typeof(Exception).GetMethod("InternalPreserveStackTrace",
24+
BindingFlags.Instance | BindingFlags.NonPublic);
25+
preserveStackTraceMethodInfo.Invoke(source, null);
26+
}
27+
}
28+
}
29+
#endif

src/MsieJavaScriptEngine/ScriptDispatcher.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
#if NETSTANDARD1_3 || NET45
4+
using System.Runtime.ExceptionServices;
5+
#endif
36
using System.Threading;
47

58
using MsieJavaScriptEngine.Utilities;
@@ -151,9 +154,17 @@ private object InnnerInvoke(Func<object> del)
151154
waitHandle.WaitOne();
152155
}
153156

154-
if (task.Exception != null)
157+
Exception exception = task.Exception;
158+
if (exception != null)
155159
{
156-
throw task.Exception;
160+
#if NETSTANDARD1_3 || NET45
161+
ExceptionDispatchInfo.Capture(exception).Throw();
162+
#elif NET40
163+
exception.PreserveStackTrace();
164+
throw exception;
165+
#else
166+
#error No implementation for this target
167+
#endif
157168
}
158169

159170
return task.Result;

0 commit comments

Comments
 (0)