Closed Bug 1148944 Opened 6 years ago Closed 3 years ago

Subtle, hard-to-pinpoint bug using iterators, for each in, and Javascript 1.7-style yield functions

Categories

(Core :: JavaScript Engine, defect)

24 Branch
x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1098412

People

(Reporter: protz, Unassigned)

Details

function range(begin, end) {
  for (let i = begin; i < end; ++i) {
    yield i;
  }
}

I'm breaking on this function. begin is 0, end is 1. Moving out of this function into the caller, I break on the third line of the snippet below.

      for each (let i in range(this.messages.length - aMessages.length, this.messages.length)) {
        this.messages[i].message.onAddedToDom(domNodes[i]);
        domNodes[i].setAttribute("tabindex", (i+2)+"");
      
The debugger tells me that i is undefined.

Furthermore:
- even though I set a breakpoint on the second line of the snippet above, the debugger won't break on that line;
- the example works, of course, fine in the debugging console of Firefox,
- my code is sprinkled with such whacky for each / iterator / whatever old-style code -- this seems to be the only one that goes off the rails,
- this used to be fine until... maybe a couple months ago? I just got around to debugging this.

I am very well aware that those non-standardized constructs are bound to break in unpredictable, hard-to-reproduce ways, and that they are going to be deprecated soon... so to be honest, I don't expect anyone to fix this, I'm just filing this out of a Mozillian's moral obligation! :)

For the record, I replaced the for each (let ... in) with for (let ... of) and changed the function range into function* range, and it all seemed to work fine.

Ah, more context. This is a big (100,000 users) Thunderbird addon, and we have quite some code written in that style in the Thunderbird codebase too. So if it turns out that there's a way to warn about these, even if the bug doesn't end up being fixed, that'd definitely help!

Thanks,

Jonathan
So with which version are you seeing this? Any chance we could bisect this?
Flags: needinfo?(jonathan.protzenko)
Probably bug 783829 as well.
This is on an up-to-date trunk version (of Thunderbird).
Flags: needinfo?(jonathan.protzenko)
bug 1098412 removed legacy generator functions and Iterator(), and bug 1388317 will remove for-each.
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1098412
You need to log in before you can comment on or make changes to this bug.