Closed Bug 121744 Opened 23 years ago Closed 23 years ago

JS should error on |for(i in undefined)|, |for(i in null)|

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: pschwartau, Assigned: khanson)

Details

(Keywords: js1.5)

Attachments

(1 file)

Reported by gonzalom@docent.com and nboyd@atg.com: 

JS should throw TypeError exceptions on the statements |for(i in undefined)|, 
|for(i in null)|. Why? From the ECMA-262 3rd Edition Final:


12.6.4 The for-in Statement

The production 
IterationStatement : for ( LeftHandSideExpression in Expression ) Statement
is evaluated as follows:

1. Evaluate the Expression.
2. Call GetValue(Result(1)).
3. Call ToObject(Result(2)).
...

9.9 ToObject

Input Type : Result
Undefined  : Throw a TypeError exception.
Null       : Throw a TypeError exception.
... 


Currently, SpiderMonkey does not error on either statement:

js> for (var i in undefined) {print(i);}
js>
js> for (var i in null) {print(i);}
js>
Keywords: js1.5
Comment on attachment 66477 [details] [diff] [review]
fix, too easy

Looks fine from over here, unless we want to condition the error on ECMAness.

r=shaver
Attachment #66477 - Flags: review+
Kenton, can you review?  shaver, how about I take your r= as sr=?

/be
Comment on attachment 66477 [details] [diff] [review]
fix, too easy

r=khanson

Works for me.

=Kenton=
Testcase added to JS testsuite:

        mozilla/js/tests/ecma_3/Statements/regress-121744.js

Currently passing in Rhino.
Currently failing in SpiderMonkey (before patch).
Comment on attachment 66477 [details] [diff] [review]
fix, too easy

sr=shaver, sure.
Attachment #66477 - Flags: superreview+
Fixed.

/be
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Marking Verified FIXED. The above testcase now passes in the 
debug/optimized SpiderMonkey shell on WinNT, Linux, Mac9.1.
Status: RESOLVED → VERIFIED
Comment on attachment 66477 [details] [diff] [review]
fix, too easy

a=asa (on behalf of drivers) for checkin to the 1.0 branch
Attachment #66477 - Flags: approval+
Flags: testcase+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: