Closed Bug 410725 Opened 17 years ago Closed 17 years ago

New test for Iterator constructor

Categories

(Rhino Graveyard :: Compiler, defect)

1.7R1
x86
Windows XP
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: norrisboyd, Unassigned)

Details

Attachments

(1 file, 1 obsolete file)

Bob, I created a new test to catch some cases I was missing in Rhino that escaped the regression suite.
Bob, can you take a look at integrating this into the test suite?
where?
Attached file js1_7/geniter/iterator-ctor.js (obsolete) —
Here's the test case (thought I had attached it when I created the bug)
Since it uses uneval, I prefer to put it in extensions although that is kind of mute at the moment since only SpiderMonkey and Rhino support js17 anyway. Would putting the test in extensions work for Rhino?

I went ahead and added this bugnumber to the test, to make it easier to find this bug and added a See devmo.

minor nit: misspelled constructor

nit: you didn't include the description in the reportCompare calls. Apart from their use visually to illustrate the specific test which failed, I use the description to distinguish individual cases when trying to compare results to known failures. In this cases the different calls to reportCompare(true, flag).

SpiderMonkey on the 1.8 and trunk fail the last test.

jstest: js1_7/extensions/iterator-ctor.js bug:  result: FAILED type: shell description: uneval(iteratorToArray(new Iterator(obji,true))) expected: [-1, -2] actual: ["__iterator__", "a", "b"] reason: Expected value '[-1, -2]', Actual value '["__iterator__", "a", "b"]' 


jstest: js1_7/extensions/iterator-ctor.js bug:  result: FAILED type: shell description: uneval(iteratorToArray(new Iterator(obji,true))) flag expected: true actual: -1 reason: Type mismatch, expected type boolean, actual type number Expected value 'true', Actual value '-1' 

I'm not really clear as to the distinction between Iterator(...) and new Iterator(...). Igor, what say you? bug in test or bug in SpiderMonkey?
Attachment #295359 - Attachment is obsolete: true
Attachment #295372 - Flags: review?(igor)
(In reply to comment #4)
> Created an attachment (id=295372) [details]
> js1_7/extensions/iterator-ctor.js
> 
> Since it uses uneval, I prefer to put it in extensions although that is kind of
> mute at the moment since only SpiderMonkey and Rhino support js17 anyway. Would
> putting the test in extensions work for Rhino?

That's fine. The uneval was just a convenient way to compare the resulting arrays against an expected result. Do you have any better way to do the comparison? Like you say, it doesn't really matter much at the moment at least.

> 
> I went ahead and added this bugnumber to the test, to make it easier to find
> this bug and added a See devmo.

Thanks

> 
> minor nit: misspelled constructor
> 
> nit: you didn't include the description in the reportCompare calls. Apart from
> their use visually to illustrate the specific test which failed, I use the
> description to distinguish individual cases when trying to compare results to
> known failures. In this cases the different calls to reportCompare(true, flag).

Thanks, that makes sense. I have to admit that I wish the test framework would just throw an exception that would have line numbers in the stack trace (does SpiderMonkey keep track of that?) but that's a bigger issue :-)

> 
> SpiderMonkey on the 1.8 and trunk fail the last test.
> 
> jstest: js1_7/extensions/iterator-ctor.js bug:  result: FAILED type: shell
> description: uneval(iteratorToArray(new Iterator(obji,true))) expected: [-1,
> -2] actual: ["__iterator__", "a", "b"] reason: Expected value '[-1, -2]',
> Actual value '["__iterator__", "a", "b"]' 
> 
> 
> jstest: js1_7/extensions/iterator-ctor.js bug:  result: FAILED type: shell
> description: uneval(iteratorToArray(new Iterator(obji,true))) flag expected:
> true actual: -1 reason: Type mismatch, expected type boolean, actual type
> number Expected value 'true', Actual value '-1' 

Yes, the SpiderMonkey trunk behavior makes more sense that what I'm testing for here. I thought I did everything compatible with SpiderMonkey but either I made a mistake or SpiderMonkey behavior has changed (I haven't rebuilt SpiderMonkey in some time).

Feel free to check in the test as it works with SpiderMonkey and I'll make Rhino compatible.

> 
> I'm not really clear as to the distinction between Iterator(...) and new
> Iterator(...). Igor, what say you? bug in test or bug in SpiderMonkey?
> 
(In reply to comment #4)
> SpiderMonkey on the 1.8 and trunk fail the last test.
> 
> jstest: js1_7/extensions/iterator-ctor.js bug:  result: FAILED type: shell
> description: uneval(iteratorToArray(new Iterator(obji,true))) expected: [-1,
> -2] actual: ["__iterator__", "a", "b"] reason: Expected value '[-1, -2]',
> Actual value '["__iterator__", "a", "b"]' 
> 
> 
> jstest: js1_7/extensions/iterator-ctor.js bug:  result: FAILED type: shell
> description: uneval(iteratorToArray(new Iterator(obji,true))) flag expected:
> true actual: -1 reason: Type mismatch, expected type boolean, actual type
> number Expected value 'true', Actual value '-1' 
> 
> I'm not really clear as to the distinction between Iterator(...) and new
> Iterator(...). Igor, what say you? bug in test or bug in SpiderMonkey?

new Iterator(obj, flag) always constructs a default iterator that iterates over the properties of the object obj and returns a sequence of property keys (flag is true) or a sequence of [key, value] pair (flag is false). There is no lookup of __iterator__ method here. As such the test case is wrong and ["__iterator__", "a", "b"] is the correct result as obji contains these 3 properties. 

Iterator(obj, flag) is a converter to iterator. The call *looks* for __iterator__ property and is roughly equivalent to the following:

let (iter = obj.__iterator__) iter ? iter.call(obj, flag) : new Iterator(obj, flag)

except it properly deals with XML objects and has a special support for native objects that provides own implementation of the iterator protocol.
Thanks Igor!

/cvsroot/mozilla/js/tests/js1_7/extensions/iterator-ctor.js,v  <--  iterator-ctor.js
initial revision: 1.1
Status: NEW → RESOLVED
Closed: 17 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Attachment #295372 - Flags: review?(igor)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: