Documentation
¶
Overview ¶
Package tifa gives a beastjs.VM what tifa (github.com/liustack/tifa) gives each VM of its pool before it runs a bundle: URL and URLSearchParams, Intl and Temporal, and the functions named __tifa_* that the bundles tifa builds ask for.
beastjs is made for tifa, so tifa, the beastjs command and the program that measures tifa's pages (internal/measure/pages) all set a VM up with Register, and what a VM of each has is the same.
The functions named __tifa_* are those of Hooks:
- __tifa_random_bytes__(n): n bytes from crypto/rand, 0 to 65536, in base64. The bundle's crypto.getRandomValues and crypto.randomUUID read them.
- __tifa_murmur2__(s): the hash of @emotion/hash of the string s, by the engine (beastjs.VM.NewMurmur2Function), or undefined for anything else, which emotion then hashes in javascript.
- __tifa_escape, __tifa_copy_props, __tifa_start_tag and __tifa_end_tag: the functions of the engine that do the work of React's escape, its copy of props and the tags React DOM writes (beastjs.VM.RegisterEscapeText, beastjs.VM.RegisterCopyProps, beastjs.VM.RegisterStartTag, beastjs.VM.RegisterEndTag).
- __tifa_async_context__: an object with get and set, the async context of the VM (beastjs.GetAsyncContext, beastjs.SetAsyncContext), which the AsyncLocalStorage of tifa's host script keeps its stores in.
The host script of a bundle takes __tifa_random_bytes__ and __tifa_async_context__ and deletes them from the global object before any code of the app runs. The others stay.
What stays in tifa: the memory limit, the call depth and the eval timeout of a VM, the checks of tifa dev and of its emit check build, the bundle and the collections between renders.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Hooks ¶
func Hooks() []string
Hooks returns the names of the globals named __tifa_* that Register defines, in the order it defines them. Each is a function, but for __tifa_async_context__, an object with the functions get and set.
func Register ¶
Register sets vm up as tifa sets up each VM of its pool, in tifa's order: URL and URLSearchParams (url.Register), Intl (intl.Register), Temporal (temporal.Register), then the hooks of Hooks. Call it after the eval timeout is set, as url.Register asks, and before the bundle runs.
Register runs once on a VM: a second call fails, as url.Register refuses a VM that has URL. When a step fails, vm keeps what the steps before it defined: close it.
Types ¶
This section is empty.