Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure Blob, structured serialization #24123

Merged
merged 1 commit into from Dec 19, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

re-structure blob, structured serialization

  • Loading branch information
gterzian committed Dec 11, 2019
commit 6e8a85482c2068d4dbccb992954271f725570f91

Some generated files are not rendered by default. Learn more.

@@ -170,6 +170,13 @@ impl PipelineNamespace {
index: MessagePortRouterIndex(self.next_index()),
}
}

fn next_blob_id(&mut self) -> BlobId {
BlobId {
namespace_id: self.id,
index: BlobIndex(self.next_index()),
}
}
}

thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = Cell::new(None));
@@ -373,6 +380,37 @@ impl fmt::Display for MessagePortRouterId {
}
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct BlobIndex(pub NonZeroU32);
malloc_size_of_is_0!(BlobIndex);

#[derive(
Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct BlobId {
pub namespace_id: PipelineNamespaceId,
pub index: BlobIndex,
}

impl BlobId {
pub fn new() -> BlobId {
PIPELINE_NAMESPACE.with(|tls| {
let mut namespace = tls.get().expect("No namespace set for this thread!");
let next_blob_id = namespace.next_blob_id();
tls.set(Some(namespace));
next_blob_id
})
}
}

impl fmt::Display for BlobId {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let PipelineNamespaceId(namespace_id) = self.namespace_id;
let BlobIndex(index) = self.index;
write!(fmt, "({},{})", namespace_id, index.get())
}
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct HistoryStateIndex(pub NonZeroU32);
malloc_size_of_is_0!(HistoryStateIndex);
@@ -19,7 +19,7 @@ pub type FileOrigin = String;
/// Relative slice positions of a sequence,
/// whose semantic should be consistent with (start, end) parameters in
/// <https://w3c.github.io/FileAPI/#dfn-slice>
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct RelativePos {
/// Relative to first byte if non-negative,
/// relative to one past last byte if negative,
@@ -9,7 +9,7 @@ use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::USVString;
use crate::dom::bindings::trace::RootedTraceableBox;
use crate::dom::blob::{Blob, BlobImpl};
use crate::dom::blob::{normalize_type_string, Blob};
use crate::dom::formdata::FormData;
use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
@@ -24,6 +24,7 @@ use js::rust::wrappers::JS_GetPendingException;
use js::rust::wrappers::JS_ParseJSON;
use js::typedarray::{ArrayBuffer, CreateWith};
use mime::{self, Mime};
use script_traits::serializable::BlobImpl;
use std::cell::Ref;
use std::ptr;
use std::rc::Rc;
@@ -166,7 +167,10 @@ fn run_blob_data_algorithm(
} else {
"".to_string()
};
let blob = Blob::new(root, BlobImpl::new_from_bytes(bytes), mime_string);
let blob = Blob::new(
root,
BlobImpl::new_from_bytes(bytes, normalize_type_string(&mime_string)),
);
Ok(FetchedData::BlobData(blob))
}

@@ -148,5 +148,5 @@ pub fn run_worker_event_loop<T, WorkerMsg, Event>(
}
worker_scope
.upcast::<GlobalScope>()
.perform_a_message_port_garbage_collection_checkpoint();
.perform_a_dom_garbage_collection_checkpoint();
}
@@ -14,6 +14,14 @@

DOMInterfaces = {

'Blob': {
'weakReferenceable': True,
},

'File': {
'weakReferenceable': True,
},

'MediaQueryList': {
'weakReferenceable': True,
},
@@ -150,6 +150,7 @@ pub mod record;
pub mod refcounted;
pub mod reflector;
pub mod root;
pub mod serializable;
pub mod settings_stack;
pub mod str;
pub mod structuredclone;
@@ -0,0 +1,32 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! Trait representing the concept of [serializable objects]
//! (https://html.spec.whatwg.org/multipage/#serializable-objects).

use crate::dom::bindings::reflector::DomObject;
This conversation was marked as resolved by jdm

This comment has been minimized.

Copy link
@jdm

jdm Nov 13, 2019

Member

nit: add a newline after the doc comment.

use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::structuredclone::StructuredDataHolder;
use crate::dom::globalscope::GlobalScope;

/// The key corresponding to the storage location
/// of a serialized platform object stored in a StructuredDataHolder.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct StorageKey {
pub index: u32,
pub name_space: u32,
}

/// Interface for serializable platform objects.
/// <https://html.spec.whatwg.org/multipage/#serializable>
pub trait Serializable: DomObject {
This conversation was marked as resolved by jdm

This comment has been minimized.

Copy link
@jdm

jdm Nov 13, 2019

Member

Add:

/// Interface for serializable platform objects.
/// <https://html.spec.whatwg.org/multipage/#serializable>
/// <https://html.spec.whatwg.org/multipage/#serialization-steps>
fn serialize(&self, sc_holder: &mut StructuredDataHolder) -> Result<StorageKey, ()>;
/// <https://html.spec.whatwg.org/multipage/#deserialization-steps>
fn deserialize(
owner: &DomRoot<GlobalScope>,
sc_holder: &mut StructuredDataHolder,
extra_data: StorageKey,
) -> Result<(), ()>;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.