dianping/cat · error · TypeError

Object.defineProperty called on non-object: {object}

Error message

Object.defineProperty called on non-object: {object}

What it means

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).

Source

Thrown at cat-home/src/main/webapp/assets/js/editor/worker-xquery.js:49329

}
if (Object.defineProperty) {
    var definePropertyWorksOnObject = doesDefinePropertyWork({});
    var definePropertyWorksOnDom = typeof document == "undefined" ||
        doesDefinePropertyWork(document.createElement("div"));
    if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
        var definePropertyFallback = Object.defineProperty;
    }
}

if (!Object.defineProperty || definePropertyFallback) {
    var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
    var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
    var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
                                      "on this javascript engine";

    Object.defineProperty = function defineProperty(object, property, descriptor) {
        if ((typeof object != "object" && typeof object != "function") || object === null)
            throw new TypeError(ERR_NON_OBJECT_TARGET + object);
        if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
            throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
        if (definePropertyFallback) {
            try {
                return definePropertyFallback.call(Object, object, property, descriptor);
            } catch (exception) {
            }
        }
        if (owns(descriptor, "value")) {

            if (supportsAccessors && (lookupGetter(object, property) ||
                                      lookupSetter(object, property)))
            {
                var prototype = object.__proto__;
                object.__proto__ = prototypeOfObject;
                delete object[property];
                object[property] = descriptor.value;
                object.__proto__ = prototype;

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Verify the target is an object/function before the call; the common bug is a null lookup result (missing DOM node, missing map entry).
  2. If the target came from getElementById/querySelector, check for null first and handle the missing-element case.
  3. If you intended to define a property on a primitive wrapper, use its object form (new String(...)) — though prefer not to.
  4. Upgrade the browser/runtime so the native Object.defineProperty is used and the shim is inert.

Example fix

// before
var el = document.getElementById('editor');
Object.defineProperty(el, 'state', { value: 1 }); // el may be null

// after
var el = document.getElementById('editor');
if (!el) throw new Error('editor element not found');
Object.defineProperty(el, 'state', { value: 1 });
Defensive patterns

Strategy: type-guard

Validate before calling

if (target === null || (typeof target !== 'object' && typeof target !== 'function')) {
  throw new Error('defineProperty target missing/invalid: ' + target);
}
Object.defineProperty(target, prop, desc);

Type guard

function isDefinePropertyTarget(t) {
  return t !== null && (typeof t === 'object' || typeof t === 'function');
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14). Data as JSON: /api/errors/bd03ef417172d74a. Report an issue: GitHub.