Skip to content

Commit 93c55b5

Browse files
committed
In JavaScriptEngineSwitcher.V8 improved implementation of the CallFunction method
1 parent 6a50fde commit 93c55b5

File tree

6 files changed

+12
-72
lines changed

6 files changed

+12
-72
lines changed

NuGet/JavaScriptEngineSwitcher.V8/JavaScriptEngineSwitcher.V8.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ This package does not contain the native ClearScript and V8 assemblies. Therefor
1717
* JavaScriptEngineSwitcher.V8.Native.win-x86
1818
* JavaScriptEngineSwitcher.V8.Native.win-x64</description>
1919
<summary>JavaScriptEngineSwitcher.V8 contains adapter `V8JsEngine` (wrapper for the Microsoft ClearScript.V8 version of May 13, 2017).</summary>
20-
<releaseNotes>Now during the rethrowing of exceptions are preserved the full call stack trace.</releaseNotes>
21-
<copyright>Copyright (c) 2013-2017 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
20+
<releaseNotes>Improved implementation of the `CallFunction` method.</releaseNotes>
21+
<copyright>Copyright (c) 2013-2018 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
2222
<language>en-US</language>
2323
<tags>JavaScriptEngineSwitcher JavaScript ECMAScript V8 ClearScript</tags>
2424
<dependencies>

NuGet/JavaScriptEngineSwitcher.V8/readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
--------------------------------------------------------------------------------
77

8-
Copyright (c) 2013-2017 Andrey Taritsyn - http://www.taritsyn.ru
8+
Copyright (c) 2013-2018 Andrey Taritsyn - http://www.taritsyn.ru
99

1010

1111
===========
@@ -25,7 +25,7 @@
2525
=============
2626
RELEASE NOTES
2727
=============
28-
Now during the rethrowing of exceptions are preserved the full call stack trace.
28+
Improved implementation of the `CallFunction` method.
2929

3030
=============
3131
DOCUMENTATION

src/JavaScriptEngineSwitcher.Msie/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[assembly: AssemblyConfiguration("")]
99
[assembly: AssemblyCompany("")]
1010
[assembly: AssemblyProduct("JavaScript Engine Switcher: MSIE")]
11-
[assembly: AssemblyCopyright("Copyright © 2013-2017 Andrey Taritsyn")]
11+
[assembly: AssemblyCopyright("Copyright © 2013-2018 Andrey Taritsyn")]
1212
[assembly: AssemblyTrademark("")]
1313
[assembly: AssemblyCulture("")]
1414

src/JavaScriptEngineSwitcher.V8/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[assembly: AssemblyConfiguration("")]
77
[assembly: AssemblyCompany("")]
88
[assembly: AssemblyProduct("JavaScript Engine Switcher: V8")]
9-
[assembly: AssemblyCopyright("Copyright © 2013-2017 Andrey Taritsyn")]
9+
[assembly: AssemblyCopyright("Copyright © 2013-2018 Andrey Taritsyn")]
1010
[assembly: AssemblyTrademark("")]
1111
[assembly: AssemblyCulture("")]
1212

src/JavaScriptEngineSwitcher.V8/V8JsEngine.cs

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
22
using System.Reflection;
3-
#if NET45
4-
using System.Runtime.ExceptionServices;
5-
#endif
63
using System.Text.RegularExpressions;
74

85
using Microsoft.ClearScript.V8;
@@ -42,11 +39,6 @@ public sealed class V8JsEngine : JsEngineBase
4239
/// </summary>
4340
private static OriginalUndefined _originalUndefinedValue;
4441

45-
/// <summary>
46-
/// Information about <code>InvokeMethod</code> method of <see cref="V8ScriptItem"/> class
47-
/// </summary>
48-
private static MethodInfo _v8ScriptItemInvokeMethodInfo;
49-
5042
/// <summary>
5143
/// Regular expression for working with the string representation of error
5244
/// </summary>
@@ -91,18 +83,17 @@ static V8JsEngine()
9183
{
9284
AssemblyResolver.Initialize();
9385
LoadUndefinedValue();
94-
LoadWinScriptItemInvokeMethodInfo();
9586
}
9687

9788
/// <summary>
98-
/// Constructs a instance of adapter for the V8 JS engine (Microsoft ClearScript.V8)
89+
/// Constructs an instance of adapter for the V8 JS engine (Microsoft ClearScript.V8)
9990
/// </summary>
10091
public V8JsEngine()
10192
: this(new V8Settings())
10293
{ }
10394

10495
/// <summary>
105-
/// Constructs a instance of adapter for the V8 JS engine (Microsoft ClearScript.V8)
96+
/// Constructs an instance of adapter for the V8 JS engine (Microsoft ClearScript.V8)
10697
/// </summary>
10798
/// <param name="settings">Settings of the V8 JS engine</param>
10899
public V8JsEngine(V8Settings settings)
@@ -166,36 +157,6 @@ private static void LoadUndefinedValue()
166157
}
167158
}
168159

169-
/// <summary>
170-
/// Loads a `InvokeMethod` method information of `Microsoft.ClearScript.V8.V8ScriptItem` type
171-
/// </summary>
172-
private static void LoadWinScriptItemInvokeMethodInfo()
173-
{
174-
const string typeName = "Microsoft.ClearScript.V8.V8ScriptItem";
175-
const string methodName = "InvokeMethod";
176-
177-
Assembly clearScriptAssembly = typeof(V8ScriptEngine).Assembly;
178-
Type v8ScriptItemType = clearScriptAssembly.GetType(typeName);
179-
MethodInfo v8ScriptItemInvokeMethodInfo = null;
180-
181-
if (v8ScriptItemType != null)
182-
{
183-
v8ScriptItemInvokeMethodInfo = v8ScriptItemType.GetMethod(methodName,
184-
BindingFlags.Instance | BindingFlags.Public);
185-
}
186-
187-
if (v8ScriptItemInvokeMethodInfo != null)
188-
{
189-
_v8ScriptItemInvokeMethodInfo = v8ScriptItemInvokeMethodInfo;
190-
}
191-
else
192-
{
193-
throw new JsEngineLoadException(
194-
string.Format(Strings.Runtime_MethodInfoNotLoaded, typeName, methodName),
195-
EngineName, EngineVersion);
196-
}
197-
}
198-
199160
/// <summary>
200161
/// Executes a mapping from the host type to a ClearScript type
201162
/// </summary>
@@ -330,32 +291,11 @@ protected override object InnerCallFunction(string functionName, params object[]
330291
{
331292
try
332293
{
333-
object obj = _jsEngine.Script;
334-
result = _v8ScriptItemInvokeMethodInfo.Invoke(obj, new object[] { functionName, processedArgs });
294+
result = _jsEngine.Invoke(functionName, processedArgs);
335295
}
336-
catch (TargetInvocationException e)
296+
catch (OriginalJsException e)
337297
{
338-
Exception innerException = e.InnerException;
339-
if (innerException != null)
340-
{
341-
var scriptEngineException = e.InnerException as OriginalJsException;
342-
if (scriptEngineException != null)
343-
{
344-
throw ConvertScriptEngineExceptionToJsRuntimeException(scriptEngineException);
345-
}
346-
#if NET45
347-
348-
ExceptionDispatchInfo.Capture(innerException).Throw();
349-
#elif NET40
350-
351-
innerException.PreserveStackTrace();
352-
throw innerException;
353-
#else
354-
#error No implementation for this target
355-
#endif
356-
}
357-
358-
throw;
298+
throw ConvertScriptEngineExceptionToJsRuntimeException(e);
359299
}
360300
}
361301

src/JavaScriptEngineSwitcher.V8/V8Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public int MaxExecutableSize
6262

6363

6464
/// <summary>
65-
/// Constructs instance of the V8 settings
65+
/// Constructs an instance of the V8 settings
6666
/// </summary>
6767
public V8Settings()
6868
{

0 commit comments

Comments
 (0)