Open Bug 1603915 Opened 6 years ago Updated 1 year ago

Wrong error type for arr[i]++ if arr is null and i is nonexistent, due to checking for null/undefined too soon

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

People

(Reporter: jorendorff, Unassigned)

References

(Blocks 1 open bug, )

Details

$ es6draft
js> arr = null; arr[i]++;
uncaught exception: ReferenceError: cannot resolve reference: "i"

$ js
js> arr = null; arr[i]++;
typein:1:13 TypeError: arr is null

Which is right, TypeError or ReferenceError?

I think ReferenceError is right, and we can fix this by deleting these lines.

Summary: Incrementing array element tests for null/undefined too soon → Wrong error type for arr[i]++ if arr is null and i is nonexistent, due to checking for null/undefined too soon
Priority: -- → P3

Deleting these lines should result in null[{toString(){print("hello"); return 0}}]++ printing "hello", which is also a spec violation. See bug 1286997.

I think we're still, more or less, waiting for a decision on https://github.com/tc39/ecma262/issues/467. So either all engines try to implement the specification (*) or the spec should be changed to match the engines (**).


(*) Where it's not entirely clear if the current spec should be implemented or some parts of the spec should first be changed, so it's easier to implement the reference semantics correctly.
(**) This requires to find some common ground first, because there are small differences across the engines for certain edge cases.

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.