mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Assert incumbent global is always some in get_incumbent_global hook
While working on module script, I'd like to use Promise with a custom callback with type `Box<dyn TaskBox>` which means we didn't use web API callbacks as native handlers. However, we'll get a panic from `enqueue_promise_job` and the panic says we have a `null` incumbent global. The main problem here is, the Promise API is strongly tied to JS engine and it always assumes there's a meaningful answer for "what specific global is this promise associated with". So, when I don't use the Promise for a specific web API, our engine cannot find a proper incumbent global for us so that we get the `null` incumbent global panic. To make us catch this case easier in the future, we should add the assertion inside `get_incumbent_global` hook so that we can know this quickly next time. Ref: https://mozilla.logbot.info/servo/20190807#c16525481
This commit is contained in:
parent
555fa75b2c
commit
28e64fc701
1 changed files with 5 additions and 1 deletions
|
@ -142,7 +142,11 @@ pub trait ScriptPort {
|
|||
unsafe extern "C" fn get_incumbent_global(_: *const c_void, _: *mut RawJSContext) -> *mut JSObject {
|
||||
wrap_panic(
|
||||
AssertUnwindSafe(|| {
|
||||
GlobalScope::incumbent()
|
||||
let incumbent_global = GlobalScope::incumbent();
|
||||
|
||||
assert!(incumbent_global.is_some());
|
||||
|
||||
incumbent_global
|
||||
.map(|g| g.reflector().get_jsobject().get())
|
||||
.unwrap_or(ptr::null_mut())
|
||||
}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue