|
1 | 1 | using System; |
2 | 2 | using System.Reflection; |
3 | | -#if NET45 |
4 | | -using System.Runtime.ExceptionServices; |
5 | | -#endif |
6 | 3 | using System.Text.RegularExpressions; |
7 | 4 |
|
8 | 5 | using Microsoft.ClearScript.V8; |
@@ -42,11 +39,6 @@ public sealed class V8JsEngine : JsEngineBase |
42 | 39 | /// </summary> |
43 | 40 | private static OriginalUndefined _originalUndefinedValue; |
44 | 41 |
|
45 | | - /// <summary> |
46 | | - /// Information about <code>InvokeMethod</code> method of <see cref="V8ScriptItem"/> class |
47 | | - /// </summary> |
48 | | - private static MethodInfo _v8ScriptItemInvokeMethodInfo; |
49 | | - |
50 | 42 | /// <summary> |
51 | 43 | /// Regular expression for working with the string representation of error |
52 | 44 | /// </summary> |
@@ -91,18 +83,17 @@ static V8JsEngine() |
91 | 83 | { |
92 | 84 | AssemblyResolver.Initialize(); |
93 | 85 | LoadUndefinedValue(); |
94 | | - LoadWinScriptItemInvokeMethodInfo(); |
95 | 86 | } |
96 | 87 |
|
97 | 88 | /// <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) |
99 | 90 | /// </summary> |
100 | 91 | public V8JsEngine() |
101 | 92 | : this(new V8Settings()) |
102 | 93 | { } |
103 | 94 |
|
104 | 95 | /// <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) |
106 | 97 | /// </summary> |
107 | 98 | /// <param name="settings">Settings of the V8 JS engine</param> |
108 | 99 | public V8JsEngine(V8Settings settings) |
@@ -166,36 +157,6 @@ private static void LoadUndefinedValue() |
166 | 157 | } |
167 | 158 | } |
168 | 159 |
|
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 | | - |
199 | 160 | /// <summary> |
200 | 161 | /// Executes a mapping from the host type to a ClearScript type |
201 | 162 | /// </summary> |
@@ -330,32 +291,11 @@ protected override object InnerCallFunction(string functionName, params object[] |
330 | 291 | { |
331 | 292 | try |
332 | 293 | { |
333 | | - object obj = _jsEngine.Script; |
334 | | - result = _v8ScriptItemInvokeMethodInfo.Invoke(obj, new object[] { functionName, processedArgs }); |
| 294 | + result = _jsEngine.Invoke(functionName, processedArgs); |
335 | 295 | } |
336 | | - catch (TargetInvocationException e) |
| 296 | + catch (OriginalJsException e) |
337 | 297 | { |
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); |
359 | 299 | } |
360 | 300 | } |
361 | 301 |
|
|
0 commit comments