aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/blob.rs
diff options
context:
space:
mode:
authorGregory Terzian <gterzian@users.noreply.github.com>2020-02-29 11:59:10 +0800
committerGregory Terzian <gterzian@users.noreply.github.com>2020-06-04 11:38:35 +0800
commitbd5796c90b8e8e066a32e7da9cfa5251d1559046 (patch)
treeaa5ed3de6608b8046924ef6e8e8ad43b91cf81a7 /components/script/dom/blob.rs
parent0281acea955085aec01a4fc6da5f89f326a14842 (diff)
downloadservo-bd5796c90b8e8e066a32e7da9cfa5251d1559046.tar.gz
servo-bd5796c90b8e8e066a32e7da9cfa5251d1559046.zip
integrate readablestream with fetch and blob
Diffstat (limited to 'components/script/dom/blob.rs')
-rw-r--r--components/script/dom/blob.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs
index 46203a031b5..44011df9494 100644
--- a/components/script/dom/blob.rs
+++ b/components/script/dom/blob.rs
@@ -14,14 +14,18 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::structuredclone::StructuredDataHolder;
use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
+use crate::dom::readablestream::ReadableStream;
use crate::realms::{AlreadyInRealm, InRealm};
+use crate::script_runtime::JSContext;
use dom_struct::dom_struct;
use encoding_rs::UTF_8;
+use js::jsapi::JSObject;
use msg::constellation_msg::{BlobId, BlobIndex, PipelineNamespaceId};
use net_traits::filemanager_thread::RelativePos;
use script_traits::serializable::BlobImpl;
use std::collections::HashMap;
use std::num::NonZeroU32;
+use std::ptr::NonNull;
use std::rc::Rc;
use uuid::Uuid;
@@ -34,13 +38,7 @@ pub struct Blob {
impl Blob {
pub fn new(global: &GlobalScope, blob_impl: BlobImpl) -> DomRoot<Blob> {
- let dom_blob = reflect_dom_object(
- Box::new(Blob {
- reflector_: Reflector::new(),
- blob_id: blob_impl.blob_id(),
- }),
- global,
- );
+ let dom_blob = reflect_dom_object(Box::new(Blob::new_inherited(&blob_impl)), global);
global.track_blob(&dom_blob, blob_impl);
dom_blob
}
@@ -89,6 +87,11 @@ impl Blob {
pub fn get_blob_url_id(&self) -> Uuid {
self.global().get_blob_url_id(&self.blob_id)
}
+
+ /// <https://w3c.github.io/FileAPI/#blob-get-stream>
+ pub fn get_stream(&self) -> DomRoot<ReadableStream> {
+ self.global().get_blob_stream(&self.blob_id)
+ }
}
impl Serializable for Blob {
@@ -213,6 +216,11 @@ impl BlobMethods for Blob {
DOMString::from(self.type_string())
}
+ // <https://w3c.github.io/FileAPI/#blob-get-stream>
+ fn Stream(&self, _cx: JSContext) -> NonNull<JSObject> {
+ self.get_stream().get_js_stream()
+ }
+
// https://w3c.github.io/FileAPI/#slice-method-algo
fn Slice(
&self,