CoreRabbitC
Deno2y ago
4 replies
CoreRabbit

How do I see which ops are registered?

I am trying to understand how the deno_core::op2 macro works. I used deno_runtime back in September 2021 and I remember that I could console.log Deno[Deno.internal].core.ops to see which ops are registered.

Back in 2021 I read the deno CLI code and in my own project copied the setup of MainWorker because I wanted setTimeout. Now in 2024 I tried to upgrade the versions of deno_runtime to 0.272 and ran into the limitations of my knowledge.

Right now I see that Deno.core.ops exists if you construct a JsRuntime. And I can use Object.getOwnPropertyNames to print out a list of ops to verify that my rust function ended up inside Deno.core.ops

And I also see that when I construct a MainWorker like in https://github.com/denoland/deno/blob/main/runtime/examples/extension/main.rs that Deno.core.ops does not exist. And instead it seems like rust function ends up inside the magic import 'ext:core/ops'.

- Do I need to be constructing a MainWorker to have setTimeout working? Because when I try making a JsRuntime and load only my extension I see setTimeout is not defined
- Is there an explanation of where the extension mechanism puts the javascript symbols?
- Does the new way of using ops work by having a bootstrap js or esm that will import from the magic ext:core/ops and then make those rust functions available by assigning to globalThis? Should I be making a wrapper function like I seen in examples, or can I directly assign the op_hello symbol to globalThis?
GitHub
A modern runtime for JavaScript and TypeScript. Contribute to denoland/deno development by creating an account on GitHub.
deno/runtime/examples/extension/main.rs at main · denoland/deno
Was this page helpful?