{"record":{"id":"bd03ef417172d74a","repo":"dianping/cat","slug":"object-defineproperty-called-on-non-object-objec","errorCode":null,"errorMessage":"Object.defineProperty called on non-object: {object}","messagePattern":"Object\\.defineProperty called on non-object: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-xquery.js","lineNumber":49329,"sourceCode":"}\nif (Object.defineProperty) {\n    var definePropertyWorksOnObject = doesDefinePropertyWork({});\n    var definePropertyWorksOnDom = typeof document == \"undefined\" ||\n        doesDefinePropertyWork(document.createElement(\"div\"));\n    if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {\n        var definePropertyFallback = Object.defineProperty;\n    }\n}\n\nif (!Object.defineProperty || definePropertyFallback) {\n    var ERR_NON_OBJECT_DESCRIPTOR = \"Property description must be an object: \";\n    var ERR_NON_OBJECT_TARGET = \"Object.defineProperty called on non-object: \"\n    var ERR_ACCESSORS_NOT_SUPPORTED = \"getters & setters can not be defined \" +\n                                      \"on this javascript engine\";\n\n    Object.defineProperty = function defineProperty(object, property, descriptor) {\n        if ((typeof object != \"object\" && typeof object != \"function\") || object === null)\n            throw new TypeError(ERR_NON_OBJECT_TARGET + object);\n        if ((typeof descriptor != \"object\" && typeof descriptor != \"function\") || descriptor === null)\n            throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);\n        if (definePropertyFallback) {\n            try {\n                return definePropertyFallback.call(Object, object, property, descriptor);\n            } catch (exception) {\n            }\n        }\n        if (owns(descriptor, \"value\")) {\n\n            if (supportsAccessors && (lookupGetter(object, property) ||\n                                      lookupSetter(object, property)))\n            {\n                var prototype = object.__proto__;\n                object.__proto__ = prototypeOfObject;\n                delete object[property];\n                object[property] = descriptor.value;\n                object.__proto__ = prototype;","sourceCodeStart":49311,"sourceCodeEnd":49347,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-xquery.js#L49311-L49347","documentation":"es5-shim's fallback implementation of Object.defineProperty, active when the engine lacks (or has a broken) defineProperty. It validates that the target is an object or function before defining, mirroring the ES5 spec requirement, and throws a TypeError naming the invalid target when it is not. In modern engines the native defineProperty throws instead, so this message signals the shim path (very old browser or a sandboxed/odd JS runtime).","triggerScenarios":"Object.defineProperty('a string', 'prop', {...}), Object.defineProperty(null, ...), Object.defineProperty(42, ...), or passing a primitive produced by a function that was expected to return an object (e.g. a factory returning undefined on a missing case).","commonSituations":"Augmenting a primitive by mistake (string from an input, number from parse); passing the result of document.getElementById (null when element missing) as target; code running in the web worker context of this editor bundle on an engine without full ES5 support.","solutions":["Verify the target is an object/function before the call; the common bug is a null lookup result (missing DOM node, missing map entry).","If the target came from getElementById/querySelector, check for null first and handle the missing-element case.","If you intended to define a property on a primitive wrapper, use its object form (new String(...)) — though prefer not to.","Upgrade the browser/runtime so the native Object.defineProperty is used and the shim is inert."],"exampleFix":"// before\nvar el = document.getElementById('editor');\nObject.defineProperty(el, 'state', { value: 1 }); // el may be null\n\n// after\nvar el = document.getElementById('editor');\nif (!el) throw new Error('editor element not found');\nObject.defineProperty(el, 'state', { value: 1 });","handlingStrategy":"type-guard","validationCode":"if (target === null || (typeof target !== 'object' && typeof target !== 'function')) {\n  throw new Error('defineProperty target missing/invalid: ' + target);\n}\nObject.defineProperty(target, prop, desc);","typeGuard":"function isDefinePropertyTarget(t) {\n  return t !== null && (typeof t === 'object' || typeof t === 'function');\n}","tryCatchPattern":null,"preventionTips":["Null-check DOM lookups before augmenting elements","Default possibly-missing objects: target = target || {};","Never pass primitives as the defineProperty target"],"tags":["es5-shim","polyfill","define-property","typeerror","null-safety"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}