{"record":{"id":"5ae2d6350ffb2e3b","repo":"oxc-project/oxc","slug":"reserved-name-iterator","errorCode":null,"errorMessage":"Reserved name `__iterator__`","messagePattern":"Reserved name `__iterator__`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_iterator.rs","lineNumber":8,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_iterator_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Reserved name `__iterator__`\")\n        .with_help(\"Consider using [Symbol.iterator] instead\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoIterator;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow the use of the `__iterator__` property.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The `__iterator__` property was a SpiderMonkey extension to JavaScript\n    /// that could be used to create custom iterators that are compatible with\n    /// JavaScript’s for in and for each constructs. However, this property is\n    /// now obsolete, so it should not be used. Here’s an example of how this","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_iterator.rs#L1-L26","documentation":"Diagnostic from oxlint's eslint/no-iterator rule (crates/oxc_linter/src/rules/eslint/no_iterator.rs:8). It reports use of the __iterator__ property, a legacy SpiderMonkey extension for making objects iterable. It is not part of any ECMAScript standard: in modern engines it silently does nothing (iteration will not work), and in old Firefox it errored. The iterable protocol is Symbol.iterator.","triggerScenarios":"Assigning or reading the property: obj.__iterator__ = function () {...}; iterator: obj.__iterator__; or object literals declaring an __iterator__ key. Any member access named __iterator__ is flagged.","commonSituations":"Porting very old Mozilla-specific code (pre-2006 Firefox extensions, old SpiderMonkey samples); following outdated tutorials on making objects iterable; generators/iterators not working because code targets the legacy hook.","solutions":["Replace the property with the standard protocol: obj[Symbol.iterator] = function* () { ... }","For plain data objects, use Array.from(obj) or spread with an appropriate iterator instead of a custom __iterator__","Search the codebase for '__iterator__' to catch all occurrences during the migration"],"exampleFix":"// before\nFoo.prototype.__iterator__ = function () { /* ... */ };\n\n// after\nFoo.prototype[Symbol.iterator] = function* () { /* ... */ };","handlingStrategy":"validation","validationCode":"// CI guard: fail if __iterator__ appears anywhere in the codebase\nimport { execSync } from 'node:child_process';\ntry {\n  execSync('grep -rn __iterator__ src/', { stdio: 'pipe' });\n  console.error('legacy __iterator__ usage found');\n  process.exitCode = 1;\n} catch {\n  /* clean */\n}","typeGuard":"function isIterable(obj) {\n  return obj != null && typeof obj[Symbol.iterator] === 'function';\n}","tryCatchPattern":null,"preventionTips":["Always implement iteration via Symbol.iterator","When porting old SpiderMonkey code, search for __proto__, __iterator__, and __noSuchMethod__ together","Use for...of only with objects that pass an isIterable guard"],"tags":["lint","javascript","deprecated-api","iterator","spidermonkey"],"backgroundTag":"deprecated-legacy-api","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}