New test for Iterator constructor

RESOLVED FIXED

Status

Rhino
Compiler
RESOLVED FIXED
11 years ago
11 years ago

People

(Reporter: Norris Boyd, Unassigned)

Tracking

1.7R1
x86
Windows XP
Bug Flags:
in-testsuite +

Details

Attachments

(1 attachment, 1 obsolete attachment)

5.22 KB, application/javascript
Details
(Reporter)

Description

11 years ago
Bob, I created a new test to catch some cases I was missing in Rhino that escaped the regression suite.
(Reporter)

Comment 1

11 years ago
Bob, can you take a look at integrating this into the test suite?

Comment 2

11 years ago
where?
(Reporter)

Comment 3

11 years ago
Created attachment 295359 [details]
js1_7/geniter/iterator-ctor.js

Here's the test case (thought I had attached it when I created the bug)

Comment 4

11 years ago
Created attachment 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?

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)
(Reporter)

Comment 5

11 years ago
(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?
> 

Comment 6

11 years ago
(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.

Comment 7

11 years ago
Thanks Igor!

/cvsroot/mozilla/js/tests/js1_7/extensions/iterator-ctor.js,v  <--  iterator-ctor.js
initial revision: 1.1
Status: NEW → RESOLVED
Last Resolved: 11 years ago
Flags: in-testsuite+
Resolution: --- → FIXED

Updated

11 years ago
Attachment #295372 - Flags: review?(igor)
You need to log in before you can comment on or make changes to this bug.