aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/interface.rs
diff options
context:
space:
mode:
authorbors-servo <servo-ops@mozilla.com>2021-08-01 10:31:40 -0400
committerGitHub <noreply@github.com>2021-08-01 10:31:40 -0400
commitbd92fad81a24d08208a5739cad4bde6eb58d6ce8 (patch)
treee0e84609080a1d237bfdcaa10e0bef18cdea26ea /components/script/dom/bindings/interface.rs
parent052278d0580ec1cbd2c9887e65d259dbf5efa775 (diff)
parentafbe2fa1f259411b6c49a3ec3b2baccfbf1664d9 (diff)
downloadservo-bd92fad81a24d08208a5739cad4bde6eb58d6ce8.tar.gz
servo-bd92fad81a24d08208a5739cad4bde6eb58d6ce8.zip
Auto merge of #28546 - yvt:feat-cow-infra, r=jdm
Implement `Location`'s custom internal methods This PR partly resurrects #16501 and introduces the use of principals object to associate objects and Realms with origins. Using this infrastructure, this PR implements [the custom internal methods][1] of the `Location` interface, which is "maybe-cross-origin". Unimplemented/incomplete things: - Other maybe-cross-origin interfaces, namely `WindowProxy` and `DissimilarWindowLocation`, aren't implemented correctly yet (causing most test cases of `tests/wpt/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects.html` to fail). - `WindowProxy`: #28556 - [The "perform a security check" operation][2] and `Location`'s non-cross-origin properties' relevant `Document` origin checks aren't implemented either (not sure if they are covered by the existing tests). - There are a slight deviation from the standard and inefficiency in `CrossOriginGetOwnPropertyHelper`'s current implementation. - #28557 [1]: https://html.spec.whatwg.org/multipage/#the-location-interface [2]: https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #16243 and make some progress in #2382 --- - [x] There are tests for these changes OR - [ ] These changes do not require tests because ___
Diffstat (limited to 'components/script/dom/bindings/interface.rs')
-rw-r--r--components/script/dom/bindings/interface.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs
index 82303f800ba..f73152c9df7 100644
--- a/components/script/dom/bindings/interface.rs
+++ b/components/script/dom/bindings/interface.rs
@@ -9,6 +9,7 @@ use crate::dom::bindings::codegen::PrototypeList;
use crate::dom::bindings::constant::{define_constants, ConstantSpec};
use crate::dom::bindings::conversions::{get_dom_class, DOM_OBJECT_SLOT};
use crate::dom::bindings::guard::Guard;
+use crate::dom::bindings::principals::ServoJSPrincipals;
use crate::dom::bindings::utils::{ProtoOrIfaceArray, DOM_PROTOTYPE_SLOT};
use crate::script_runtime::JSContext as SafeJSContext;
use js::error::throw_type_error;
@@ -36,6 +37,7 @@ use js::rust::wrappers::{JS_DefineProperty3, JS_DefineProperty4, JS_DefineProper
use js::rust::wrappers::{JS_LinkConstructorAndPrototype, JS_NewObjectWithGivenProto};
use js::rust::{define_methods, define_properties, get_object_class};
use js::rust::{HandleObject, HandleValue, MutableHandleObject, RealmOptions};
+use servo_url::MutableOrigin;
use std::convert::TryFrom;
use std::ptr;
@@ -136,6 +138,7 @@ pub unsafe fn create_global_object(
private: *const libc::c_void,
trace: TraceHook,
mut rval: MutableHandleObject,
+ origin: &MutableOrigin,
) {
assert!(rval.is_null());
@@ -145,10 +148,12 @@ pub unsafe fn create_global_object(
options.creationOptions_.streams_ = true;
select_compartment(cx, &mut options);
+ let principal = ServoJSPrincipals::new(origin);
+
rval.set(JS_NewGlobalObject(
*cx,
class,
- ptr::null_mut(),
+ principal.as_raw(),
OnNewGlobalHookOption::DontFireOnNewGlobalHook,
&*options,
));