From 8513c8fa69171a6721cb3474080af58e1b56aae2 Mon Sep 17 00:00:00 2001 From: Moritz Gunz Date: Mon, 7 Sep 2020 12:00:35 +0100 Subject: [PATCH] Add bindings to 'v8::Isolate::LowMemoryNotification()' (#459) --- src/binding.cc | 4 ++++ src/isolate.rs | 7 +++++++ tests/test_api.rs | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/src/binding.cc b/src/binding.cc index 4011b067..355793c7 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -119,6 +119,10 @@ void v8__Isolate__Enter(v8::Isolate* isolate) { isolate->Enter(); } void v8__Isolate__Exit(v8::Isolate* isolate) { isolate->Exit(); } +void v8__Isolate__LowMemoryNotification(v8::Isolate* isolate) { + isolate->LowMemoryNotification(); +} + void v8__Isolate__GetHeapStatistics(v8::Isolate* isolate, v8::HeapStatistics* s) { isolate->GetHeapStatistics(s); diff --git a/src/isolate.rs b/src/isolate.rs index 4a4626c8..f6753b29 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -105,6 +105,7 @@ extern "C" { fn v8__Isolate__GetNumberOfDataSlots(this: *const Isolate) -> u32; fn v8__Isolate__Enter(this: *mut Isolate); fn v8__Isolate__Exit(this: *mut Isolate); + fn v8__Isolate__LowMemoryNotification(isolate: *mut Isolate); fn v8__Isolate__GetHeapStatistics(this: *mut Isolate, s: *mut HeapStatistics); fn v8__Isolate__SetCaptureStackTraceForUncaughtExceptions( this: *mut Isolate, @@ -366,6 +367,12 @@ impl Isolate { unsafe { v8__Isolate__Exit(self) } } + /// Optional notification that the system is running low on memory. + /// V8 uses these notifications to attempt to free memory. + pub fn low_memory_notification(&mut self) { + unsafe { v8__Isolate__LowMemoryNotification(self) } + } + /// Get statistics about the heap memory usage. pub fn get_heap_statistics(&mut self, s: &mut HeapStatistics) { unsafe { v8__Isolate__GetHeapStatistics(self, s) } diff --git a/tests/test_api.rs b/tests/test_api.rs index ea97d898..46a258d2 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -3414,6 +3414,12 @@ fn heap_statistics() { assert_ne!(s.number_of_native_contexts(), 0); } +#[test] +fn low_memory_notification() { + let mut isolate = v8::Isolate::new(Default::default()); + isolate.low_memory_notification(); +} + fn synthetic_evaluation_steps<'a>( context: v8::Local<'a, v8::Context>, module: v8::Local,