siyuan-note/siyuan · error
globalThis.Object.seal is not a function
Error message
globalThis.Object.seal is not a function
What it means
ObjectSeal resolves globalThis.Object and requires its "seal" property to be a callable function. If Object exists but Object.seal was replaced by a non-function value, goja.AssertFunction fails and this error is thrown. It indicates the Object built-in was partially overwritten or incompletely stubbed.
Source
Thrown at kernel/plugin/sandbox.go:148
freeze, ok := goja.AssertFunction(Object.Get("freeze"))
if !ok {
return fmt.Errorf("globalThis.Object.freeze is not a function")
}
_, err := freeze(Object, obj)
return err
}
// ObjectSeal calls Object.seal() on the given goja object.
func ObjectSeal(rt *goja.Runtime, obj *goja.Object) error {
Object := rt.GlobalObject().Get("Object").ToObject(rt)
if Object == nil {
return fmt.Errorf("globalThis.Object is not an object")
}
seal, ok := goja.AssertFunction(Object.Get("seal"))
if !ok {
return fmt.Errorf("globalThis.Object.seal is not a function")
}
_, err := seal(Object, obj)
return err
}
// ObjectSetDataMethods attaches text(), json(), buffer() and arrayBuffer() methods to a JS object,
// each returning a Promise that resolves with the corresponding representation of data.
func ObjectSetDataMethods(p *KernelPlugin, rt *goja.Runtime, object *goja.Object, data []byte) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ObjectSetDataMethods: %v", r)
}
}()
lo.Must0(object.Set("text", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
promise, resolve, reject := rt.NewPromise()
View on GitHub (pinned to 8641553a1f)
Solutions
- Restore globalThis.Object.seal to a function before injection
- Seal API objects before untrusted code runs so built-ins cannot be overwritten first
- In tests, stub with a callable: Object.seal = (o) => o
- Catch the error and degrade gracefully (skip sealing) rather than failing plugin load
Example fix
// before
rt.RunString("Object.seal = undefined")
plugin.ObjectSeal(rt, obj) // error: not a function
// after
rt.RunString("Object.seal = Object.seal || ((o) => o)") Defensive patterns
Strategy: type-guard
Validate before calling
o := rt.GlobalObject().Get("Object")
if o != nil {
if _, ok := goja.AssertFunction(o.ToObject(rt).Get("seal")); !ok { /* skip or restore */ }
} Type guard
func canSeal(rt *goja.Runtime) bool {
o := rt.GlobalObject().Get("Object")
if o == nil { return false }
_, ok := goja.AssertFunction(o.ToObject(rt).Get("seal"))
return ok
} Try / catch
if err := plugin.ObjectSeal(rt, obj); err != nil {
logging.LogWarningf("seal skipped: %v", err)
} Prevention
- Never reassign Object.seal to a non-function
- Seal before executing untrusted code
- Use callable stubs in tests
When it happens
Trigger: Calling ObjectSeal on a runtime where globalThis.Object.seal was reassigned to undefined, a number, an object, or a non-callable value — typically by plugin code, a polyfill, or an incorrect test stub.
Common situations: Test doubles that stubbed Object.seal as a plain value; polyfills redefining Object wholesale; hardening scripts that replaced seal with metadata instead of a function.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- globalThis.Object is not an object
- globalThis.Object.freeze is not a function
- RunScript: %v
- globalThis.siyuan.plugin.lifecycle not found
- globalThis.siyuan.plugin.lifecycle.%s not bound to a functio
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/a9c90c5f37f4a7de.
Report an issue: GitHub.