Skip to content

Commit 9cb704a

Browse files
committed
In JavaScriptEngineSwitcher.V8 improved implementation of the CallFunction method
1 parent 138ebb3 commit 9cb704a

File tree

3 files changed

+9
-76
lines changed

3 files changed

+9
-76
lines changed

NuGet/JavaScriptEngineSwitcher.V8/JavaScriptEngineSwitcher.V8.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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 5.4.10).</summary>
20-
<releaseNotes>Microsoft ClearScript.V8 was updated to version 5.4.10.</releaseNotes>
20+
<releaseNotes>Improved implementation of the `CallFunction` method.</releaseNotes>
2121
<copyright>Copyright (c) 2013-2017 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
2222
<language>en-US</language>
2323
<tags>JavaScriptEngineSwitcher JavaScript ECMAScript V8 ClearScript</tags>

NuGet/JavaScriptEngineSwitcher.V8/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
=============
2626
RELEASE NOTES
2727
=============
28-
Microsoft ClearScript.V8 was updated to version 5.4.10.
28+
Improved implementation of the `CallFunction` method.
2929

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

src/JavaScriptEngineSwitcher.V8/V8JsEngine.cs

Lines changed: 7 additions & 74 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;
@@ -44,11 +41,6 @@ public sealed class V8JsEngine : JsEngineBase
4441
/// </summary>
4542
private static OriginalUndefined _originalUndefinedValue;
4643

47-
/// <summary>
48-
/// Information about <code>InvokeMethod</code> method of <see cref="V8ScriptItem"/> class
49-
/// </summary>
50-
private static MethodInfo _v8ScriptItemInvokeMethodInfo;
51-
5244
/// <summary>
5345
/// Regular expression for working with the string representation of error
5446
/// </summary>
@@ -69,7 +61,6 @@ static V8JsEngine()
6961
{
7062
AssemblyResolver.Initialize();
7163
LoadUndefinedValue();
72-
LoadWinScriptItemInvokeMethodInfo();
7364
}
7465

7566
/// <summary>
@@ -144,36 +135,6 @@ private static void LoadUndefinedValue()
144135
}
145136
}
146137

147-
/// <summary>
148-
/// Loads a `InvokeMethod` method information of `Microsoft.ClearScript.V8.V8ScriptItem` type
149-
/// </summary>
150-
private static void LoadWinScriptItemInvokeMethodInfo()
151-
{
152-
const string typeName = "Microsoft.ClearScript.V8.V8ScriptItem";
153-
const string methodName = "InvokeMethod";
154-
155-
Assembly clearScriptAssembly = typeof(V8ScriptEngine).Assembly;
156-
Type v8ScriptItemType = clearScriptAssembly.GetType(typeName);
157-
MethodInfo v8ScriptItemInvokeMethodInfo = null;
158-
159-
if (v8ScriptItemType != null)
160-
{
161-
v8ScriptItemInvokeMethodInfo = v8ScriptItemType.GetMethod(methodName,
162-
BindingFlags.Instance | BindingFlags.Public);
163-
}
164-
165-
if (v8ScriptItemInvokeMethodInfo != null)
166-
{
167-
_v8ScriptItemInvokeMethodInfo = v8ScriptItemInvokeMethodInfo;
168-
}
169-
else
170-
{
171-
throw new JsEngineLoadException(
172-
string.Format(Strings.Runtime_MethodInfoNotLoaded, typeName, methodName),
173-
EngineName, EngineVersion);
174-
}
175-
}
176-
177138
#region Mapping
178139

179140
/// <summary>
@@ -329,43 +290,15 @@ protected override object InnerCallFunction(string functionName, params object[]
329290
{
330291
try
331292
{
332-
object obj = _jsEngine.Script;
333-
result = _v8ScriptItemInvokeMethodInfo.Invoke(obj, new object[] { functionName, processedArgs });
293+
result = _jsEngine.Invoke(functionName, processedArgs);
334294
}
335-
catch (TargetInvocationException e)
295+
catch (OriginalScriptEngineException e)
296+
{
297+
throw ConvertScriptEngineExceptionToHostException(e);
298+
}
299+
catch (OriginalScriptInterruptedException e)
336300
{
337-
Exception innerException = e.InnerException;
338-
if (innerException != null)
339-
{
340-
if (innerException is IOriginalScriptEngineException)
341-
{
342-
var scriptEngineException = innerException as OriginalScriptEngineException;
343-
if (scriptEngineException != null)
344-
{
345-
throw ConvertScriptEngineExceptionToHostException(scriptEngineException);
346-
}
347-
348-
var scriptInterruptedException =
349-
innerException as OriginalScriptInterruptedException;
350-
if (scriptInterruptedException != null)
351-
{
352-
throw ConvertScriptInterruptedExceptionToHostException(
353-
scriptInterruptedException);
354-
}
355-
}
356-
#if NET45
357-
358-
ExceptionDispatchInfo.Capture(innerException).Throw();
359-
#elif NET40
360-
361-
innerException.PreserveStackTrace();
362-
throw innerException;
363-
#else
364-
#error No implementation for this target
365-
#endif
366-
}
367-
368-
throw;
301+
throw ConvertScriptInterruptedExceptionToHostException(e);
369302
}
370303
}
371304

0 commit comments

Comments
 (0)