Skip to content

Commit

Permalink
Merge pull request #1118 from cloudflare/jsnell/jsg-completion-api-sq…
Browse files Browse the repository at this point in the history
…l-jsvalue
  • Loading branch information
jasnell authored Sep 5, 2023
2 parents bf79c38 + 78d8f22 commit 6e52fa6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/workerd/api/sql.c++
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ void SqlStorage::Cursor::CachedColumnNames::ensureInitialized(
jsg::Lock& js, SqliteDatabase::Query& source) {
if (names == nullptr) {
js.withinHandleScope([&] {
auto builder = kj::heapArrayBuilder<jsg::V8Ref<v8::String>>(source.columnCount());
auto builder = kj::heapArrayBuilder<jsg::JsRef<jsg::JsString>>(source.columnCount());
for (auto i: kj::zeroTo(builder.capacity())) {
builder.add(js.v8Isolate, jsg::v8StrIntern(js.v8Isolate, source.getColumnName(i)));
builder.add(js, js.str(source.getColumnName(i)));
}
names = builder.finish();
});
Expand Down Expand Up @@ -123,7 +123,7 @@ kj::Maybe<SqlStorage::Cursor::RowDict> SqlStorage::Cursor::rowIteratorNext(
// A little trick here: We know there are no HandleScopes on the stack between JSG and here,
// so we can return a dict keyed by local handles, which avoids constructing new V8Refs here
// which would be relatively slower.
.name = jsg::JsString(names[i].getHandle(js).As<v8::String>()),
.name = names[i].getHandle(js),
.value = kj::mv(value)
};
}).map([&](kj::Array<RowDict::Field>&& fields) {
Expand All @@ -138,7 +138,7 @@ jsg::Ref<SqlStorage::Cursor::RawIterator> SqlStorage::Cursor::raw(jsg::Lock&) {
// Returns the set of column names for the current Cursor. An exception will be thrown if the
// iterator has already been fully consumed. The resulting columns may contain duplicate entries,
// for instance a `SELECT *` across a join of two tables that share a column name.
kj::Array<jsg::V8Ref<v8::String>> SqlStorage::Cursor::getColumnNames(jsg::Lock& js) {
kj::Array<jsg::JsRef<jsg::JsString>> SqlStorage::Cursor::getColumnNames(jsg::Lock& js) {
KJ_IF_MAYBE(s, state) {
cachedColumnNames.ensureInitialized(js, (*s)->query);
return KJ_MAP(name, this->cachedColumnNames.get()) {
Expand Down
6 changes: 3 additions & 3 deletions src/workerd/api/sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SqlStorage::Cursor final: public jsg::Object {
double getRowsRead();
double getRowsWritten();

kj::Array<jsg::V8Ref<v8::String>> getColumnNames(jsg::Lock& js);
kj::Array<jsg::JsRef<jsg::JsString>> getColumnNames(jsg::Lock& js);
JSG_RESOURCE_TYPE(Cursor, CompatibilityFlags::Reader flags) {
JSG_ITERABLE(rows);
JSG_METHOD(raw);
Expand All @@ -126,12 +126,12 @@ class SqlStorage::Cursor final: public jsg::Object {
// TODO(perf): Can we further cache the V8 object layout information for a row?
public:
// Get the cached names. ensureInitialized() must have been called previously.
kj::ArrayPtr<jsg::V8Ref<v8::String>> get() { return KJ_REQUIRE_NONNULL(names); }
kj::ArrayPtr<jsg::JsRef<jsg::JsString>> get() { return KJ_REQUIRE_NONNULL(names); }

void ensureInitialized(jsg::Lock& js, SqliteDatabase::Query& source);

private:
kj::Maybe<kj::Array<jsg::V8Ref<v8::String>>> names;
kj::Maybe<kj::Array<jsg::JsRef<jsg::JsString>>> names;
};

struct State {
Expand Down

0 comments on commit 6e52fa6

Please sign in to comment.