Skip to content

Commit

Permalink
script: Ensure script is initialized before running script.
Browse files Browse the repository at this point in the history
Fixes #14154
  • Loading branch information
emilio committed Nov 12, 2016
1 parent d49840e commit a7cee44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 6 additions & 4 deletions components/script/lib.rs
Expand Up @@ -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();
Expand Down
9 changes: 7 additions & 2 deletions components/servo/lib.rs
Expand Up @@ -170,6 +170,10 @@ impl<Window> Browser<Window> 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.
Expand All @@ -183,7 +187,7 @@ impl<Window> Browser<Window> 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 {
Expand Down Expand Up @@ -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::<script_layout_interface::message::Msg,
layout_thread::LayoutThread,
Expand Down

0 comments on commit a7cee44

Please sign in to comment.