servo: Merge #15767 - Remove support for Blob::{close, isClosed} (from charlesvdv:blob-close); r=nox
authorCharles Vandevoorde <charles.vandevoorde@hotmail.be>
Fri, 03 Mar 2017 02:16:51 -0800
changeset 374867 29c16c3ec59b309787730d3059b1df86e0bb3b6b
parent 374866 ed6fe97d40718fcaef9ca36bd207e4e7be46ae32
child 374868 d67caca960aa9f4b1b59d0d79d4ecfb83eb18e68
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnox
bugs15767, 15660
milestone54.0a1
servo: Merge #15767 - Remove support for Blob::{close, isClosed} (from charlesvdv:blob-close); r=nox <!-- Please describe your changes on the following line: --> <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15660 <!-- Either: --> - [x] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 1b1fadb8b88eefe878617230a7b78c75a164332d
servo/components/script/dom/blob.rs
servo/components/script/dom/filereader.rs
servo/components/script/dom/url.rs
servo/components/script/dom/webidls/Blob.webidl
--- a/servo/components/script/dom/blob.rs
+++ b/servo/components/script/dom/blob.rs
@@ -13,17 +13,16 @@ use dom::bindings::str::DOMString;
 use dom::globalscope::GlobalScope;
 use dom_struct::dom_struct;
 use encoding::all::UTF_8;
 use encoding::types::{EncoderTrap, Encoding};
 use ipc_channel::ipc;
 use net_traits::{CoreResourceMsg, IpcSend};
 use net_traits::blob_url_store::{BlobBuf, get_blob_origin};
 use net_traits::filemanager_thread::{FileManagerThreadMsg, ReadFileProgress, RelativePos};
-use std::cell::Cell;
 use std::mem;
 use std::ops::Index;
 use std::path::PathBuf;
 use uuid::Uuid;
 
 /// File-based blob
 #[derive(JSTraceable)]
 pub struct FileBlob {
@@ -70,17 +69,16 @@ impl BlobImpl {
 // https://w3c.github.io/FileAPI/#blob
 #[dom_struct]
 pub struct Blob {
     reflector_: Reflector,
     #[ignore_heap_size_of = "No clear owner"]
     blob_impl: DOMRefCell<BlobImpl>,
     /// content-type string
     type_string: String,
-    is_closed: Cell<bool>,
 }
 
 impl Blob {
     #[allow(unrooted_must_root)]
     pub fn new(
             global: &GlobalScope, blob_impl: BlobImpl, typeString: String)
             -> Root<Blob> {
         let boxed_blob = box Blob::new_inherited(blob_impl, typeString);
@@ -90,17 +88,16 @@ impl Blob {
     #[allow(unrooted_must_root)]
     pub fn new_inherited(blob_impl: BlobImpl, type_string: String) -> Blob {
         Blob {
             reflector_: Reflector::new(),
             blob_impl: DOMRefCell::new(blob_impl),
             // NOTE: Guarding the format correctness here,
             // https://w3c.github.io/FileAPI/#dfn-type
             type_string: normalize_type_string(&type_string),
-            is_closed: Cell::new(false),
         }
     }
 
     #[allow(unrooted_must_root)]
     fn new_sliced(parent: &Blob, rel_pos: RelativePos,
                   relative_content_type: DOMString) -> Root<Blob> {
         let blob_impl = match *parent.blob_impl.borrow() {
             BlobImpl::File(_) => {
@@ -292,19 +289,17 @@ impl Blob {
         let global = self.global();
         let resource_threads = global.resource_threads();
         let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
     }
 }
 
 impl Drop for Blob {
     fn drop(&mut self) {
-        if !self.IsClosed() {
-            self.clean_up_file_resource();
-        }
+        self.clean_up_file_resource();
     }
 }
 
 fn read_file(global: &GlobalScope, id: Uuid) -> Result<Vec<u8>, ()> {
     let resource_threads = global.resource_threads();
     let (chan, recv) = ipc::channel().map_err(|_|())?;
     let origin = get_blob_origin(&global.get_url());
     let check_url_validity = false;
@@ -370,35 +365,16 @@ impl BlobMethods for Blob {
     fn Slice(&self,
              start: Option<i64>,
              end: Option<i64>,
              content_type: Option<DOMString>)
              -> Root<Blob> {
         let rel_pos = RelativePos::from_opts(start, end);
         Blob::new_sliced(self, rel_pos, content_type.unwrap_or(DOMString::from("")))
     }
-
-    // https://w3c.github.io/FileAPI/#dfn-isClosed
-    fn IsClosed(&self) -> bool {
-        self.is_closed.get()
-    }
-
-    // https://w3c.github.io/FileAPI/#dfn-close
-    fn Close(&self) {
-        // Step 1
-        if self.is_closed.get() {
-            return;
-        }
-
-        // Step 2
-        self.is_closed.set(true);
-
-        // Step 3
-        self.clean_up_file_resource();
-    }
 }
 
 /// Get the normalized, MIME-parsable type string
 /// https://w3c.github.io/FileAPI/#dfn-type
 /// XXX: We will relax the restriction here,
 /// since the spec has some problem over this part.
 /// see https://github.com/w3c/FileAPI/issues/43
 fn normalize_type_string(s: &str) -> String {
--- a/servo/components/script/dom/filereader.rs
+++ b/servo/components/script/dom/filereader.rs
@@ -370,30 +370,21 @@ impl FileReader {
         self.generation_id.set(GenerationId(prev_id + 1));
     }
 
     fn read(&self, function: FileReaderFunction, blob: &Blob, label: Option<DOMString>) -> ErrorResult {
         // Step 1
         if self.ready_state.get() == FileReaderReadyState::Loading {
             return Err(Error::InvalidState);
         }
+
         // Step 2
-        let global = self.global();
-        if blob.IsClosed() {
-            let exception = DOMException::new(&global, DOMErrorName::InvalidStateError);
-            self.error.set(Some(&exception));
-
-            self.dispatch_progress_event(atom!("error"), 0, None);
-            return Ok(());
-        }
+        self.change_ready_state(FileReaderReadyState::Loading);
 
         // Step 3
-        self.change_ready_state(FileReaderReadyState::Loading);
-
-        // Step 4
         let blob_contents = Arc::new(blob.get_bytes().unwrap_or(vec![]));
 
         let type_ = blob.Type();
 
         let load_data = ReadMetaData::new(String::from(type_), label.map(String::from), function);
 
         let fr = Trusted::new(self);
         let gen_id = self.generation_id.get();
--- a/servo/components/script/dom/url.rs
+++ b/servo/components/script/dom/url.rs
@@ -1,14 +1,13 @@
 /* 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/. */
 
 use dom::bindings::cell::DOMRefCell;
-use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
 use dom::bindings::codegen::Bindings::URLBinding::{self, URLMethods};
 use dom::bindings::error::{Error, ErrorResult, Fallible};
 use dom::bindings::js::{MutNullableJS, Root};
 use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
 use dom::bindings::str::{DOMString, USVString};
 use dom::blob::Blob;
 use dom::globalscope::GlobalScope;
 use dom::urlhelper::UrlHelper;
@@ -97,37 +96,28 @@ impl URL {
     }
 
     // https://w3c.github.io/FileAPI/#dfn-createObjectURL
     pub fn CreateObjectURL(global: &GlobalScope, blob: &Blob) -> DOMString {
         /// XXX: Second field is an unicode-serialized Origin, it is a temporary workaround
         ///      and should not be trusted. See issue https://github.com/servo/servo/issues/11722
         let origin = get_blob_origin(&global.get_url());
 
-        if blob.IsClosed() {
-            // Generate a dummy id
-            let id = Uuid::new_v4();
-            return DOMString::from(URL::unicode_serialization_blob_url(&origin, &id));
-        }
-
         let id = blob.get_blob_url_id();
 
         DOMString::from(URL::unicode_serialization_blob_url(&origin, &id))
     }
 
     // https://w3c.github.io/FileAPI/#dfn-revokeObjectURL
     pub fn RevokeObjectURL(global: &GlobalScope, url: DOMString) {
         /*
-            If the url refers to a Blob that has a readability state of CLOSED OR
-            if the value provided for the url argument is not a Blob URL, OR
+            If the value provided for the url argument is not a Blob URL OR
             if the value provided for the url argument does not have an entry in the Blob URL Store,
 
             this method call does nothing. User agents may display a message on the error console.
-
-            NOTE: The first step is unnecessary, since closed blobs do not exist in the store
         */
         let origin = get_blob_origin(&global.get_url());
 
         if let Ok(url) = ServoUrl::parse(&url) {
              if let Ok((id, _)) = parse_blob_url(&url) {
                 let resource_threads = global.resource_threads();
                 let (tx, rx) = ipc::channel().unwrap();
                 let msg = FileManagerThreadMsg::RevokeBlobURL(id, origin, tx);
--- a/servo/components/script/dom/webidls/Blob.webidl
+++ b/servo/components/script/dom/webidls/Blob.webidl
@@ -6,26 +6,20 @@
 
 [Constructor(optional sequence<BlobPart> blobParts,
   optional BlobPropertyBag options),
  Exposed=(Window,Worker)]
 interface Blob {
 
   readonly attribute unsigned long long size;
   readonly attribute DOMString type;
-  readonly attribute boolean isClosed;
 
-  //slice Blob into byte-ranged chunks
-
+  // slice Blob into byte-ranged chunks
   Blob slice([Clamp] optional long long start,
              [Clamp] optional long long end,
              optional DOMString contentType);
-  void close();
-
 };
 
 dictionary BlobPropertyBag {
-
   DOMString type = "";
-
 };
 
 typedef (/*ArrayBuffer or ArrayBufferView or */Blob or DOMString) BlobPart;