Closed Bug 1069480 Opened 6 years ago Closed 4 years ago

Update for- and for-in/of TDZ rules to match latest spec

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: anba, Assigned: Waldo)

References

Details

(Whiteboard: [v8api])

Expected: ReferenceError thrown when calling the various test* functions
Actual: No ReferenceError thrown


function testForOfRhs() {
  let x = "outer";
  for (let x of [x]) print(x);
}
testForOfRhs();

function testForOfComputed() {
  let x = "outer";
  for (let {[x]: x} of [{outer: 123}]) {
    print(x)
  }
}
testForOfComputed();

function testForInRhs() {
  let x = "outer";
  for (let x in {key: x}) print(x);
}
testForInRhs();

function testForInComputed() {
  let x = "0";
  for (let {[x]: x} in {key: 123}) {
    print(x)
  }
}
testForInComputed();

function testForRhs() {
  let x = "outer";
  for (let x = x;;) {
    print(x);
    break;
  }
}
testForRhs()

function testForComputed() {
  let x = "outer";
  for (let {[x]: x} = {outer: 123};;) {
    print(x);
    break;
  }
}
testForComputed();
Duplicate of this bug: 1135167
Another fun addition I seem to have discovered in reading the semantics for this stuff just now:

  var item;
  for (let x of [function() { x; }])
    item = x;
  // This is a TDZ violation as far as I can tell: |x;| refers to
  // an x in the loop-head, not an x for an iteration of the loop.
  item();

I don't believe this changes the implementability of anything (or at least it seems like it shouldn't, in advance of implementation) -- but it is a rather odd bit of behavior.
Depends on: 1233249
Will see if I can make any progress on this.
Assignee: nobody → winter2718
Assignee: winter2718 → nobody
Duplicate of this bug: 1278150
Whiteboard: [v8api]
I have a PR against the Github repo/branch where bug 1263355 is being worked on, that I believe fixes this.  Don't anybody bother testing it, tho, because there are known cases (e.g. any for-in/of loop with lexical declaration whose body captures one of those lexical declarations) where the PR falls down, because the underlying branch isn't fully completed yet.

https://github.com/syg/gecko-dev/pull/1
Assignee: nobody → jwalden+bmo
Status: NEW → ASSIGNED
Fixed by bug 1263355.
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.