Documentation
¶
Index ¶
- func ClockSkew(ctx context.Context) (time.Duration, error)
- func VerifyClock(ctx context.Context, maxSkew time.Duration) error
- func VerifyClockErrorFor(sandbox, host time.Time, maxSkew time.Duration) error
- type Context
- func (c *Context) Array() Value
- func (c *Context) ArrayBuffer(data []byte) Value
- func (c *Context) BigInt(v int64) Value
- func (c *Context) Bool(v bool) Value
- func (c *Context) Close() error
- func (c *Context) Date(epochMs float64) Value
- func (c *Context) Eval(code string) (Value, error)
- func (c *Context) EvalFile(code, filename string) (Value, error)
- func (c *Context) EvalModule(code, filename string) (Value, error)
- func (c *Context) EvalToString(code, filename string) (string, error)
- func (c *Context) Float64(v float64) Value
- func (c *Context) Function(name string, fn GoFunc) Value
- func (c *Context) GetGlobal(name string) (Value, error)
- func (c *Context) Global() (Value, error)
- func (c *Context) Int32(v int32) Value
- func (c *Context) Int64(v int64) Value
- func (c *Context) Null() Value
- func (c *Context) Object() Value
- func (c *Context) ParseJSON(json string) (Value, error)
- func (c *Context) SetGlobal(name string, val Value) error
- func (c *Context) String(s string) Value
- func (c *Context) ThrowError(msg string) Value
- func (c *Context) ThrowTypeError(msg string) Value
- func (c *Context) Undefined() Value
- type EvalFlag
- type GoFunc
- type Runtime
- func (r *Runtime) Close() error
- func (r *Runtime) ExecutePendingJobs() (int, error)
- func (r *Runtime) ForceClose() error
- func (r *Runtime) NewContext() (*Context, error)
- func (r *Runtime) RunGC() error
- func (r *Runtime) SetLogFunc(fn func(msg string))
- func (r *Runtime) SetMaxStackSize(size uint32) error
- func (r *Runtime) SetMemoryLimit(limit uint32) error
- type Value
- func (v Value) BigInt() (int64, error)
- func (v Value) Bool() bool
- func (v Value) Bytes() ([]byte, error)
- func (v Value) Call(this Value, args ...Value) (Value, error)
- func (v Value) CallMethod(method string, args ...Value) (Value, error)
- func (v Value) Delete(prop string) error
- func (v Value) Float64() (float64, error)
- func (v Value) Get(prop string) (Value, error)
- func (v Value) GetIdx(idx int) (Value, error)
- func (v Value) Has(prop string) bool
- func (v Value) Instanceof(ctor Value) bool
- func (v Value) Int32() (int32, error)
- func (v Value) Int64() (int64, error)
- func (v Value) IsArray() bool
- func (v Value) IsBigInt() bool
- func (v Value) IsBool() bool
- func (v Value) IsDate() bool
- func (v Value) IsError() bool
- func (v Value) IsFunction() bool
- func (v Value) IsNull() bool
- func (v Value) IsNumber() bool
- func (v Value) IsObject() bool
- func (v Value) IsPromise() bool
- func (v Value) IsString() bool
- func (v Value) IsSymbol() bool
- func (v Value) IsUndefined() bool
- func (v Value) JSONStringify() (string, error)
- func (v Value) Len() int
- func (v Value) New(args ...Value) (Value, error)
- func (v Value) Set(prop string, val Value) error
- func (v Value) SetIdx(idx int, val Value) error
- func (v Value) String() string
- func (v Value) Typeof() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClockSkew ¶ added in v0.16.0
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
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
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) ArrayBuffer ¶
func (*Context) EvalToString ¶
func (*Context) ThrowError ¶
func (*Context) ThrowTypeError ¶
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
func NewRuntime ¶
func (*Runtime) ExecutePendingJobs ¶
func (*Runtime) ForceClose ¶
func (*Runtime) NewContext ¶
func (*Runtime) SetLogFunc ¶
func (*Runtime) SetMaxStackSize ¶
func (*Runtime) SetMemoryLimit ¶
type Value ¶
type Value struct {
// contains filtered or unexported fields
}