Closed Bug 394345 Opened 17 years ago Closed 5 years ago

JavaScript strict: document.chicken === 'something' should not trigger "reference to undefined property" warning

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: docwhat, Unassigned)

References

Details

Hello! Great work on Firefox, I really appreciate your hard work! What happens: Enable 'javascript.options.strict' and execute the following JavaScript: if (document.chicken === 'something') { alert('Those are some chickens.'); } The Error Console will spit out: reference to undefined property document.chicken http://chicken.powered.mozilla.org/strict.html Line 8 What I expected: This should not produce a warning. It's a legit check to see if it exists. document.chicken === undefined, undefined !== 'something', so there should be no problems. The only time accessing a non-existent attribute/property is if you are calling a function (document.chicken();) or if it is on the RHS of an assignment (var poultry = document.chicken;). A related case to this is if the javascript code read: if (document.chicken.feet === 'something') { alert('Those are some chicken feet.'); } I would argue that this isn't an warning either, since document.chicken.feet is undefined, too. Ciao!
Summary: JavaScript strict: document.chicken === 'something' should not be a warning. → JavaScript strict: document.chicken === 'something' should not trigger "reference to undefined property" warning
There seems to be a thin line between what the JS engine considers "object detection" (e.g. !a.b, typeof a.b) and what it warns about. See bug 332299, for example.
Blocks: 296661
Assignee: general → nobody
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.