dianping/cat · error · TypeError

Object.getOwnPropertyDescriptor called on a non-object: {obj

Error message

Object.getOwnPropertyDescriptor called on a non-object: {object}

What it means

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.

Source

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

        }
        return -1;
    };
}
if (!Object.getPrototypeOf) {
    Object.getPrototypeOf = function getPrototypeOf(object) {
        return object.__proto__ || (
            object.constructor ?
            object.constructor.prototype :
            prototypeOfObject
        );
    };
}
if (!Object.getOwnPropertyDescriptor) {
    var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
                         "non-object: ";
    Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
        if ((typeof object != "object" && typeof object != "function") || object === null)
            throw new TypeError(ERR_NON_OBJECT + object);
        if (!owns(object, property))
            return;

        var descriptor, getter, setter;
        descriptor =  { enumerable: true, configurable: true };
        if (supportsAccessors) {
            var prototype = object.__proto__;
            object.__proto__ = prototypeOfObject;

            var getter = lookupGetter(object, property);
            var setter = lookupSetter(object, property);
            object.__proto__ = prototype;

            if (getter || setter) {
                if (getter) descriptor.get = getter;
                if (setter) descriptor.set = setter;
                return descriptor;
            }

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Coerce or check first: ensure the target is an object (typeof target === 'object' && target !== null) before calling.
  2. For strings, wrap or use String(target) semantics deliberately; better, use Object('str') when you need a wrapper object.
  3. In cross-browser code, do not rely on the native lenient behavior — validate explicitly so old shims and new engines behave the same.

Example fix

// before
var d = Object.getOwnPropertyDescriptor(value, 'prop');

// after
var d = (value !== null && (typeof value === 'object' || typeof value === 'function'))
    ? Object.getOwnPropertyDescriptor(value, 'prop')
    : undefined;
Defensive patterns

Strategy: type-guard

Validate before calling

function safeGetOwnPropertyDescriptor(o, p) {
  if (o === null || (typeof o !== 'object' && typeof o !== 'function')) return undefined;
  return Object.getOwnPropertyDescriptor(o, p);
}

Type guard

function isInspectableObject(v) {
  return v !== null && (typeof v === 'object' || typeof v === 'function');
}

Try / catch

try {
  d = Object.getOwnPropertyDescriptor(target, prop);
} catch (e) {
  if (e instanceof TypeError && /non-object/.test(e.message)) {
    d = undefined; // target was a primitive/null — treat as no descriptor
  } else { throw e; }
}

Prevention

When it happens

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

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

Related errors


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