{"record":{"id":"3c9ed2e92d15b62b","repo":"karatelabs/karate","slug":"super-parent-class-is-not-a-constructor","errorCode":null,"errorMessage":"super: parent class is not a constructor","messagePattern":"super: parent class is not a constructor","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/Interpreter.java","lineNumber":1436,"sourceCode":"        }\n        if (thisObj instanceof JsSet dst && built instanceof JsSet src) {\n            dst.elements.putAll(src.elements);\n            return true;\n        }\n        if (thisObj instanceof JsDate dst && built instanceof JsDate src) {\n            dst.setTimeValue(src.getTimeValue());\n            return true;\n        }\n        return false;\n    }\n\n    // Runs the parent constructor of {@code derivedCtor} against an existing\n    // instance ({@code thisObj}) — the derived `this`. The parent is the derived\n    // constructor's [[Prototype]] (set to the superclass at class-eval time).\n    static void runSuperConstructor(JsFunctionNode derivedCtor, Object thisObj, Object[] args, CoreContext context) {\n        Object parent = derivedCtor.getPrototype(); // Child.__proto__ === Parent\n        if (!(parent instanceof JsCallable parentCallable) || !parentCallable.isConstructable()) {\n            throw JsErrorException.typeError(\"super: parent class is not a constructor\");\n        }\n        if (parent instanceof JsFunctionNode parentFn) {\n            CoreContext sc = new CoreContext(context, parentFn.node, args,\n                    parentFn.declaredContext, parentFn.capturedBindings);\n            sc.strict = parentFn.strict;\n            sc.thisObject = thisObj;\n            sc.activeFunction = parentFn;\n            sc.callInfo = new CallInfo(true, parentFn);\n            sc.privateEnv = parentFn.privateEnv;\n            // If the parent is itself a derived class with an implicit\n            // constructor, forward up the chain before running its (empty) body.\n            // Either way the parent's own instance fields (and private brands) are\n            // its responsibility, on the same before-body / after-super schedule the\n            // top-level construction path uses; a parent with an explicit derived\n            // constructor runs them from its own super() call instead.\n            if (parentFn.isDefaultDerivedConstructor) {\n                runSuperConstructor(parentFn, thisObj, args, sc);\n                runInstanceFieldInitializers(parentFn, thisObj, sc);","sourceCodeStart":1418,"sourceCodeEnd":1454,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/Interpreter.java#L1418-L1454","documentation":"Thrown when running a derived constructor's `super(...)` but the derived class's prototype (its [[Prototype]], set to the superclass at class-eval time) is not a constructable JsCallable. This happens when the extends chain was corrupted or the parent was replaced with a non-constructor value.","triggerScenarios":"Instantiating a derived class whose parent class reference was overwritten with a non-constructable value, or whose [[Prototype]] was mutated (e.g. Object.setPrototypeOf) to a non-callable.","commonSituations":"Monkey-patching or reassigning a class binding after definition; circular or partially-initialized class definitions where the parent ended up undefined or an object.","solutions":["Do not reassign the parent class binding after the derived class is declared.","Re-derive the child class from a valid constructor: `class Child extends ValidParent {}`.","Check for Object.setPrototypeOf calls or factory code that replaced the parent with a plain object."],"exampleFix":"// before\nlet Parent = {};\nclass Child extends Parent {}\n// after\nclass Parent {}\nclass Child extends Parent {}","handlingStrategy":"validation","validationCode":"if (typeof ParentClass !== 'function') throw new Error('parent class must be a constructable function');","typeGuard":"function isClassLike(v) { return typeof v === 'function' && v.prototype && v.prototype.constructor === v; }","tryCatchPattern":"try { var c = new Child(); } catch (e) { if (String(e).includes('parent class is not a constructor')) restoreParent(); }","preventionTips":["Never reassign class bindings after declaration","Avoid Object.setPrototypeOf on constructors","Define inheritance chains in one place"],"tags":["javascript","super","class","inheritance"],"backgroundTag":"not-a-constructor","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"}