{"record":{"id":"0df4957952d23b45","repo":"ajaxorg/ace","slug":"cannot-convert-undefined-or-null-to-object","errorCode":null,"errorMessage":"Cannot convert undefined or null to object","messagePattern":"Cannot convert undefined or null to object","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lib/es6-shim.js","lineNumber":51,"sourceCode":"      var result = \"\";\n      var string = this;\n      while (count > 0) {\n        if (count & 1) result += string;\n\n        if ((count >>= 1)) string += string;\n      }\n      return result;\n    });\n  }\n  if (!String.prototype.includes) {\n    defineProp(String.prototype, \"includes\", function (str, position) {\n      return this.indexOf(str, position) != -1;\n    });\n  }\n  if (!Object.assign) {\n    Object.assign = function (target) {\n      if (target === undefined || target === null) {\n        throw new TypeError(\"Cannot convert undefined or null to object\");\n      }\n\n      var output = Object(target);\n      for (var index = 1; index < arguments.length; index++) {\n        var source = arguments[index];\n        if (source !== undefined && source !== null) {\n          Object.keys(source).forEach(function (key) {\n            output[key] = source[key];\n          });\n        }\n      }\n      return output;\n    };\n  }\n  if (!Object.values) {\n    Object.values = function (o) {\n      return Object.keys(o).map(function (k) {\n        return o[k];","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/ajaxorg/ace/blob/2c1eddc392eb92cf222a4478f1893d2b2c354fb0/src/lib/es6-shim.js#L33-L69","documentation":"This TypeError is thrown by the ES6-shim polyfill for Object.assign when the first argument (target) is undefined or null. Per the ES6 spec, Object.assign cannot coerce null/undefined into an object, so the shim mimics native behavior and fails fast with this exact message.","triggerScenarios":"Calling Object.assign(null, {...}) or Object.assign(undefined, {...}) — typically when a variable expected to hold a target object is uninitialized or a lookup returned null.","commonSituations":"Running code on legacy browsers (IE) or old JS engines lacking native Object.assign, where the es6-shim polyfill is active; passing the result of a failed lookup (e.g., map.get or DOM query) as the merge target.","solutions":["Ensure the target argument is a non-null object before calling Object.assign, or default it: Object.assign(target || {}, src)","Fix the upstream code that produced the null/undefined target instead of papering over it at the call site","If null targets are intentional no-ops in your logic, switch to a helper like {...target, ...src} or a merge utility that skips null targets","On modern engines verify Object.assign is native (not this shim) — the native one throws the same TypeError, so the root fix is identical"],"exampleFix":"// before\nObject.assign(userPrefs, defaults); // userPrefs undefined on first run\n// after\nObject.assign(userPrefs || {}, defaults);","handlingStrategy":"type-guard","validationCode":"if (target == null) throw new TypeError('Object.assign requires a non-null target');\nObject.assign(target, source);","typeGuard":"function isMergeTarget(t) { return t !== null && (typeof t === 'object' || typeof t === 'function'); }","tryCatchPattern":"try {\n  return Object.assign(target, src);\n} catch (e) {\n  if (e instanceof TypeError) return Object.assign({}, src); // or rethrow\n  throw e;\n}","preventionTips":["Default target arguments: Object.assign(target || {}, src)","Enable null-safety lint rules or TypeScript non-null assertions on merge targets","Don't pass results of possibly-empty lookups (Map.get, querySelector) straight into Object.assign"],"tags":["typeerror","null-undefined","polyfill","object-assign"],"backgroundTag":"cannot-convert-null-or-undefined-to-object","analyzedSha":"2c1eddc392eb92cf222a4478f1893d2b2c354fb0","analyzedAt":"2026-08-30T00:39:52.222Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}