@@ -554,6 +554,22 @@ pub struct OomDetails {
554
554
pub type OomErrorCallback =
555
555
unsafe extern "C" fn ( location : * const char , details : & OomDetails ) ;
556
556
557
+ #[ repr( C ) ]
558
+ pub struct ModifyCodeGenerationFromStringsResult < ' s > {
559
+ pub codegen_allowed : bool ,
560
+ pub modified_source : Option < Local < ' s , String > > ,
561
+ }
562
+
563
+ // We use Option<NonNull<T>> which _is_ FFI-safe.
564
+ // See https://doc.rust-lang.org/nomicon/other-reprs.html
565
+ #[ allow( improper_ctypes_definitions) ]
566
+ pub type ModifyCodeGenerationFromStringsCallback < ' s > =
567
+ extern "C" fn (
568
+ context : Local < ' s , Context > ,
569
+ source : Local < ' s , Value > ,
570
+ is_code_like : bool ,
571
+ ) -> ModifyCodeGenerationFromStringsResult < ' s > ;
572
+
557
573
// Windows x64 ABI: MaybeLocal<Value> returned on the stack.
558
574
#[ cfg( target_os = "windows" ) ]
559
575
pub type PrepareStackTraceCallback < ' s > =
@@ -713,6 +729,13 @@ unsafe extern "C" {
713
729
isolate : * mut Isolate ,
714
730
callback : UseCounterCallback ,
715
731
) ;
732
+ // We use Option<NonNull<T>> which _is_ FFI-safe.
733
+ // See https://doc.rust-lang.org/nomicon/other-reprs.html
734
+ #[ allow( improper_ctypes) ]
735
+ fn v8__Isolate__SetModifyCodeGenerationFromStringsCallback (
736
+ isolate : * mut Isolate ,
737
+ callback : ModifyCodeGenerationFromStringsCallback ,
738
+ ) ;
716
739
fn v8__Isolate__RequestInterrupt (
717
740
isolate : * const Isolate ,
718
741
callback : InterruptCallback ,
@@ -1405,6 +1428,20 @@ impl Isolate {
1405
1428
unsafe { v8__Isolate__RemoveGCEpilogueCallback ( self , callback, data) }
1406
1429
}
1407
1430
1431
+ /// This specifies the callback called by v8 when JS is trying to dynamically execute
1432
+ /// code using `eval` or the `Function` constructor.
1433
+ ///
1434
+ /// The callback can decide whether to allow code generation and, if so, modify
1435
+ /// the source code beforehand.
1436
+ pub fn set_modify_code_generation_from_strings_callback (
1437
+ & mut self ,
1438
+ callback : ModifyCodeGenerationFromStringsCallback ,
1439
+ ) {
1440
+ unsafe {
1441
+ v8__Isolate__SetModifyCodeGenerationFromStringsCallback ( self , callback)
1442
+ }
1443
+ }
1444
+
1408
1445
/// Add a callback to invoke in case the heap size is close to the heap limit.
1409
1446
/// If multiple callbacks are added, only the most recently added callback is
1410
1447
/// invoked.
0 commit comments