mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-24 15:19:31 -05:00
Add Isolate::date_time_configuration_change_notification
(#1446)
* Add `Isolate::date_time_configuration_change_notification` * write some C --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
This commit is contained in:
parent
2ce9b4ca09
commit
57c2338212
4 changed files with 63 additions and 0 deletions
|
@ -359,6 +359,14 @@ size_t v8__Isolate__CreateParams__SIZEOF() {
|
|||
return sizeof(v8::Isolate::CreateParams);
|
||||
}
|
||||
|
||||
void v8__Isolate__DateTimeConfigurationChangeNotification(
|
||||
v8::Isolate* isolate,
|
||||
v8::Isolate::TimeZoneDetection time_zone_detection
|
||||
) {
|
||||
isolate->DateTimeConfigurationChangeNotification(time_zone_detection);
|
||||
}
|
||||
|
||||
|
||||
void v8__ResourceConstraints__ConfigureDefaultsFromHeapSize(
|
||||
v8::ResourceConstraints* constraints, size_t initial_heap_size_in_bytes,
|
||||
size_t maximum_heap_size_in_bytes) {
|
||||
|
|
|
@ -86,6 +86,24 @@ pub enum MemoryPressureLevel {
|
|||
Critical = 2,
|
||||
}
|
||||
|
||||
/// Time zone redetection indicator for
|
||||
/// DateTimeConfigurationChangeNotification.
|
||||
///
|
||||
/// kSkip indicates V8 that the notification should not trigger redetecting
|
||||
/// host time zone. kRedetect indicates V8 that host time zone should be
|
||||
/// redetected, and used to set the default time zone.
|
||||
///
|
||||
/// The host time zone detection may require file system access or similar
|
||||
/// operations unlikely to be available inside a sandbox. If v8 is run inside a
|
||||
/// sandbox, the host time zone has to be detected outside the sandbox before
|
||||
/// calling DateTimeConfigurationChangeNotification function.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(C)]
|
||||
pub enum TimeZoneDetection {
|
||||
Skip = 0,
|
||||
Redetect = 1,
|
||||
}
|
||||
|
||||
/// PromiseHook with type Init is called when a new promise is
|
||||
/// created. When a new promise is created as part of the chain in the
|
||||
/// case of Promise.then or in the intermediate promises created by
|
||||
|
@ -502,6 +520,10 @@ extern "C" {
|
|||
isolate: *mut Isolate,
|
||||
callback: extern "C" fn(*const FunctionCallbackInfo),
|
||||
);
|
||||
fn v8__Isolate__DateTimeConfigurationChangeNotification(
|
||||
isolate: *mut Isolate,
|
||||
time_zone_detection: TimeZoneDetection,
|
||||
);
|
||||
fn v8__Isolate__HasPendingBackgroundTasks(isolate: *const Isolate) -> bool;
|
||||
fn v8__Isolate__RequestGarbageCollectionForTesting(
|
||||
isolate: *mut Isolate,
|
||||
|
@ -1200,6 +1222,27 @@ impl Isolate {
|
|||
unsafe { v8__Isolate__SetWasmStreamingCallback(self, trampoline::<F>()) }
|
||||
}
|
||||
|
||||
/// Notification that the embedder has changed the time zone, daylight savings
|
||||
/// time or other date / time configuration parameters. V8 keeps a cache of
|
||||
/// various values used for date / time computation. This notification will
|
||||
/// reset those cached values for the current context so that date / time
|
||||
/// configuration changes would be reflected.
|
||||
///
|
||||
/// This API should not be called more than needed as it will negatively impact
|
||||
/// the performance of date operations.
|
||||
#[inline(always)]
|
||||
pub fn date_time_configuration_change_notification(
|
||||
&mut self,
|
||||
time_zone_detection: TimeZoneDetection,
|
||||
) {
|
||||
unsafe {
|
||||
v8__Isolate__DateTimeConfigurationChangeNotification(
|
||||
self,
|
||||
time_zone_detection,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if there is ongoing background work within V8 that will
|
||||
/// eventually post a foreground task, like asynchronous WebAssembly
|
||||
/// compilation.
|
||||
|
|
|
@ -116,6 +116,7 @@ pub use isolate::OwnedIsolate;
|
|||
pub use isolate::PromiseHook;
|
||||
pub use isolate::PromiseHookType;
|
||||
pub use isolate::PromiseRejectCallback;
|
||||
pub use isolate::TimeZoneDetection;
|
||||
pub use isolate::WasmAsyncSuccess;
|
||||
pub use isolate_create_params::CreateParams;
|
||||
pub use microtask::MicrotaskQueue;
|
||||
|
|
|
@ -4651,6 +4651,17 @@ fn allow_atomics_wait() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn date_time_configuration_change_notification() {
|
||||
let _setup_guard = setup::parallel_test();
|
||||
let isolate = &mut v8::Isolate::new(Default::default());
|
||||
isolate
|
||||
.date_time_configuration_change_notification(v8::TimeZoneDetection::Skip);
|
||||
isolate.date_time_configuration_change_notification(
|
||||
v8::TimeZoneDetection::Redetect,
|
||||
);
|
||||
}
|
||||
|
||||
fn mock_script_origin<'s>(
|
||||
scope: &mut v8::HandleScope<'s>,
|
||||
resource_name_: &str,
|
||||
|
|
Loading…
Reference in a new issue