{"record":{"id":"aef0e61a4f69b144","repo":"karatelabs/karate","slug":"function-prototype-call-called-on-non-callable","errorCode":null,"errorMessage":"Function.prototype.call called on non-callable","messagePattern":"Function\\.prototype\\.call called on non-callable","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsFunctionPrototype.java","lineNumber":89,"sourceCode":"                    this.args = list;\n                } else {\n                    Object first = list.getFirst();\n                    if (first instanceof List) {\n                        this.args = ((List<Object>) first);\n                    } else {\n                        this.args = new ArrayList<>();\n                    }\n                }\n            } else {\n                this.args = list;\n            }\n        }\n    }\n\n    private Object callMethod(Context context, Object[] args) {\n        JsCallable callable = asCallable(context);\n        if (callable == null) {\n            throw JsErrorException.typeError(\"Function.prototype.call called on non-callable\");\n        }\n        ThisArgs thisArgs = new ThisArgs(args, false);\n        if (context instanceof CoreContext cc) {\n            cc.thisObject = bindForCall(callable, thisArgs.thisObject, cc);\n        }\n        return callable.call(context, thisArgs.args.toArray(new Object[0]));\n    }\n\n    // Spec OrdinaryCallBindThis (§9.2.1.2): the null/undefined → globalThis\n    // substitution applies to sloppy-mode user-defined functions only.\n    // Built-in methods and strict-mode user fns see the raw thisArg —\n    // required for e.g. Object.prototype.toString.call(null) returning\n    // \"[object Null]\" and for RequireObjectCoercible-gated built-ins to throw\n    // TypeError on null/undefined receivers.\n    private static Object bindForCall(JsCallable callable, Object thisObject, CoreContext cc) {\n        if (callable instanceof JsBuiltinMethod) {\n            return thisObject;\n        }","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsFunctionPrototype.java#L71-L107","documentation":"Function.prototype.call invokes its receiver as a callable after rebinding `this`. If the receiver is not callable (undefined, null, a plain object, etc.), Karate throws this TypeError, matching spec §20.3.4.1 step 2 (Call on non-callable).","triggerScenarios":"Function.prototype.call.call({}, obj), calling a method reference whose target was replaced by a non-function, invoking fn.call where fn resolved to undefined from a config or lookup map.","commonSituations":"Dependency-injected callbacks that are missing (undefined) at call time, plugin registries where an entry was overwritten with a non-function, destructured functions from objects that lack the key.","solutions":["Verify the receiver is a function before calling: typeof fn === 'function'.","Fix the lookup/registry so the expected function is actually present.","Provide a default no-op: (fn || (() => {})).call(thisArg, ...)."],"exampleFix":"// before\nhandlers[type].call(ctx, ev); // TypeError when handlers[type] is undefined\n// after\nif (typeof handlers[type] === 'function') handlers[type].call(ctx, ev);","handlingStrategy":"type-guard","validationCode":"if (typeof fn !== 'function') throw new Error('expected a callable, got: ' + typeof fn);","typeGuard":"function isCallable(v) { return typeof v === 'function'; }","tryCatchPattern":"try { return fn.call(ctx, arg); } catch (e) { if (e instanceof TypeError && /non-callable/.test(e.message)) return noOpResult; throw e; }","preventionTips":["Check typeof before invoking looked-up or injected callbacks.","Provide default no-op functions for optional hooks.","Validate registry/plugin entries at registration time.","Avoid overwriting function-valued properties with non-functions."],"tags":["javascript","function","type-error","callable"],"backgroundTag":"type-mismatch","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}