Lodash isArguments Detection in Node.js Strict Mode

The Lodash utility _.isArguments determines whether a given value is a native JavaScript arguments object by leveraging both internal type tags and specific structural object markers. In Node.js environments—including those executing in strict mode—Lodash primarily inspects the internal [[Class]] via Object.prototype.toString. When that check is insufficient or across varying runtime contexts, it falls back to inspecting specific property descriptors on the object, notably the presence and non-enumerability of the callee property alongside basic object-like characteristics.

Primary Marker: The Internal Class Tag

In modern Node.js runtimes (V8), the engine assigns the internal [[Class]] tag [object Arguments] to arguments objects created in both sloppy and strict modes.

Lodash first evaluates:

baseGetTag(value) === '[object Arguments]'

If the environment correctly exposes this tag via Object.prototype.toString.call(value), Lodash uses it directly. In standard Node.js execution, strict mode does not alter this internal tag, allowing this primary check to pass.

Fallback Environment Markers in Strict Mode

If environment inconsistencies arise (such as cross-realm boundary issues, transpiled code, or older engine shims), Lodash relies on a fallback function. In Node.js strict mode, accessing certain properties like callee directly throws a TypeError. To safely detect arguments without triggering errors, Lodash inspects structural environment markers using prototype methods:

  1. Object-Like Verification (isObjectLike)
    The target value must be non-null and have a typeof evaluation of 'object':

    value !== null && typeof value === 'object'
  2. The callee Own Property Marker
    In strict mode, the JavaScript engine attaches a non-configurable, non-enumerable "poison-pill" getter/setter to arguments.callee. Lodash tests for the presence of this key using Object.prototype.hasOwnProperty:

    hasOwnProperty.call(value, 'callee') === true

    Calling hasOwnProperty checks for the existence of the property descriptor without invoking the getter, preventing the strict mode TypeError.

  3. Non-Enumerability of callee
    Ordinary objects that spoof arguments typically declare an enumerable callee property. Lodash verifies that callee is strictly non-enumerable:

    !propertyIsEnumerable.call(value, 'callee')

Combined Fallback Logic

When the primary tag check is unavailable or bypassed, Lodash compiles these markers into a single structural condition:

function baseIsArguments(value) {
  return isObjectLike(value) && 
         hasOwnProperty.call(value, 'callee') && 
         !propertyIsEnumerable.call(value, 'callee');
}

By coupling the non-enumerable 'callee' descriptor check with object validation, _.isArguments safely and accurately isolates native strict-mode arguments objects in Node.js without producing runtime evaluation faults.