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 this

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace the property with the standard protocol: obj[Symbol.iterator] = function* () { ... }
  2. For plain data objects, use Array.from(obj) or spread with an appropriate iterator instead of a custom __iterator__
  3. 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

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


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/5ae2d6350ffb2e3b. Report an issue: GitHub.