12
12
using OriginalException = MsieJavaScriptEngine . JsException ;
13
13
using OriginalFatalException = MsieJavaScriptEngine . JsFatalException ;
14
14
using OriginalInterruptedException = MsieJavaScriptEngine . JsInterruptedException ;
15
+ using OriginalPrecompiledScript = MsieJavaScriptEngine . PrecompiledScript ;
15
16
using OriginalRuntimeException = MsieJavaScriptEngine . JsRuntimeException ;
16
17
using OriginalScriptException = MsieJavaScriptEngine . JsScriptException ;
17
18
using OriginalTypeConverter = MsieJavaScriptEngine . Utilities . TypeConverter ;
@@ -215,12 +216,23 @@ private WrapperException WrapJsException(OriginalException originalException)
215
216
216
217
protected override IPrecompiledScript InnerPrecompile ( string code )
217
218
{
218
- throw new NotSupportedException ( ) ;
219
+ return InnerPrecompile ( code , null ) ;
219
220
}
220
221
221
222
protected override IPrecompiledScript InnerPrecompile ( string code , string documentName )
222
223
{
223
- throw new NotSupportedException ( ) ;
224
+ OriginalPrecompiledScript precompiledScript ;
225
+
226
+ try
227
+ {
228
+ precompiledScript = _jsEngine . Precompile ( code , documentName ) ;
229
+ }
230
+ catch ( OriginalException e )
231
+ {
232
+ throw WrapJsException ( e ) ;
233
+ }
234
+
235
+ return new MsiePrecompiledScript ( precompiledScript ) ;
224
236
}
225
237
226
238
protected override object InnerEvaluate ( string expression )
@@ -277,7 +289,24 @@ protected override void InnerExecute(string code, string documentName)
277
289
278
290
protected override void InnerExecute ( IPrecompiledScript precompiledScript )
279
291
{
280
- throw new NotSupportedException ( ) ;
292
+ var msiePrecompiledScript = precompiledScript as MsiePrecompiledScript ;
293
+ if ( msiePrecompiledScript == null )
294
+ {
295
+ throw new WrapperUsageException (
296
+ string . Format ( CoreStrings . Usage_CannotConvertPrecompiledScriptToInternalType ,
297
+ typeof ( MsiePrecompiledScript ) . FullName ) ,
298
+ Name , Version
299
+ ) ;
300
+ }
301
+
302
+ try
303
+ {
304
+ _jsEngine . Execute ( msiePrecompiledScript . PrecompiledScript ) ;
305
+ }
306
+ catch ( OriginalException e )
307
+ {
308
+ throw WrapJsException ( e ) ;
309
+ }
281
310
}
282
311
283
312
protected override object InnerCallFunction ( string functionName , params object [ ] args )
@@ -441,7 +470,7 @@ public override string Version
441
470
/// </summary>
442
471
public override bool SupportsScriptPrecompilation
443
472
{
444
- get { return false ; }
473
+ get { return _jsEngine . SupportsScriptPrecompilation ; }
445
474
}
446
475
447
476
/// <summary>
@@ -461,6 +490,160 @@ public override bool SupportsGarbageCollection
461
490
}
462
491
463
492
493
+ public override IPrecompiledScript PrecompileFile ( string path , Encoding encoding = null )
494
+ {
495
+ VerifyNotDisposed ( ) ;
496
+
497
+ if ( path == null )
498
+ {
499
+ throw new ArgumentNullException (
500
+ nameof ( path ) ,
501
+ string . Format ( CoreStrings . Common_ArgumentIsNull , nameof ( path ) )
502
+ ) ;
503
+ }
504
+
505
+ if ( string . IsNullOrWhiteSpace ( path ) )
506
+ {
507
+ throw new ArgumentException (
508
+ string . Format ( CoreStrings . Common_ArgumentIsEmpty , nameof ( path ) ) ,
509
+ nameof ( path )
510
+ ) ;
511
+ }
512
+
513
+ if ( ! ValidationHelpers . CheckDocumentNameFormat ( path ) )
514
+ {
515
+ throw new ArgumentException (
516
+ string . Format ( CoreStrings . Usage_InvalidFileNameFormat , path ) ,
517
+ nameof ( path )
518
+ ) ;
519
+ }
520
+
521
+ OriginalPrecompiledScript precompiledScript ;
522
+
523
+ try
524
+ {
525
+ precompiledScript = _jsEngine . PrecompileFile ( path , encoding ) ;
526
+ }
527
+ catch ( OriginalException e )
528
+ {
529
+ throw WrapJsException ( e ) ;
530
+ }
531
+ catch ( FileNotFoundException )
532
+ {
533
+ throw ;
534
+ }
535
+
536
+ return new MsiePrecompiledScript ( precompiledScript ) ;
537
+ }
538
+
539
+ public override IPrecompiledScript PrecompileResource ( string resourceName , Type type )
540
+ {
541
+ VerifyNotDisposed ( ) ;
542
+
543
+ if ( resourceName == null )
544
+ {
545
+ throw new ArgumentNullException (
546
+ nameof ( resourceName ) ,
547
+ string . Format ( CoreStrings . Common_ArgumentIsNull , nameof ( resourceName ) )
548
+ ) ;
549
+ }
550
+
551
+ if ( type == null )
552
+ {
553
+ throw new ArgumentNullException (
554
+ nameof ( type ) ,
555
+ string . Format ( CoreStrings . Common_ArgumentIsNull , nameof ( type ) )
556
+ ) ;
557
+ }
558
+
559
+ if ( string . IsNullOrWhiteSpace ( resourceName ) )
560
+ {
561
+ throw new ArgumentException (
562
+ string . Format ( CoreStrings . Common_ArgumentIsEmpty , nameof ( resourceName ) ) ,
563
+ nameof ( resourceName )
564
+ ) ;
565
+ }
566
+
567
+ if ( ! ValidationHelpers . CheckDocumentNameFormat ( resourceName ) )
568
+ {
569
+ throw new ArgumentException (
570
+ string . Format ( CoreStrings . Usage_InvalidResourceNameFormat , resourceName ) ,
571
+ nameof ( resourceName )
572
+ ) ;
573
+ }
574
+
575
+ OriginalPrecompiledScript precompiledScript ;
576
+
577
+ try
578
+ {
579
+ precompiledScript = _jsEngine . PrecompileResource ( resourceName , type ) ;
580
+ }
581
+ catch ( OriginalException e )
582
+ {
583
+ throw WrapJsException ( e ) ;
584
+ }
585
+ catch ( NullReferenceException )
586
+ {
587
+ throw ;
588
+ }
589
+
590
+ return new MsiePrecompiledScript ( precompiledScript ) ;
591
+ }
592
+
593
+ public override IPrecompiledScript PrecompileResource ( string resourceName , Assembly assembly )
594
+ {
595
+ VerifyNotDisposed ( ) ;
596
+
597
+ if ( resourceName == null )
598
+ {
599
+ throw new ArgumentNullException (
600
+ nameof ( resourceName ) ,
601
+ string . Format ( CoreStrings . Common_ArgumentIsNull , nameof ( resourceName ) )
602
+ ) ;
603
+ }
604
+
605
+ if ( assembly == null )
606
+ {
607
+ throw new ArgumentNullException (
608
+ nameof ( assembly ) ,
609
+ string . Format ( CoreStrings . Common_ArgumentIsNull , nameof ( assembly ) )
610
+ ) ;
611
+ }
612
+
613
+ if ( string . IsNullOrWhiteSpace ( resourceName ) )
614
+ {
615
+ throw new ArgumentException (
616
+ string . Format ( CoreStrings . Common_ArgumentIsEmpty , nameof ( resourceName ) ) ,
617
+ nameof ( resourceName )
618
+ ) ;
619
+ }
620
+
621
+ if ( ! ValidationHelpers . CheckDocumentNameFormat ( resourceName ) )
622
+ {
623
+ throw new ArgumentException (
624
+ string . Format ( CoreStrings . Usage_InvalidResourceNameFormat , resourceName ) ,
625
+ nameof ( resourceName )
626
+ ) ;
627
+ }
628
+
629
+ OriginalPrecompiledScript precompiledScript ;
630
+
631
+ try
632
+ {
633
+ precompiledScript = _jsEngine . PrecompileResource ( resourceName , assembly ) ;
634
+ }
635
+ catch ( OriginalException e )
636
+ {
637
+ throw WrapJsException ( e ) ;
638
+ }
639
+ catch ( NullReferenceException )
640
+ {
641
+ throw ;
642
+ }
643
+
644
+ return new MsiePrecompiledScript ( precompiledScript ) ;
645
+ }
646
+
464
647
public override void ExecuteFile ( string path , Encoding encoding = null )
465
648
{
466
649
VerifyNotDisposed ( ) ;
0 commit comments