Skip to content

Commit

Permalink
fix: js iterate method wrap Iterate into a Iterator.from
Browse files Browse the repository at this point in the history
I did not found how to produce an iterator extending Iterator with v8.
So I've done this part in js side.
  • Loading branch information
tpoisseau committed Aug 5, 2024
1 parent 11190c6 commit 16e00d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ const { emitExperimentalWarning } = require('internal/util');

emitExperimentalWarning('SQLite');
module.exports = internalBinding('sqlite');

const statementIterate = module.exports.StatementSync.prototype.iterate;
module.exports.StatementSync.prototype.iterate = function iterate() {
return Iterator.from(statementIterate.apply(this, arguments));
}
8 changes: 4 additions & 4 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,12 @@ void StatementSync::Iterate(const FunctionCallbackInfo<Value>& args) {
v8::External::New(isolate, captureContext)
);

iterableIteratorTemplate->Set(String::NewFromUtf8Literal(isolate, "next"), nextFuncTemplate);
iterableIteratorTemplate->Set(
String::NewFromUtf8Literal(isolate, "next"),
nextFuncTemplate
);

auto iterableIterator = iterableIteratorTemplate->NewInstance(context).ToLocalChecked();
auto JSIteratorPrototype = context->Global()->Get(context, String::NewFromUtf8Literal(isolate, "Iterator.prototype")).ToLocalChecked();
iterableIterator->SetPrototype(context, JSIteratorPrototype).Check();

args.GetReturnValue().Set(iterableIterator);
}

Expand Down

0 comments on commit 16e00d0

Please sign in to comment.