Brr: WorkerGlobalScope?

I have a piece of OCaml/Brr/js_of_ocaml code running inside a WebWorker.

How do I grab the WorkerGlobalScope - Web APIs | MDN via self (or any other way) ?

Thanks!

In jsoo, I would expect Js.Unsafe.global to work.

1 Like

In brr it doesn’t take a long time to discover Jv.global via the API docs or the FFI manual.

1 Like

Maybe this is due to my lack of JS knowledge, it was not obvious to me that JS “globalThis” is actually a WorkerGlobalScope: globalThis - JavaScript | MDN

The first thing I tried, was rg "WorkerGlobalScope" which only returns one line:

let ami () = Jv.has “WorkerGlobalScope” Jv.global

Now, with 2020 hindsight, one could argue: you should then see that Jv.global is what you’re after.

However, I’d argue on the contrary that line seems to suggest that Jv.global is NOT what I want, and instead, I want to somehow fetch the “WorkerGlobalScope” field of Jv.global .

The next thing that came to mind was: perhaps there is a module named WorkerGlobalScope, and if we find it ,we find some object of type WorkerGlobalScope.t and we’re done.

This leads to rg WorkerGlobalScope (without the “”). In addition to the previous *.ml file, this now brings up a number of *.mli files, where WorkerGlboalScope is mentioned in a comment pointing at MDN.

For whatever reason, WorkerGlobalScope - Web APIs | MDN currently does not mention the word “globalThis”

Conditioned on knowing that WorkerGlobalScope == globalThis, this is easy to resolve; however, until knowing that WorkerGlobalScope == globalThis, it is not obvious to me how one makes the jump from WorkerGlobalScope to Jv.global