servo/components/script/dom/bindings
Josh Matthews 3a04f4195e
script: Return global objects for DOM objects in the relevant realm (#37120)
DomObject::global is a tricky API because it's used pervasively but has
subtle requirements that are not documented and not yet enforced by the
type system (#36116). The method returns the relevant global object for
a given DOM object, but that operation is only meaningful if there is an
active realm. We usually, but not always, have an active realm.

This change avoids a footgun by following the principle of least
surprise. Rather than making every single caller of `something.global()`
both prove that there is an active realm and think about which realm
they want active, we implement the obvious behaviour: always activate
the realm of the callee before obtaining the relevant global.
 
Testing: Existing WPT coverage is sufficient; this method is called all
over the codebase.
Fixes: #37070 #27037

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-05-25 03:21:05 +00:00
..
buffer_source.rs WebIDL Fix ImageData constructor to take a Uint8ClampedArray instead of js_object (#31398) 2025-05-09 11:05:56 +00:00
cell.rs Remove ref_filter_map dependency (#36857) 2025-05-18 14:00:58 +00:00
constructor.rs Use version of markup5ever with web_atoms crate (#36542) 2025-04-19 11:49:37 +00:00
conversions.rs Move generated bindings to script_bindings (#36323) 2025-04-04 06:45:08 +00:00
error.rs Implement CSSStyleSheet::replaceSync (#36586) 2025-04-23 15:29:01 +00:00
frozenarray.rs Use explicit reborrows with mozjs::MutableHandle (#35892) 2025-03-23 01:23:52 +00:00
function.rs Cleanups for future script crate split (#35987) 2025-03-16 13:46:14 +00:00
import.rs Move generated bindings to script_bindings (#36323) 2025-04-04 06:45:08 +00:00
inheritance.rs More miscellaneous script splitting changes (#36220) 2025-03-30 11:06:30 +00:00
like.rs Move more bindings types to script_bindings (#35620) 2025-02-23 14:25:46 +00:00
mod.rs script: copy include! files from script_bindings to script's OUT_DIR (#36384) 2025-04-08 19:22:24 +00:00
principals.rs Move generated bindings to script_bindings (#36323) 2025-04-04 06:45:08 +00:00
proxyhandler.rs Move generated bindings to script_bindings (#36323) 2025-04-04 06:45:08 +00:00
refcounted.rs refactor: add CanGc as argument to Promise::reject_error (#35646) 2025-02-25 10:12:58 +00:00
reflector.rs script: Return global objects for DOM objects in the relevant realm (#37120) 2025-05-25 03:21:05 +00:00
root.rs More miscellaneous script splitting changes (#36220) 2025-03-30 11:06:30 +00:00
serializable.rs script: Add generic root storage to StructuredCloneReader. (#36640) 2025-04-23 13:05:41 +00:00
settings_stack.rs Move generated bindings to script_bindings (#36323) 2025-04-04 06:45:08 +00:00
str.rs Update rustfmt to the 2024 style edition (#35764) 2025-03-03 11:26:53 +00:00
structuredclone.rs imagebitmap: Make ImageBitmap serializable and transferable (#37101) 2025-05-23 20:40:25 +00:00
trace.rs Move generated bindings to script_bindings (#36323) 2025-04-04 06:45:08 +00:00
transferable.rs script: Add generic root storage to StructuredCloneReader. (#36640) 2025-04-23 13:05:41 +00:00
utils.rs Eagerly define interfaces on non-Window globals (#36604) 2025-04-21 03:32:21 +00:00
weakref.rs Move generated bindings to script_bindings (#36323) 2025-04-04 06:45:08 +00:00
xmlname.rs Use version of markup5ever with web_atoms crate (#36542) 2025-04-19 11:49:37 +00:00