siyuan-note/siyuan · error
globalThis.Object is not an object
Error message
globalThis.Object is not an object
What it means
ObjectFreeze calls JavaScript Object.freeze() on a goja object to make it immutable inside the plugin sandbox. Before doing so it reads globalThis.Object and converts it; if the global Object constructor is missing (nil), it throws this error. This should never happen on a healthy ECMAScript runtime, so it indicates the runtime's global object has been stripped or corrupted.
Source
Thrown at kernel/plugin/sandbox.go:127
lo.Must0(injectLogger(p, rt, siyuan))
lo.Must0(injectStorage(p, rt, siyuan))
lo.Must0(injectRpc(p, rt, siyuan))
lo.Must0(injectAgent(p, rt, siyuan))
lo.Must0(injectClient(p, rt, siyuan))
lo.Must0(injectServer(p, rt, siyuan))
lo.Must0(injectSecretsVars(p, rt, siyuan))
lo.Must0(ObjectFreeze(rt, siyuan))
lo.Must0(rt.GlobalObject().Set("siyuan", siyuan))
return
}
// ObjectFreeze calls Object.freeze() on the given goja object.
func ObjectFreeze(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")
}
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")
}
View on GitHub (pinned to 8641553a1f)
Solutions
- Ensure the goja Runtime is created with the standard global environment (do not delete or overwrite globalThis.Object)
- Run ObjectFreeze/injection before any plugin code that could tamper with globals, or after restoring Object
- Add a fallback that skips freezing when Object is unavailable, logging a warning instead of failing hard
- Verify with rt.GlobalObject().Get("Object") != nil before calling ObjectFreeze
Example fix
// before
plugin.ObjectFreeze(rt, siyuan) // error: globalThis.Object is not an object
// after
if rt.GlobalObject().Get("Object") == nil {
logging.LogWarningf("skip freeze: global Object missing")
} else if err := plugin.ObjectFreeze(rt, siyuan); err != nil {
return err
} Defensive patterns
Strategy: type-guard
Validate before calling
if rt.GlobalObject().Get("Object") == nil {
// skip freeze or rebuild runtime
} Type guard
func hasGlobalObject(rt *goja.Runtime) bool {
return rt != nil && rt.GlobalObject() != nil && rt.GlobalObject().Get("Object") != nil
} Try / catch
if err := plugin.ObjectFreeze(rt, obj); err != nil {
logging.LogWarningf("freeze skipped: %v", err)
} Prevention
- Never delete or replace globalThis.Object in runtime setup
- Freeze objects before running untrusted plugin code
- Use the standard global environment when creating the runtime
When it happens
Trigger: Calling ObjectFreeze on a goja Runtime whose GlobalObject() has no "Object" property — e.g. the global was replaced/deleted, the runtime was created with a minimal global template lacking Object, or Get("Object") returned a nil value that ToObject turned into nil.
Common situations: A sandbox that deliberately removed standard globals before freezing; running injection before the runtime finished constructing its global environment; custom runtime initialization code that overwrote globalThis.Object.
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.freeze is not a function
- globalThis.Object.seal 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/b91ffca2845dbe0c.
Report an issue: GitHub.