Closed Bug 1072932 Opened 10 years ago Closed 10 years ago

TDZ buglet in test_eventemitter_basic.html

Categories

(DevTools :: General, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 35

People

(Reporter: tromey, Assigned: tromey)

References

Details

Attachments

(1 file)

I had a "try" build fail in test_eventemitter_basic.html.
The error says in part:

ReferenceError: can't access let declaration `beenHere1' before initialization: next@chrome://mochitests/content/chrome/toolkit/devtools/tests/mochitest/test_eventemitter_basic.html:61:14
ReferenceError: can't access let declaration `beenHere1' before initialization: next@chrome://mochitests/content/chrome/toolkit/devtools/tests/mochitest/test_eventemitter_basic.html:61:14


Looking at `beenHere1' I see:

      function testEmitter(aObject) {
...
        emitter.on("next", next);
        emitter.emit("next", "abc", "def");

        let beenHere1 = false;
        function next(eventName, str1, str2) {
...

So I think that `beenHere1' is calling into the "temporal dead zone":
depending on the circumstances, `next' may be called before `beenHere1'
has been bound.

The fix is to hoist the `let' up above the call to `emitter.on'.
I'll attach a patch momentarily.
I hoisted "beenHere2" as well since it seemed possible for "onlyOnce"
to be called before that let binding was seen.

I looked at the other files in this directory and everything else was
fine.
Assignee: nobody → ttromey
Attachment #8495260 - Flags: review?(past)
Comment on attachment 8495260 [details] [diff] [review]
hoist "let"s to avoid the TDZ

Review of attachment 8495260 [details] [diff] [review]:
-----------------------------------------------------------------

Nice, I've seen that error recently myself.
Attachment #8495260 - Flags: review?(past) → review+
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/d056ffd17f0c
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 35
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: