aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-05-27 13:06:37 -0500
committerbors-servo <lbergstrom+bors@mozilla.com>2016-05-27 13:06:37 -0500
commitd9323121b6d3357f84c72225b6554b5c40ba1258 (patch)
tree11444c6128050312f216856786c2d461c4ce073a /components/script
parent3052e4f478e660a60c01dcd2368607429d423e10 (diff)
parent555661ef1ce55b35c624fbe7bfa14c1558b21924 (diff)
downloadservo-d9323121b6d3357f84c72225b6554b5c40ba1258.tar.gz
servo-d9323121b6d3357f84c72225b6554b5c40ba1258.zip
Auto merge of #11470 - servo:postmessage1.5, r=Ms2ger
Make script origins sendable and immutable. <!-- 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 - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because no behaviour change <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11470) <!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r--components/script/origin.rs34
1 files changed, 12 insertions, 22 deletions
diff --git a/components/script/origin.rs b/components/script/origin.rs
index 97e03162679..9b0ba7738e2 100644
--- a/components/script/origin.rs
+++ b/components/script/origin.rs
@@ -2,63 +2,53 @@
* 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 ref_filter_map::ref_filter_map;
-use std::cell::{RefCell, Ref};
-use std::rc::Rc;
+use std::sync::Arc;
use url::Origin as UrlOrigin;
use url::{Url, Host};
/// A representation of an [origin](https://html.spec.whatwg.org/multipage/#origin-2).
-#[derive(HeapSizeOf)]
+#[derive(HeapSizeOf, JSTraceable)]
pub struct Origin {
- #[ignore_heap_size_of = "Rc<T> has unclear ownership semantics"]
- inner: Rc<RefCell<UrlOrigin>>,
+ #[ignore_heap_size_of = "Arc<T> has unclear ownership semantics"]
+ inner: Arc<UrlOrigin>,
}
-// We can't use RefCell inside JSTraceable, but Origin doesn't contain JS values and
-// DOMRefCell makes it much harder to write unit tests (due to setting up required TLS).
-no_jsmanaged_fields!(Origin);
-
impl Origin {
/// Create a new origin comprising a unique, opaque identifier.
pub fn opaque_identifier() -> Origin {
Origin {
- inner: Rc::new(RefCell::new(UrlOrigin::new_opaque())),
+ inner: Arc::new(UrlOrigin::new_opaque()),
}
}
/// Create a new origin for the given URL.
pub fn new(url: &Url) -> Origin {
Origin {
- inner: Rc::new(RefCell::new(url.origin())),
+ inner: Arc::new(url.origin()),
}
}
- pub fn set(&self, origin: UrlOrigin) {
- *self.inner.borrow_mut() = origin;
- }
-
/// Does this origin represent a host/scheme/port tuple?
pub fn is_scheme_host_port_tuple(&self) -> bool {
- self.inner.borrow().is_tuple()
+ self.inner.is_tuple()
}
/// Return the host associated with this origin.
- pub fn host(&self) -> Option<Ref<Host<String>>> {
- ref_filter_map(self.inner.borrow(), |origin| match *origin {
+ pub fn host(&self) -> Option<&Host<String>> {
+ match *self.inner {
UrlOrigin::Tuple(_, ref host, _) => Some(host),
UrlOrigin::Opaque(..) => None,
- })
+ }
}
/// https://html.spec.whatwg.org/multipage/#same-origin
pub fn same_origin(&self, other: &Origin) -> bool {
- *self.inner.borrow() == *other.inner.borrow()
+ self.inner == other.inner
}
pub fn copy(&self) -> Origin {
Origin {
- inner: Rc::new(RefCell::new(self.inner.borrow().clone())),
+ inner: Arc::new((*self.inner).clone()),
}
}