Closed Bug 393306 Opened 17 years ago Closed 17 years ago

add JSClass hook for iteration

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: jorendorff, Assigned: mrbkap)

References

Details

Attachments

(3 files)

Implementing iteration in C is awkward.  One way is to resolve the "__iterator__" property in NewResolve.  See bug 390947, attachment 275918 [details] [diff] [review] for an example of code that tries to do this.

A JSClass hook for iteration would make things more straightforward for the embedder (and in this case, the embedder is Mozilla).
Attached patch WIP (deleted) — Splinter Review
I'm holding off on asking for review until I can test this (and convince hg to generate a diff -w).
Assignee: general → mrbkap
Status: NEW → ASSIGNED
Attached patch jsiter.c -w (deleted) — Splinter Review
These are the jsiter.c changes. I changed the indentation in one place, otherwise this is functionally equivalent.
Attachment #278227 - Flags: review?(brendan)
Comment on attachment 278227 [details] [diff] [review]
WIP

>+            xclasp->iteratorObject(cx, obj, (flags & JSITER_FOREACH) == 0);
. . .
>+(* JS_DLL_CALLBACK JSIteratorOp)(JSContext *cx, JSObject *obj, JSBool foreach);

So either the arg is notforeach, or you want != 0 in the call's third arg.

/be
Oops, yeah.
Actually, I've done this instead:

-(* JS_DLL_CALLBACK JSIteratorOp)(JSContext *cx, JSObject *obj, JSBool foreach);
+(* JS_DLL_CALLBACK JSIteratorOp)(JSContext *cx, JSObject *obj,
+                                 JSBool keysonly);

since it matches __iterator__'s sense.
Comment on attachment 278227 [details] [diff] [review]
WIP

Ok, with that keysonly, r+a=me. Still going to regret this when JS2 iterator support goes in and removes keysonly, but compatibility rules for now.

/be
Attachment #278227 - Flags: review?(brendan)
Attachment #278227 - Flags: review+
Attachment #278227 - Flags: approval1.9+
Blocks: 390947
Attached patch What I'm about to check in (deleted) — Splinter Review
Fix checked into trunk.
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Flags: in-testsuite-
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: