11using System ;
22using System . Reflection ;
3- #if NET45
4- using System . Runtime . ExceptionServices ;
5- #endif
63using System . Text . RegularExpressions ;
74
85using 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