Skip to content

Commit

Permalink
feat(ext/webstorage): use implied origin when --location not set
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Oct 26, 2021
1 parent d936a8f commit 1d56537
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
34 changes: 26 additions & 8 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()),
Expand Down
2 changes: 0 additions & 2 deletions ext/webstorage/01_webstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@
}

function createStorage(persistent) {
if (persistent) window.location;

const storage = webidl.createBranded(Storage);
storage[_persistent] = persistent;

Expand Down
4 changes: 2 additions & 2 deletions ext/webstorage/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub fn init(origin_storage_dir: Option<PathBuf>) -> 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(())
})
Expand Down

0 comments on commit 1d56537

Please sign in to comment.