Refactor:Refactors report_cross_origin_denial method to use unsafe block (#36365)

The method report_cross_origin_denial was marked as unsafe, have instead
moved the unsafe code within the method into an unsafe block within the
method and removed the unsafe marking for the method.

Testing: No testing needed
Fixes: This PR resolves #36356.
Signed-off-by : Ashok Kaushik kaushikashok45@gmail.com

---------

Signed-off-by: ashok.kaushik <ashok.kaushik@zohocorp.com>
Co-authored-by: ashok.kaushik <ashok.kaushik@zohocorp.com>
This commit is contained in:
kaushikashok45 2025-04-06 00:36:48 +05:30 committed by GitHub
parent b87bf0b806
commit a67409fb25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -509,7 +509,7 @@ fn ensure_cross_origin_property_holder(
/// What this function does corresponds to the operations in
/// <https://html.spec.whatwg.org/multipage/#the-location-interface> denoted as
/// "Throw a `SecurityError` DOMException".
pub(crate) unsafe fn report_cross_origin_denial<D: DomTypes>(
pub(crate) fn report_cross_origin_denial<D: DomTypes>(
cx: SafeJSContext,
id: RawHandleId,
access: &str,
@ -520,10 +520,12 @@ pub(crate) unsafe fn report_cross_origin_denial<D: DomTypes>(
id_to_source(cx, id).as_deref().unwrap_or("< error >"),
);
let in_realm_proof = AlreadyInRealm::assert_for_cx(cx);
if !JS_IsExceptionPending(*cx) {
let global = D::GlobalScope::from_context(*cx, InRealm::Already(&in_realm_proof));
// TODO: include `id` and `access` in the exception message
<D as DomHelpers<D>>::throw_dom_exception(cx, &global, Error::Security, CanGc::note());
unsafe {
if !JS_IsExceptionPending(*cx) {
let global = D::GlobalScope::from_context(*cx, InRealm::Already(&in_realm_proof));
// TODO: include `id` and `access` in the exception message
<D as DomHelpers<D>>::throw_dom_exception(cx, &global, Error::Security, CanGc::note());
}
}
false
}