3
3
using System . Text ;
4
4
5
5
using Jint ;
6
- using IOriginalCallable = Jint . Native . ICallable ;
7
6
using OriginalEngine = Jint . Engine ;
8
7
using OriginalJavaScriptException = Jint . Runtime . JavaScriptException ;
9
8
using OriginalMemoryLimitExceededException = Jint . Runtime . MemoryLimitExceededException ;
@@ -101,10 +100,13 @@ public JintJsEngine(JintSettings settings)
101
100
. Strict ( jintSettings . StrictMode )
102
101
. TimeoutInterval ( jintSettings . TimeoutInterval )
103
102
;
103
+
104
104
if ( jintSettings . RegexTimeoutInterval . HasValue )
105
105
{
106
106
options . RegexTimeoutInterval ( jintSettings . RegexTimeoutInterval . Value ) ;
107
107
}
108
+
109
+ options . AddObjectConverter ( new UndefinedConverter ( ) ) ;
108
110
} ) ;
109
111
}
110
112
catch ( Exception e )
@@ -140,11 +142,6 @@ private static OriginalParserOptions CreateParserOptions(string documentName)
140
142
/// <returns>The mapped value</returns>
141
143
private OriginalValue MapToScriptType ( object value )
142
144
{
143
- if ( value is Undefined )
144
- {
145
- return OriginalValue . Undefined ;
146
- }
147
-
148
145
return OriginalValue . FromObject ( _jsEngine , value ) ;
149
146
}
150
147
@@ -539,29 +536,11 @@ protected override object InnerCallFunction(string functionName, params object[]
539
536
throw WrapJavaScriptException ( e ) ;
540
537
}
541
538
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
-
560
539
OriginalValue resultValue ;
561
540
562
541
try
563
542
{
564
- resultValue = callable . Call ( functionValue , processedArgs ) ;
543
+ resultValue = _jsEngine . Invoke ( functionValue , args ) ;
565
544
}
566
545
catch ( OriginalJavaScriptException e )
567
546
{
@@ -583,6 +562,11 @@ protected override object InnerCallFunction(string functionName, params object[]
583
562
{
584
563
throw WrapTimeoutException ( e ) ;
585
564
}
565
+ catch ( ArgumentException e ) when ( e . Message == "Can only invoke functions" )
566
+ {
567
+ throw new WrapperRuntimeException (
568
+ string . Format ( CoreStrings . Runtime_FunctionNotExist , functionName ) ) ;
569
+ }
586
570
587
571
result = MapToHostType ( resultValue ) ;
588
572
}
0 commit comments