diff --git a/cli/main.rs b/cli/main.rs index f4d4046df10cde..a26682ba971b80 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -204,6 +204,31 @@ pub fn create_main_worker( let create_web_worker_cb = create_web_worker_callback(ps.clone()); + let maybe_storage_origin = if let Some(location) = &ps.flags.location { + // if a location is set, then the ascii serialization of the location is + // used, unless the origin is opaque, and then no storage origin is set, as + // we can't expect the origin to be reproducible + let storage_origin = location.origin().ascii_serialization(); + if storage_origin == "null" { + None + } else { + Some(storage_origin) + } + } else if let Some(config_file) = &ps.maybe_config_file { + // otherwise we will use the path to the config file + config_file.path.to_str().map(|s| s.to_string()) + } else { + // otherwise we will use the path to the main module + Some(main_module.to_string()) + }; + + let origin_storage_dir = maybe_storage_origin.map(|so| { + ps.dir + .root + .join("location_data") + .join(checksum::gen(&[so.as_bytes()])) + }); + let options = WorkerOptions { bootstrap: BootstrapOptions { apply_source_maps: true, @@ -231,14 +256,7 @@ pub fn create_main_worker( should_break_on_first_statement, module_loader, get_error_class_fn: Some(&crate::errors::get_error_class_name), - origin_storage_dir: ps.flags.location.clone().map(|loc| { - ps.dir - .root - .clone() - // TODO(@crowlKats): change to origin_data for 2.0 - .join("location_data") - .join(checksum::gen(&[loc.to_string().as_bytes()])) - }), + origin_storage_dir, blob_store: ps.blob_store.clone(), broadcast_channel: ps.broadcast_channel.clone(), shared_array_buffer_store: Some(ps.shared_array_buffer_store.clone()), diff --git a/ext/webstorage/01_webstorage.js b/ext/webstorage/01_webstorage.js index 558522a3cee78d..e9274946b716e4 100644 --- a/ext/webstorage/01_webstorage.js +++ b/ext/webstorage/01_webstorage.js @@ -91,8 +91,6 @@ } function createStorage(persistent) { - if (persistent) window.location; - const storage = webidl.createBranded(Storage); storage[_persistent] = persistent; diff --git a/ext/webstorage/lib.rs b/ext/webstorage/lib.rs index e7e53d983d93b3..9894c265d39fab 100644 --- a/ext/webstorage/lib.rs +++ b/ext/webstorage/lib.rs @@ -38,8 +38,8 @@ pub fn init(origin_storage_dir: Option) -> Extension { ), ]) .state(move |state| { - if let Some(origin_storage_dir) = origin_storage_dir.clone() { - state.put(OriginStorageDir(origin_storage_dir)); + if let Some(origin_storage_dir) = &origin_storage_dir { + state.put(OriginStorageDir(origin_storage_dir.clone())); } Ok(()) })