Documentation
¶
Overview ¶
Package mozjs 经 cgo 嵌入 SpiderMonkey,提供线程绑定的上下文、根表句柄、求值、Go 原生函数、微任务与中断
Index ¶
- func Clock() float64
- func Gzip(data []byte) []byte
- func Init() error
- func Now() float64
- func SetCamouLocale(locale string)
- func SetClock(base, pace, limit float64)
- type Call
- type Context
- func (cx *Context) Call(fn Handle, this Handle, args ...Value) (Value, error)
- func (cx *Context) ClearKeptObjects()
- func (cx *Context) Close()
- func (cx *Context) Evaluate(global Handle, source, filename string, line int) (Value, error)
- func (cx *Context) FlushRejections(fn Handle) error
- func (cx *Context) GC()
- func (cx *Context) Get(object Handle, name string) (Value, error)
- func (cx *Context) InstallHostNatives(target Handle) error
- func (cx *Context) InstallWindowNatives(global Handle) error
- func (cx *Context) Interrupt()
- func (cx *Context) NewFunction(global Handle, name string, nargs int, fn NativeFunc) (Handle, error)
- func (cx *Context) NewGlobal(same Handle, timezone string) (Handle, error)
- func (cx *Context) NewObject(global Handle) (Handle, error)
- func (cx *Context) ParseJSON(global Handle, text string) (Value, error)
- func (cx *Context) Release(handle Handle)
- func (cx *Context) ReleaseValue(value Value)
- func (cx *Context) RunJobs()
- func (cx *Context) Set(object Handle, name string, value Value) error
- func (cx *Context) SetMicrotaskReporter(fn Handle)
- func (cx *Context) SetThrowLocation(filename string, line, column int)
- func (cx *Context) SetTrustedTypes(registry Handle, block bool)
- func (cx *Context) ShrinkGC()
- type Error
- type Handle
- type Kind
- type NativeFunc
- type Options
- type ThrowError
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Gzip ¶ added in v0.3.10
Gzip 返回 Windows 版 Firefox CompressionStream("gzip") 对 data 输出的字节:以 Firefox 所用的 zlib-rs 按其默认级别与调用顺序压缩,gzip 头的操作系统字节取 Windows 版写入的 10
func SetCamouLocale ¶
func SetCamouLocale(locale string)
SetCamouLocale 设置当前线程 mozilla::intl::Locale 的默认区域为 Camoufox 的 navigator.language
Types ¶
type Call ¶
type Call struct {
// contains filtered or unexported fields
}
Call 是一次原生函数调用
func (*Call) ReturnBytes ¶
ReturnBytes 以字节新建 ArrayBuffer 作为返回值
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context 是绑定到创建它的 OS 线程的 JSContext,除 Interrupt 外只能在该线程上使用
func NewContext ¶
NewContext 在当前 OS 线程创建上下文,调用方需已锁定线程
func (*Context) ClearKeptObjects ¶
func (cx *Context) ClearKeptObjects()
ClearKeptObjects 结束当前任务的 WeakRef 存活期
func (*Context) FlushRejections ¶
FlushRejections 按发生顺序以 (promise, handled, global) 调用 fn 并清空 Promise 拒绝记录
func (*Context) InstallHostNatives ¶
InstallHostNatives 在 target 上定义 now、kindOf、throwLocation 与 incumbent
func (*Context) InstallWindowNatives ¶
InstallWindowNatives 在全局对象上定义 queueMicrotask、atob 与 btoa
func (*Context) Interrupt ¶
func (cx *Context) Interrupt()
Interrupt 请求终止正在执行的脚本,可在任意 goroutine 调用,上下文已销毁时不做任何事
func (*Context) NewFunction ¶
func (cx *Context) NewFunction(global Handle, name string, nargs int, fn NativeFunc) (Handle, error)
NewFunction 在 global 的 Realm 中新建调用 fn 的函数
func (*Context) NewGlobal ¶
NewGlobal 新建 Window 全局对象,same 非 0 时与其共用 compartment,timezone 为该 Realm 的时区
func (*Context) SetMicrotaskReporter ¶
SetMicrotaskReporter 设置以 (global, exception) 报告微任务回调异常的函数
func (*Context) SetThrowLocation ¶
SetThrowLocation 设置宿主 throwLocation 返回的抛出位置
func (*Context) SetTrustedTypes ¶
SetTrustedTypes 设置 TrustedScript 源码登记表与是否拒绝以字符串编译代码
type ThrowError ¶
ThrowError 让原生函数以当前全局对象中名为 Type 的错误构造器抛出 Message
func (*ThrowError) Error ¶
func (err *ThrowError) Error() string