oxc-project/oxc · warning · OxcDiagnostic
Reserved name `__iterator__`
Error message
Reserved name `__iterator__`
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_iterator.rs:8
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use crate::{AstNode, context::LintContext, rule::Rule};
fn no_iterator_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Reserved name `__iterator__`")
.with_help("Consider using [Symbol.iterator] instead")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoIterator;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow the use of the `__iterator__` property.
///
/// ### Why is this bad?
///
/// The `__iterator__` property was a SpiderMonkey extension to JavaScript
/// that could be used to create custom iterators that are compatible with
/// JavaScript’s for in and for each constructs. However, this property is
/// now obsolete, so it should not be used. Here’s an example of how thisView on GitHub (pinned to e1e7af627c)
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
Example fix
// before
Foo.prototype.__iterator__ = function () { /* ... */ };
// after
Foo.prototype[Symbol.iterator] = function* () { /* ... */ }; Defensive patterns
Strategy: validation
Validate before calling
// CI guard: fail if __iterator__ appears anywhere in the codebase
import { execSync } from 'node:child_process';
try {
execSync('grep -rn __iterator__ src/', { stdio: 'pipe' });
console.error('legacy __iterator__ usage found');
process.exitCode = 1;
} catch {
/* clean */
} Type guard
function isIterable(obj) {
return obj != null && typeof obj[Symbol.iterator] === 'function';
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Do not use `arguments.{method_name}`.
- `debugger` statement is not allowed
- Variables should not be deleted
- A regular expression literal can be confused with '/='.
- Duplicate class member: {member_name:?}
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/5ae2d6350ffb2e3b.
Report an issue: GitHub.