diff options
author | bors-servo <servo-ops@mozilla.com> | 2021-08-01 10:31:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-01 10:31:40 -0400 |
commit | bd92fad81a24d08208a5739cad4bde6eb58d6ce8 (patch) | |
tree | e0e84609080a1d237bfdcaa10e0bef18cdea26ea /components/script/dom/bindings/utils.rs | |
parent | 052278d0580ec1cbd2c9887e65d259dbf5efa775 (diff) | |
parent | afbe2fa1f259411b6c49a3ec3b2baccfbf1664d9 (diff) | |
download | servo-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/utils.rs')
-rw-r--r-- | components/script/dom/bindings/utils.rs | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 36f255bc4ee..77192291416 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -17,8 +17,8 @@ use crate::dom::bindings::trace::trace_object; use crate::dom::windowproxy; use crate::script_runtime::JSContext as SafeJSContext; use js::conversions::ToJSValConvertible; +use js::glue::JS_GetReservedSlot; use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper}; -use js::glue::{GetCrossCompartmentWrapper, JS_GetReservedSlot, WrapperNew}; use js::glue::{UnwrapObjectDynamic, UnwrapObjectStatic, RUST_JSID_TO_INT, RUST_JSID_TO_STRING}; use js::glue::{ RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING, RUST_JSID_IS_VOID, @@ -26,12 +26,11 @@ use js::glue::{ use js::jsapi::HandleId as RawHandleId; use js::jsapi::HandleObject as RawHandleObject; use js::jsapi::MutableHandleIdVector as RawMutableHandleIdVector; -use js::jsapi::MutableHandleObject as RawMutableHandleObject; use js::jsapi::{AtomToLinearString, GetLinearStringCharAt, GetLinearStringLength}; use js::jsapi::{CallArgs, DOMCallbacks, GetNonCCWObjectGlobal}; -use js::jsapi::{Heap, JSAutoRealm, JSContext, JS_FreezeObject}; +use js::jsapi::{Heap, JSContext, JS_FreezeObject}; use js::jsapi::{JSAtom, JS_IsExceptionPending, JS_IsGlobalObject}; -use js::jsapi::{JSJitInfo, JSObject, JSTracer, JSWrapObjectCallbacks}; +use js::jsapi::{JSJitInfo, JSObject, JSTracer}; use js::jsapi::{ JS_DeprecatedStringHasLatin1Chars, JS_ResolveStandardClass, ObjectOpResult, StringIsArrayIndex, }; @@ -44,7 +43,7 @@ use js::rust::wrappers::JS_GetPrototype; use js::rust::wrappers::JS_HasProperty; use js::rust::wrappers::JS_HasPropertyById; use js::rust::wrappers::JS_SetProperty; -use js::rust::{get_object_class, is_dom_class, GCMethods, ToString, ToWindowProxyIfWindow}; +use js::rust::{get_object_class, is_dom_class, GCMethods, ToString}; use js::rust::{Handle, HandleId, HandleObject, HandleValue, MutableHandleValue}; use js::typedarray::{CreateWith, Float32Array}; use js::JS_CALLEE; @@ -53,6 +52,7 @@ use std::ffi::CString; use std::os::raw::{c_char, c_void}; use std::ptr; use std::slice; +use std::str; /// Proxy handler for a WindowProxy. pub struct WindowProxyHandler(pub *const libc::c_void); @@ -475,36 +475,6 @@ pub unsafe extern "C" fn resolve_global( true } -unsafe extern "C" fn wrap( - cx: *mut JSContext, - _existing: RawHandleObject, - obj: RawHandleObject, -) -> *mut JSObject { - // FIXME terrible idea. need security wrappers - // https://github.com/servo/servo/issues/2382 - WrapperNew(cx, obj, GetCrossCompartmentWrapper(), ptr::null(), false) -} - -unsafe extern "C" fn pre_wrap( - cx: *mut JSContext, - _scope: RawHandleObject, - _orig_obj: RawHandleObject, - obj: RawHandleObject, - _object_passed_to_wrap: RawHandleObject, - rval: RawMutableHandleObject, -) { - let _ac = JSAutoRealm::new(cx, obj.get()); - let obj = ToWindowProxyIfWindow(obj.get()); - assert!(!obj.is_null()); - rval.set(obj) -} - -/// Callback table for use with JS_SetWrapObjectCallbacks -pub static WRAP_CALLBACKS: JSWrapObjectCallbacks = JSWrapObjectCallbacks { - wrap: Some(wrap), - preWrap: Some(pre_wrap), -}; - /// Deletes the property `id` from `object`. pub unsafe fn delete_property_by_id( cx: *mut JSContext, |