Help us shape the future of Go! Take the 2026 Go Developer Survey

bldr_util_qjsbytecode

package
v0.57.30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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

View Source
const Ext = ".qbc"

Ext is the file extension of a cached module.

Variables

This section is empty.

Functions

func FileName

func FileName(name string, src []byte) string

FileName returns the cache file name of a module.

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 NewCache

func NewCache(dir string) *Cache

NewCache returns a cache rooted at dir.

func (*Cache) DeleteOwner

func (c *Cache) DeleteOwner(owner string) error

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.

func (*Cache) OwnerDir

func (c *Cache) OwnerDir(owner string) string

OwnerDir returns the directory of an owner's modules.

func (*Cache) Prune

func (c *Cache) Prune(owner string, used map[string]struct{}) error

Prune removes the owner's cached modules whose file names are not in used.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL