Documentation
¶
Overview ¶
Package bldr_util_qjsbytecode caches ES modules compiled to bytecode by the QuickJS-NG WASI reactor, so a later QuickJS instance links a module without parsing its source.
Index ¶
Constants ¶
const Ext = ".qbc"
Ext is the file extension of a cached module.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores module bytecode in a directory, with one subdirectory for each owner, such as a plugin. Each module has one file, named by the SHA-256 of the reactor build, the module name and the module source. QuickJS trusts the bytecode it reads, so only this process writes the cache.
func (*Cache) DeleteOwner ¶
DeleteOwner removes the cached modules of an owner.
func (*Cache) LoadModule ¶
func (c *Cache) LoadModule(ctx context.Context, le *logrus.Entry, qjs *quickjs.QuickJS, owner, name string, src []byte) (string, bool, error)
LoadModule registers the module name with the source src in qjs, from the owner's cached bytecode or by compiling src and caching its bytecode. It returns the module's cache file name and whether the cache held it.
An entry QuickJS rejects is discarded and compiled again, and a failure to write the cache is logged. A module that does not compile returns the error.