Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Iterator.from #555

Merged
merged 1 commit into from
Sep 26, 2024
Merged

Add Iterator.from #555

merged 1 commit into from
Sep 26, 2024

Conversation

bnoordhuis
Copy link
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
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
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
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
52 checks passed
@bnoordhuis bnoordhuis deleted the Iterator.from branch September 26, 2024 22:16
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants