quickjs

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClockSkew added in v0.16.0

func ClockSkew(ctx context.Context) (time.Duration, error)

ClockSkew measures how far the QuickJS sandbox wall clock (Date.now(), evaluated in a throwaway runtime) drifts from the host clock. Positive means the sandbox is ahead of the host.

Motivation (issue "QuickJS prerender sandbox wall clock frozen at 2022-01-01T00:00:00Z"): wazero's default ModuleConfig serves a deterministic fake clock (epoch 2022-01-01 UTC, +1ms per read); bridge.New wires the real host clock via WithSysWalltime/WithSysNanotime. If that wiring ever regresses (wazero upgrade, refactored instantiation), prerenders silently bake stale timestamps into HTML that then fail hydration in the browser. This check turns that silent failure into a construction-time signal.

Cost: one wasm instantiation against the shared compilation cache (no recompile), a single eval, then teardown.

func VerifyClock added in v0.16.0

func VerifyClock(ctx context.Context, maxSkew time.Duration) error

VerifyClock asserts the sandbox wall clock tracks the host clock within maxSkew. Engine-pool construction or prerender builds should call this once up front (e.g. maxSkew = time.Minute) and fail fast — or log the returned error through the caller's structured logger — so a fake sandbox clock is exposed at build time instead of as wrong years in shipped HTML.

Returns nil when the sandbox clock is within maxSkew of the host.

func VerifyClockErrorFor added in v0.16.0

func VerifyClockErrorFor(sandbox, host time.Time, maxSkew time.Duration) error

VerifyClockErrorFor is the pure decision core of VerifyClock on already captured readings (exported so the failure branch is testable without faking an engine). sandbox/host are the two clock samples to compare.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

func (*Context) Array

func (c *Context) Array() Value

func (*Context) ArrayBuffer

func (c *Context) ArrayBuffer(data []byte) Value

func (*Context) BigInt

func (c *Context) BigInt(v int64) Value

func (*Context) Bool

func (c *Context) Bool(v bool) Value

func (*Context) Close

func (c *Context) Close() error

func (*Context) Date

func (c *Context) Date(epochMs float64) Value

func (*Context) Eval

func (c *Context) Eval(code string) (Value, error)

func (*Context) EvalFile

func (c *Context) EvalFile(code, filename string) (Value, error)

func (*Context) EvalModule

func (c *Context) EvalModule(code, filename string) (Value, error)

func (*Context) EvalToString

func (c *Context) EvalToString(code, filename string) (string, error)

func (*Context) Float64

func (c *Context) Float64(v float64) Value

func (*Context) Function

func (c *Context) Function(name string, fn GoFunc) Value

func (*Context) GetGlobal

func (c *Context) GetGlobal(name string) (Value, error)

func (*Context) Global

func (c *Context) Global() (Value, error)

func (*Context) Int32

func (c *Context) Int32(v int32) Value

func (*Context) Int64

func (c *Context) Int64(v int64) Value

func (*Context) Null

func (c *Context) Null() Value

func (*Context) Object

func (c *Context) Object() Value

func (*Context) ParseJSON

func (c *Context) ParseJSON(json string) (Value, error)

func (*Context) SetGlobal

func (c *Context) SetGlobal(name string, val Value) error

func (*Context) String

func (c *Context) String(s string) Value

func (*Context) ThrowError

func (c *Context) ThrowError(msg string) Value

func (*Context) ThrowTypeError

func (c *Context) ThrowTypeError(msg string) Value

func (*Context) Undefined

func (c *Context) Undefined() Value

type EvalFlag

type EvalFlag int32
const (
	EvalGlobal EvalFlag = 0

	EvalModule EvalFlag = 1 << 0
)

type GoFunc

type GoFunc func(ctx *Context, this Value, args []Value) Value

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

func NewRuntime

func NewRuntime() (*Runtime, error)

func NewRuntimeWithContext

func NewRuntimeWithContext(ctx context.Context) (*Runtime, error)

func (*Runtime) Close

func (r *Runtime) Close() error

func (*Runtime) ExecutePendingJobs

func (r *Runtime) ExecutePendingJobs() (int, error)

func (*Runtime) ForceClose

func (r *Runtime) ForceClose() error

func (*Runtime) NewContext

func (r *Runtime) NewContext() (*Context, error)

func (*Runtime) RunGC

func (r *Runtime) RunGC() error

func (*Runtime) SetLogFunc

func (r *Runtime) SetLogFunc(fn func(msg string))

func (*Runtime) SetMaxStackSize

func (r *Runtime) SetMaxStackSize(size uint32) error

func (*Runtime) SetMemoryLimit

func (r *Runtime) SetMemoryLimit(limit uint32) error

type Value

type Value struct {
	// contains filtered or unexported fields
}

func (Value) BigInt

func (v Value) BigInt() (int64, error)

func (Value) Bool

func (v Value) Bool() bool

func (Value) Bytes

func (v Value) Bytes() ([]byte, error)

func (Value) Call

func (v Value) Call(this Value, args ...Value) (Value, error)

func (Value) CallMethod

func (v Value) CallMethod(method string, args ...Value) (Value, error)

func (Value) Delete

func (v Value) Delete(prop string) error

func (Value) Float64

func (v Value) Float64() (float64, error)

func (Value) Get

func (v Value) Get(prop string) (Value, error)

func (Value) GetIdx

func (v Value) GetIdx(idx int) (Value, error)

func (Value) Has

func (v Value) Has(prop string) bool

func (Value) Instanceof

func (v Value) Instanceof(ctor Value) bool

func (Value) Int32

func (v Value) Int32() (int32, error)

func (Value) Int64

func (v Value) Int64() (int64, error)

func (Value) IsArray

func (v Value) IsArray() bool

func (Value) IsBigInt

func (v Value) IsBigInt() bool

func (Value) IsBool

func (v Value) IsBool() bool

func (Value) IsDate

func (v Value) IsDate() bool

func (Value) IsError

func (v Value) IsError() bool

func (Value) IsFunction

func (v Value) IsFunction() bool

func (Value) IsNull

func (v Value) IsNull() bool

func (Value) IsNumber

func (v Value) IsNumber() bool

func (Value) IsObject

func (v Value) IsObject() bool

func (Value) IsPromise

func (v Value) IsPromise() bool

func (Value) IsString

func (v Value) IsString() bool

func (Value) IsSymbol

func (v Value) IsSymbol() bool

func (Value) IsUndefined

func (v Value) IsUndefined() bool

func (Value) JSONStringify

func (v Value) JSONStringify() (string, error)

func (Value) Len

func (v Value) Len() int

func (Value) New

func (v Value) New(args ...Value) (Value, error)

func (Value) Set

func (v Value) Set(prop string, val Value) error

func (Value) SetIdx

func (v Value) SetIdx(idx int, val Value) error

func (Value) String

func (v Value) String() string

func (Value) Typeof

func (v Value) Typeof() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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