{"record":{"id":"b91ffca2845dbe0c","repo":"siyuan-note/siyuan","slug":"globalthis-object-is-not-an-object","errorCode":null,"errorMessage":"globalThis.Object is not an object","messagePattern":"globalThis\\.Object is not an object","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/sandbox.go","lineNumber":127,"sourceCode":"\tlo.Must0(injectLogger(p, rt, siyuan))\n\tlo.Must0(injectStorage(p, rt, siyuan))\n\tlo.Must0(injectRpc(p, rt, siyuan))\n\tlo.Must0(injectAgent(p, rt, siyuan))\n\tlo.Must0(injectClient(p, rt, siyuan))\n\tlo.Must0(injectServer(p, rt, siyuan))\n\tlo.Must0(injectSecretsVars(p, rt, siyuan))\n\n\tlo.Must0(ObjectFreeze(rt, siyuan))\n\n\tlo.Must0(rt.GlobalObject().Set(\"siyuan\", siyuan))\n\treturn\n}\n\n// ObjectFreeze calls Object.freeze() on the given goja object.\nfunc ObjectFreeze(rt *goja.Runtime, obj *goja.Object) error {\n\tObject := rt.GlobalObject().Get(\"Object\").ToObject(rt)\n\tif Object == nil {\n\t\treturn fmt.Errorf(\"globalThis.Object is not an object\")\n\t}\n\n\tfreeze, ok := goja.AssertFunction(Object.Get(\"freeze\"))\n\tif !ok {\n\t\treturn fmt.Errorf(\"globalThis.Object.freeze is not a function\")\n\t}\n\n\t_, err := freeze(Object, obj)\n\treturn err\n}\n\n// ObjectSeal calls Object.seal() on the given goja object.\nfunc ObjectSeal(rt *goja.Runtime, obj *goja.Object) error {\n\tObject := rt.GlobalObject().Get(\"Object\").ToObject(rt)\n\tif Object == nil {\n\t\treturn fmt.Errorf(\"globalThis.Object is not an object\")\n\t}\n","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/plugin/sandbox.go#L109-L145","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nplugin.ObjectFreeze(rt, siyuan) // error: globalThis.Object is not an object\n// after\nif rt.GlobalObject().Get(\"Object\") == nil {\n    logging.LogWarningf(\"skip freeze: global Object missing\")\n} else if err := plugin.ObjectFreeze(rt, siyuan); err != nil {\n    return err\n}","handlingStrategy":"type-guard","validationCode":"if rt.GlobalObject().Get(\"Object\") == nil {\n    // skip freeze or rebuild runtime\n}","typeGuard":"func hasGlobalObject(rt *goja.Runtime) bool {\n    return rt != nil && rt.GlobalObject() != nil && rt.GlobalObject().Get(\"Object\") != nil\n}","tryCatchPattern":"if err := plugin.ObjectFreeze(rt, obj); err != nil {\n    logging.LogWarningf(\"freeze skipped: %v\", err)\n}","preventionTips":["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"],"tags":["goja","javascript","object-freeze","sandbox"],"backgroundTag":"type-mismatch","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}