Skip to content
Permalink
Browse files

re-structure blob, structured serialization

  • Loading branch information
gterzian committed Aug 31, 2019
1 parent 7aa68c8 commit 6e8a85482c2068d4dbccb992954271f725570f91
Showing with 988 additions and 480 deletions.
  1. +1 −0 Cargo.lock
  2. +38 −0 components/msg/constellation_msg.rs
  3. +1 −1 components/net_traits/filemanager_thread.rs
  4. +6 −2 components/script/body.rs
  5. +1 −1 components/script/dom/abstractworkerglobalscope.rs
  6. +8 −0 components/script/dom/bindings/codegen/Bindings.conf
  7. +1 −0 components/script/dom/bindings/mod.rs
  8. +32 −0 components/script/dom/bindings/serializable.rs
  9. +84 −117 components/script/dom/bindings/structuredclone.rs
  10. +5 −1 components/script/dom/bindings/trace.rs
  11. +102 −276 components/script/dom/blob.rs
  12. +1 −1 components/script/dom/dedicatedworkerglobalscope.rs
  13. +3 −0 components/script/dom/document.rs
  14. +17 −17 components/script/dom/file.rs
  15. +3 −3 components/script/dom/formdata.rs
  16. +445 −3 components/script/dom/globalscope.rs
  17. +1 −0 components/script/dom/history.rs
  18. +1 −1 components/script/dom/messageport.rs
  19. +7 −11 components/script/dom/testbinding.rs
  20. +3 −2 components/script/dom/websocket.rs
  21. +4 −3 components/script/dom/xmlhttprequest.rs
  22. +1 −1 components/script/script_thread.rs
  23. +1 −0 components/script_traits/Cargo.toml
  24. +7 −1 components/script_traits/lib.rs
  25. +148 −0 components/script_traits/serializable.rs
  26. +3 −0 tests/wpt/metadata/FileAPI/url/url-in-tags-revoke.window.js.ini
  27. +3 −0 tests/wpt/metadata/FileAPI/url/url-with-fetch.any.js.ini
  28. +14 −4 tests/wpt/metadata/MANIFEST.json
  29. +0 −35 ...web-platform-tests/html/infrastructure/safe-passing-of-structured-data/structured_clone_blob.html
  30. +22 −0 ...latform-tests/html/infrastructure/safe-passing-of-structured-data/structured_clone_blob.window.js
  31. +25 −0 ...m-tests/html/infrastructure/safe-passing-of-structured-data/structured_clone_blob_array.window.js

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;
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 {
/// <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<(), ()>;
}

0 comments on commit 6e8a854

Please sign in to comment.
You can’t perform that action at this time.