From a7cee44f59237c877cd8132cf8634b25d7ea6c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 12 Nov 2016 02:27:51 +0100 Subject: [PATCH] script: Ensure script is initialized before running script. Fixes #14154 --- components/script/lib.rs | 10 ++++++---- components/servo/lib.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/components/script/lib.rs b/components/script/lib.rs index 94e9683ffaf7..91ccc817cf81 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -163,15 +163,17 @@ fn perform_platform_specific_initialization() { #[cfg(not(target_os = "linux"))] fn perform_platform_specific_initialization() {} +pub fn init_service_workers(sw_senders: SWManagerSenders) { + // Spawn the service worker manager passing the constellation sender + ServiceWorkerManager::spawn_manager(sw_senders); +} + #[allow(unsafe_code)] -pub fn init(sw_senders: SWManagerSenders) { +pub fn init() { unsafe { proxyhandler::init(); } - // Spawn the service worker manager passing the constellation sender - ServiceWorkerManager::spawn_manager(sw_senders); - // Create the global vtables used by the (generated) DOM // bindings to implement JS proxies. RegisterBindings::RegisterProxyHandlers(); diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 909daec3002c..83de1b52db1e 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -170,6 +170,10 @@ impl Browser where Window: WindowMethods + 'static { }) }; + // Important that this call is done in a single-threaded fashion, we + // can't defer it after `create_constellation` has started. + script::init(); + // Create the constellation, which maintains the engine // pipelines, including the script and layout threads, as well // as the navigation context. @@ -183,7 +187,7 @@ impl Browser where Window: WindowMethods + 'static { webrender_api_sender.clone()); // Send the constellation's swmanager sender to service worker manager thread - script::init(sw_senders); + script::init_service_workers(sw_senders); if cfg!(feature = "webdriver") { if let Some(port) = opts.webdriver_port { @@ -339,7 +343,8 @@ pub fn run_content_process(token: String) { // send the required channels to the service worker manager let sw_senders = unprivileged_content.swmanager_senders(); - script::init(sw_senders); + script::init(); + script::init_service_workers(sw_senders); unprivileged_content.start_all::