33using System . Text ;
44
55using Jint ;
6- using IOriginalCallable = Jint . Native . ICallable ;
76using OriginalEngine = Jint . Engine ;
87using OriginalJavaScriptException = Jint . Runtime . JavaScriptException ;
98using OriginalMemoryLimitExceededException = Jint . Runtime . MemoryLimitExceededException ;
@@ -101,10 +100,13 @@ public JintJsEngine(JintSettings settings)
101100 . Strict ( jintSettings . StrictMode )
102101 . TimeoutInterval ( jintSettings . TimeoutInterval )
103102 ;
103+
104104 if ( jintSettings . RegexTimeoutInterval . HasValue )
105105 {
106106 options . RegexTimeoutInterval ( jintSettings . RegexTimeoutInterval . Value ) ;
107107 }
108+
109+ options . AddObjectConverter ( new UndefinedConverter ( ) ) ;
108110 } ) ;
109111 }
110112 catch ( Exception e )
@@ -140,11 +142,6 @@ private static OriginalParserOptions CreateParserOptions(string documentName)
140142 /// <returns>The mapped value</returns>
141143 private OriginalValue MapToScriptType ( object value )
142144 {
143- if ( value is Undefined )
144- {
145- return OriginalValue . Undefined ;
146- }
147-
148145 return OriginalValue . FromObject ( _jsEngine , value ) ;
149146 }
150147
@@ -539,29 +536,11 @@ protected override object InnerCallFunction(string functionName, params object[]
539536 throw WrapJavaScriptException ( e ) ;
540537 }
541538
542- var callable = functionValue . TryCast < IOriginalCallable > ( ) ;
543- if ( callable == null )
544- {
545- throw new WrapperRuntimeException (
546- string . Format ( CoreStrings . Runtime_FunctionNotExist , functionName ) ) ;
547- }
548-
549- int argumentCount = args . Length ;
550- var processedArgs = new OriginalValue [ argumentCount ] ;
551-
552- if ( argumentCount > 0 )
553- {
554- for ( int argumentIndex = 0 ; argumentIndex < argumentCount ; argumentIndex ++ )
555- {
556- processedArgs [ argumentIndex ] = MapToScriptType ( args [ argumentIndex ] ) ;
557- }
558- }
559-
560539 OriginalValue resultValue ;
561540
562541 try
563542 {
564- resultValue = callable . Call ( functionValue , processedArgs ) ;
543+ resultValue = _jsEngine . Invoke ( functionValue , args ) ;
565544 }
566545 catch ( OriginalJavaScriptException e )
567546 {
@@ -583,6 +562,11 @@ protected override object InnerCallFunction(string functionName, params object[]
583562 {
584563 throw WrapTimeoutException ( e ) ;
585564 }
565+ catch ( ArgumentException e ) when ( e . Message == "Can only invoke functions" )
566+ {
567+ throw new WrapperRuntimeException (
568+ string . Format ( CoreStrings . Runtime_FunctionNotExist , functionName ) ) ;
569+ }
586570
587571 result = MapToHostType ( resultValue ) ;
588572 }
0 commit comments