{"record":{"id":"9f3b42a9a6a2ad80","repo":"dianping/cat","slug":"object-getownpropertydescriptor-called-on-a-non-ob","errorCode":null,"errorMessage":"Object.getOwnPropertyDescriptor called on a non-object: {object}","messagePattern":"Object\\.getOwnPropertyDescriptor called on a non-object: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-xquery.js","lineNumber":49235,"sourceCode":"        }\n        return -1;\n    };\n}\nif (!Object.getPrototypeOf) {\n    Object.getPrototypeOf = function getPrototypeOf(object) {\n        return object.__proto__ || (\n            object.constructor ?\n            object.constructor.prototype :\n            prototypeOfObject\n        );\n    };\n}\nif (!Object.getOwnPropertyDescriptor) {\n    var ERR_NON_OBJECT = \"Object.getOwnPropertyDescriptor called on a \" +\n                         \"non-object: \";\n    Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {\n        if ((typeof object != \"object\" && typeof object != \"function\") || object === null)\n            throw new TypeError(ERR_NON_OBJECT + object);\n        if (!owns(object, property))\n            return;\n\n        var descriptor, getter, setter;\n        descriptor =  { enumerable: true, configurable: true };\n        if (supportsAccessors) {\n            var prototype = object.__proto__;\n            object.__proto__ = prototypeOfObject;\n\n            var getter = lookupGetter(object, property);\n            var setter = lookupSetter(object, property);\n            object.__proto__ = prototype;\n\n            if (getter || setter) {\n                if (getter) descriptor.get = getter;\n                if (setter) descriptor.set = setter;\n                return descriptor;\n            }","sourceCodeStart":49217,"sourceCodeEnd":49253,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-xquery.js#L49217-L49253","documentation":"From the bundled ES5 shim: a fallback Object.getOwnPropertyDescriptor that validates its first argument, throwing TypeError 'Object.getOwnPropertyDescriptor called on a non-object: <object>' unless typeof is 'object' or 'function' and the value is not null. Per ES5, the API requires an object; primitives (except the shim's strict object/function check) and null are rejected.","triggerScenarios":"Object.getOwnPropertyDescriptor('str', 'length'), Object.getOwnPropertyDescriptor(null, 'x'), or passing a number/boolean/undefined first argument in code executed where the shim is installed or natively (spec-wise the native version accepts primitives and returns undefined — the shim is stricter, so behavior can differ).","commonSituations":"Feature-detecting properties on values that may be primitives; duck-typing helpers that call it on whatever is passed; differences between shim behavior (throw) and modern native behavior (coerce/undefined) surfacing only on old engines.","solutions":["Coerce or check first: ensure the target is an object (typeof target === 'object' && target !== null) before calling.","For strings, wrap or use String(target) semantics deliberately; better, use Object('str') when you need a wrapper object.","In cross-browser code, do not rely on the native lenient behavior — validate explicitly so old shims and new engines behave the same."],"exampleFix":"// before\nvar d = Object.getOwnPropertyDescriptor(value, 'prop');\n\n// after\nvar d = (value !== null && (typeof value === 'object' || typeof value === 'function'))\n    ? Object.getOwnPropertyDescriptor(value, 'prop')\n    : undefined;","handlingStrategy":"type-guard","validationCode":"function safeGetOwnPropertyDescriptor(o, p) {\n  if (o === null || (typeof o !== 'object' && typeof o !== 'function')) return undefined;\n  return Object.getOwnPropertyDescriptor(o, p);\n}","typeGuard":"function isInspectableObject(v) {\n  return v !== null && (typeof v === 'object' || typeof v === 'function');\n}","tryCatchPattern":"try {\n  d = Object.getOwnPropertyDescriptor(target, prop);\n} catch (e) {\n  if (e instanceof TypeError && /non-object/.test(e.message)) {\n    d = undefined; // target was a primitive/null — treat as no descriptor\n  } else { throw e; }\n}","preventionTips":["Guard calls with an object check so behavior matches across native and shim environments.","Wrap primitives explicitly with Object(...) only when wrapper semantics are intended.","Do not assume modern leniency (primitives returning undefined) in code that must also run with the shim."],"tags":["javascript","es5-shim","object-introspection","typeerror"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}