Commit 510d84c330e for nodejs
commit 510d84c330e8e7d2bb8699608163024baf54eaa6
Author: Guilherme Araújo <arauujogui@gmail.com>
Date: Tue Oct 20 22:53:03 2026 -0300
sqlite: cache the SQLTagStore constructor template
Store the template on the environment like the other sqlite classes,
so stores no longer get a fresh template and prototype each time.
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66912
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
diff --git a/src/env_properties.h b/src/env_properties.h
index c4e3bc5c72a..9f634ec13f9 100644
--- a/src/env_properties.h
+++ b/src/env_properties.h
@@ -457,6 +457,7 @@
V(sqlite_statement_sync_constructor_template, v8::FunctionTemplate) \
V(sqlite_statement_sync_iterator_constructor_template, v8::FunctionTemplate) \
V(sqlite_session_constructor_template, v8::FunctionTemplate) \
+ V(sqlite_tag_store_constructor_template, v8::FunctionTemplate) \
V(srv_record_template, v8::DictionaryTemplate) \
V(streambaseoutputstream_constructor_template, v8::ObjectTemplate) \
V(tcp_constructor_template, v8::FunctionTemplate) \
diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc
index 71cc49c09fe..2bf67b97689 100644
--- a/src/node_sqlite.cc
+++ b/src/node_sqlite.cc
@@ -4353,24 +4353,27 @@ static inline void SetSideEffectFreeGetter(
SQLTagStore::~SQLTagStore() {}
Local<FunctionTemplate> SQLTagStore::GetConstructorTemplate(Environment* env) {
- Isolate* isolate = env->isolate();
- Local<FunctionTemplate> tmpl =
- NewFunctionTemplate(isolate, IllegalConstructor);
- tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "SQLTagStore"));
- tmpl->InstanceTemplate()->SetInternalFieldCount(
- SQLTagStore::kInternalFieldCount);
- SetProtoMethod(isolate, tmpl, "get", Get);
- SetProtoMethod(isolate, tmpl, "all", All);
- SetProtoMethod(isolate, tmpl, "iterate", Iterate);
- SetProtoMethod(isolate, tmpl, "run", Run);
- SetProtoMethod(isolate, tmpl, "clear", Clear);
- SetSideEffectFreeGetter(isolate,
- tmpl,
- FIXED_ONE_BYTE_STRING(isolate, "capacity"),
- CapacityGetter);
- SetSideEffectFreeGetter(
- isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "db"), DatabaseGetter);
- SetSideEffectFreeGetter(isolate, tmpl, env->size_string(), SizeGetter);
+ Local<FunctionTemplate> tmpl = env->sqlite_tag_store_constructor_template();
+ if (tmpl.IsEmpty()) {
+ Isolate* isolate = env->isolate();
+ tmpl = NewFunctionTemplate(isolate, IllegalConstructor);
+ tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "SQLTagStore"));
+ tmpl->InstanceTemplate()->SetInternalFieldCount(
+ SQLTagStore::kInternalFieldCount);
+ SetProtoMethod(isolate, tmpl, "get", Get);
+ SetProtoMethod(isolate, tmpl, "all", All);
+ SetProtoMethod(isolate, tmpl, "iterate", Iterate);
+ SetProtoMethod(isolate, tmpl, "run", Run);
+ SetProtoMethod(isolate, tmpl, "clear", Clear);
+ SetSideEffectFreeGetter(isolate,
+ tmpl,
+ FIXED_ONE_BYTE_STRING(isolate, "capacity"),
+ CapacityGetter);
+ SetSideEffectFreeGetter(
+ isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "db"), DatabaseGetter);
+ SetSideEffectFreeGetter(isolate, tmpl, env->size_string(), SizeGetter);
+ env->set_sqlite_tag_store_constructor_template(tmpl);
+ }
return tmpl;
}
diff --git a/test/parallel/test-sqlite-template-tag.js b/test/parallel/test-sqlite-template-tag.js
index f7a5053a330..5ecf055523f 100644
--- a/test/parallel/test-sqlite-template-tag.js
+++ b/test/parallel/test-sqlite-template-tag.js
@@ -295,6 +295,12 @@ test('sql.db returns the associated Database instance', () => {
assert.strictEqual(sql.db, db);
});
+test('tag stores share a prototype', () => {
+ const other = new Database(':memory:').createTagStore();
+ assert.strictEqual(Object.getPrototypeOf(other), Object.getPrototypeOf(sql));
+ assert.strictEqual(other.constructor, sql.constructor);
+});
+
test('sql error messages are descriptive', () => {
assert.strictEqual(sql.run`INSERT INTO foo (text) VALUES (${'test'})`.changes, 1);