Back to Deno

Snapshot Example

libs/core/examples/snapshot/README.md

2.7.141.1 KB
Original Source

Snapshot Example

This example roughly follows the blog post Roll Your Own JavaScript Runtime: Part 3 to create a JsRuntime with an embedded startup snapshot.

That blog post and the two that preceded it were no longer accurate. By including this example in the repository, it will continually be built, so it will hopefully stay up-to-date.

Running

The example can be run by changing to the core/examples/snapshot directory and running cargo run.

Differences

Differences from those blog posts:

  • The create_snapshot() API has changed in various ways.
  • New API features for extensions:
    • #[op2] (read more)
    • extension!(...) macro replaces Extension::builder()
    • ESM-based extensions.

Missing features vs. those blog posts:

  • Does not implement TsModuleLoader, to keep this example more concise.