Skip to content
Browse files

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

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.

  • Loading branch information...
CYBAI committed Aug 8, 2019
1 parent 555fa75 commit 28e64fc701fc4a5f2f2e2dafe841465fe87e036c
Showing with 5 additions and 1 deletion.
  1. +5 −1 components/script/
@@ -142,7 +142,11 @@ pub trait ScriptPort {
unsafe extern "C" fn get_incumbent_global(_: *const c_void, _: *mut RawJSContext) -> *mut JSObject {
AssertUnwindSafe(|| {
let incumbent_global = GlobalScope::incumbent();


.map(|g| g.reflector().get_jsobject().get())

0 comments on commit 28e64fc

Please sign in to comment.
You can’t perform that action at this time.