{"record":{"id":"d48cdcc8bf7e7c6a","repo":"denoland/deno","slug":"illegal-constructor-d48cdc","errorCode":null,"errorMessage":"Illegal constructor","messagePattern":"Illegal constructor","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/web/04_global_interfaces.js","lineNumber":20,"sourceCode":"\n// @ts-check\n/// <reference path=\"../../core/internal.d.ts\" />\n\n(function () {\nconst { core, primordials } = __bootstrap;\nconst {\n  Symbol,\n  SymbolToStringTag,\n  TypeError,\n} = primordials;\nconst { EventTarget } = core.loadExtScript(\"ext:deno_web/02_event.js\");\n\nconst illegalConstructorKey = Symbol(\"illegalConstructorKey\");\n\nclass Window extends EventTarget {\n  constructor(key = null) {\n    if (key !== illegalConstructorKey) {\n      throw new TypeError(\"Illegal constructor\");\n    }\n    super();\n  }\n\n  get [SymbolToStringTag]() {\n    return \"Window\";\n  }\n}\n\nclass WorkerGlobalScope extends EventTarget {\n  constructor(key = null) {\n    if (key != illegalConstructorKey) {\n      throw new TypeError(\"Illegal constructor\");\n    }\n    super();\n  }\n\n  get [SymbolToStringTag]() {","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/web/04_global_interfaces.js#L2-L38","documentation":"Window is exposed on Deno's global interface list for type and instanceof purposes only; its constructor requires the internal illegalConstructorKey (ext/web/04_global_interfaces.js:20), so new Window() throws TypeError 'Illegal constructor'. Deno has no Window instance distinct from the global object — the window global is an alias of globalThis. The class exists so library code that does feature detection (typeof window, instanceof checks) works.","triggerScenarios":"new Window(); Reflect.construct(Window, []) — any direct instantiation from user code.","commonSituations":"jsdom-style test scaffolding or polyfills that construct window objects in Node habits; feature-detection code that instantiates to probe support; snippets pasted from browser DevTools experimentation.","solutions":["Use globalThis (or its window alias) directly — Deno's window already exists.","For instanceof checks, compare against the prototype: x instanceof Window works without constructing.","In tests, stub window-like behavior with your own objects rather than constructing Window."],"exampleFix":"// before\nconst win = new Window(); // TypeError: Illegal constructor\n\n// after\nconst win = globalThis; // `window` is an alias of globalThis in Deno","handlingStrategy":"fallback","validationCode":"const win = typeof window === 'object' ? window : globalThis;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use globalThis or its window alias directly","Use instanceof Window for checks, never construction","Fake window-like behavior in tests with your own objects"],"tags":["window","dom","constructor"],"backgroundTag":"illegal-constructor","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}