Skip to content

Add Iterator.from#555

Merged
bnoordhuis merged 1 commit intoquickjs-ng:masterfrom
bnoordhuis:Iterator.from
Sep 26, 2024
Merged

Add Iterator.from#555
bnoordhuis merged 1 commit intoquickjs-ng:masterfrom
bnoordhuis:Iterator.from

Conversation

@bnoordhuis
Copy link
Copy Markdown
Contributor

No description provided.

method = JS_GetProperty(ctx, obj, JS_ATOM_next);
if (JS_IsException(method))
return JS_EXCEPTION;
// honestly kind of ghetto but avoids having to
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what you are doing here. Care to satify my curiosity? :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec requires that you return a wrapped iterator and I accomplish that by basically doing:

var inner = /* ... */
var outer = { __proto__: Iterator.prototype, next: inner.next.bind(inner) }
return outer

The responsible-adult solution would probably involve an additional class with internal fields for inner and inner.next, custom mark and finalize functions, etc. This was less work :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks!

@bnoordhuis bnoordhuis merged commit 348d609 into quickjs-ng:master Sep 26, 2024
@bnoordhuis bnoordhuis deleted the Iterator.from branch September 26, 2024 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants