@@ -330,56 +330,6 @@ private void ThrowError()
330
330
}
331
331
}
332
332
333
- private void InvokeScript ( Action action )
334
- {
335
- _dispatcher . Invoke ( ( ) =>
336
- {
337
- try
338
- {
339
- action ( ) ;
340
- }
341
- catch ( ActiveScriptException e )
342
- {
343
- throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
344
- }
345
- catch ( TargetInvocationException e )
346
- {
347
- var activeScriptException = e . InnerException as ActiveScriptException ;
348
- if ( activeScriptException != null )
349
- {
350
- throw ConvertActiveScriptExceptionToJsRuntimeException ( activeScriptException ) ;
351
- }
352
-
353
- throw ;
354
- }
355
- } ) ;
356
- }
357
-
358
- private T InvokeScript < T > ( Func < T > func )
359
- {
360
- return _dispatcher . Invoke ( ( ) =>
361
- {
362
- try
363
- {
364
- return func ( ) ;
365
- }
366
- catch ( ActiveScriptException e )
367
- {
368
- throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
369
- }
370
- catch ( TargetInvocationException e )
371
- {
372
- var activeScriptException = e . InnerException as ActiveScriptException ;
373
- if ( activeScriptException != null )
374
- {
375
- throw ConvertActiveScriptExceptionToJsRuntimeException ( activeScriptException ) ;
376
- }
377
-
378
- throw ;
379
- }
380
- } ) ;
381
- }
382
-
383
333
/// <summary>
384
334
/// Executes a script text
385
335
/// </summary>
@@ -516,35 +466,33 @@ private void InnerSetVariableValue(string variableName, object value)
516
466
}
517
467
}
518
468
519
- private void EmbedHostItem ( string itemName , object value )
469
+ private void InnerEmbedHostItem ( string itemName , object value )
520
470
{
521
- InvokeScript ( ( ) =>
471
+ object oldValue = null ;
472
+ if ( _hostItems . ContainsKey ( itemName ) )
522
473
{
523
- object oldValue = null ;
524
- if ( _hostItems . ContainsKey ( itemName ) )
525
- {
526
- oldValue = _hostItems [ itemName ] ;
527
- }
528
- _hostItems [ itemName ] = value ;
474
+ oldValue = _hostItems [ itemName ] ;
475
+ }
476
+ _hostItems [ itemName ] = value ;
529
477
530
- try
478
+ try
479
+ {
480
+ _activeScriptWrapper . AddNamedItem ( itemName , ScriptItemFlags . IsVisible | ScriptItemFlags . GlobalMembers ) ;
481
+ }
482
+ catch
483
+ {
484
+ if ( oldValue != null )
531
485
{
532
- _activeScriptWrapper . AddNamedItem ( itemName , ScriptItemFlags . IsVisible | ScriptItemFlags . GlobalMembers ) ;
486
+ _hostItems [ itemName ] = oldValue ;
533
487
}
534
- catch ( Exception )
488
+ else
535
489
{
536
- if ( oldValue != null )
537
- {
538
- _hostItems [ itemName ] = oldValue ;
539
- }
540
- else
541
- {
542
- _hostItems . Remove ( itemName ) ;
543
- }
544
-
545
- throw ;
490
+ _hostItems . Remove ( itemName ) ;
546
491
}
547
- } ) ;
492
+
493
+ ThrowError ( ) ;
494
+ throw ;
495
+ }
548
496
}
549
497
550
498
/// <summary>
@@ -614,30 +562,52 @@ public override string Mode
614
562
615
563
public override object Evaluate ( string expression , string documentName )
616
564
{
617
- object result = InvokeScript ( ( ) => InnerExecute ( expression , documentName , true ) ) ;
565
+ object result = _dispatcher . Invoke ( ( ) =>
566
+ {
567
+ try
568
+ {
569
+ return InnerExecute ( expression , documentName , true ) ;
570
+ }
571
+ catch ( ActiveScriptException e )
572
+ {
573
+ throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
574
+ }
575
+ } ) ;
576
+
618
577
result = MapToHostType ( result ) ;
619
578
620
579
return result ;
621
580
}
622
581
623
582
public override void Execute ( string code , string documentName )
624
583
{
625
- InvokeScript ( ( ) =>
584
+ _dispatcher . Invoke ( ( ) =>
626
585
{
627
- InnerExecute ( code , documentName , false ) ;
586
+ try
587
+ {
588
+ InnerExecute ( code , documentName , false ) ;
589
+ }
590
+ catch ( ActiveScriptException e )
591
+ {
592
+ throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
593
+ }
628
594
} ) ;
629
595
}
630
596
631
597
public override object CallFunction ( string functionName , params object [ ] args )
632
598
{
633
599
object [ ] processedArgs = MapToScriptType ( args ) ;
634
600
635
- object result = InvokeScript ( ( ) =>
601
+ object result = _dispatcher . Invoke ( ( ) =>
636
602
{
637
603
try
638
604
{
639
605
return InnerCallFunction ( functionName , processedArgs ) ;
640
606
}
607
+ catch ( ActiveScriptException e )
608
+ {
609
+ throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
610
+ }
641
611
catch ( MissingMemberException )
642
612
{
643
613
throw new JsRuntimeException (
@@ -652,7 +622,7 @@ public override object CallFunction(string functionName, params object[] args)
652
622
653
623
public override bool HasVariable ( string variableName )
654
624
{
655
- bool result = InvokeScript ( ( ) =>
625
+ bool result = _dispatcher . Invoke ( ( ) =>
656
626
{
657
627
bool variableExist ;
658
628
@@ -661,6 +631,10 @@ public override bool HasVariable(string variableName)
661
631
object variableValue = InnerGetVariableValue ( variableName ) ;
662
632
variableExist = variableValue != null ;
663
633
}
634
+ catch ( ActiveScriptException e )
635
+ {
636
+ throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
637
+ }
664
638
catch ( MissingMemberException )
665
639
{
666
640
variableExist = false ;
@@ -674,12 +648,16 @@ public override bool HasVariable(string variableName)
674
648
675
649
public override object GetVariableValue ( string variableName )
676
650
{
677
- object result = InvokeScript ( ( ) =>
651
+ object result = _dispatcher . Invoke ( ( ) =>
678
652
{
679
653
try
680
654
{
681
655
return InnerGetVariableValue ( variableName ) ;
682
656
}
657
+ catch ( ActiveScriptException e )
658
+ {
659
+ throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
660
+ }
683
661
catch ( MissingMemberException )
684
662
{
685
663
throw new JsRuntimeException (
@@ -695,32 +673,72 @@ public override object GetVariableValue(string variableName)
695
673
public override void SetVariableValue ( string variableName , object value )
696
674
{
697
675
object processedValue = MapToScriptType ( value ) ;
698
- InvokeScript ( ( ) => InnerSetVariableValue ( variableName , processedValue ) ) ;
676
+
677
+ _dispatcher . Invoke ( ( ) =>
678
+ {
679
+ try
680
+ {
681
+ InnerSetVariableValue ( variableName , processedValue ) ;
682
+ }
683
+ catch ( ActiveScriptException e )
684
+ {
685
+ throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
686
+ }
687
+ } ) ;
699
688
}
700
689
701
690
public override void RemoveVariable ( string variableName )
702
691
{
703
- InvokeScript ( ( ) =>
692
+ _dispatcher . Invoke ( ( ) =>
704
693
{
705
- InnerSetVariableValue ( variableName , null ) ;
694
+ try
695
+ {
696
+ InnerSetVariableValue ( variableName , null ) ;
706
697
707
- if ( _hostItems . ContainsKey ( variableName ) )
698
+ if ( _hostItems . ContainsKey ( variableName ) )
699
+ {
700
+ _hostItems . Remove ( variableName ) ;
701
+ }
702
+ }
703
+ catch ( ActiveScriptException e )
708
704
{
709
- _hostItems . Remove ( variableName ) ;
705
+ throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
710
706
}
711
707
} ) ;
712
708
}
713
709
714
710
public override void EmbedHostObject ( string itemName , object value )
715
711
{
716
712
object processedValue = MapToScriptType ( value ) ;
717
- EmbedHostItem ( itemName , processedValue ) ;
713
+
714
+ _dispatcher . Invoke ( ( ) =>
715
+ {
716
+ try
717
+ {
718
+ InnerEmbedHostItem ( itemName , processedValue ) ;
719
+ }
720
+ catch ( ActiveScriptException e )
721
+ {
722
+ throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
723
+ }
724
+ } ) ;
718
725
}
719
726
720
727
public override void EmbedHostType ( string itemName , Type type )
721
728
{
722
729
var typeValue = new HostType ( type , _engineMode ) ;
723
- EmbedHostItem ( itemName , typeValue ) ;
730
+
731
+ _dispatcher . Invoke ( ( ) =>
732
+ {
733
+ try
734
+ {
735
+ InnerEmbedHostItem ( itemName , typeValue ) ;
736
+ }
737
+ catch ( ActiveScriptException e )
738
+ {
739
+ throw ConvertActiveScriptExceptionToJsRuntimeException ( e ) ;
740
+ }
741
+ } ) ;
724
742
}
725
743
726
744
public override void CollectGarbage ( )
0 commit comments