Skip to content

Commit 4652345

Browse files
sqlite: dedupe SQLTagStore prototype instances
Previously all `SQLTagStore` instances had unique prototypes. Note that the class and its prototype are currently not exposed on `node:sqlite`, i.e. it currently can't be directly used for `instanceOf` checks.
1 parent d4d6cc2 commit 4652345

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

src/env_properties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@
439439
V(sqlite_statement_sync_constructor_template, v8::FunctionTemplate) \
440440
V(sqlite_statement_sync_iterator_constructor_template, v8::FunctionTemplate) \
441441
V(sqlite_session_constructor_template, v8::FunctionTemplate) \
442+
V(sqlite_sql_tag_store_constructor_template, v8::FunctionTemplate) \
442443
V(srv_record_template, v8::DictionaryTemplate) \
443444
V(streambaseoutputstream_constructor_template, v8::ObjectTemplate) \
444445
V(tcp_constructor_template, v8::FunctionTemplate) \

src/node_sqlite.cc

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,24 +2856,27 @@ SQLTagStore::SQLTagStore(Environment* env,
28562856
SQLTagStore::~SQLTagStore() {}
28572857

28582858
Local<FunctionTemplate> SQLTagStore::GetConstructorTemplate(Environment* env) {
2859-
Isolate* isolate = env->isolate();
28602859
Local<FunctionTemplate> tmpl =
2861-
NewFunctionTemplate(isolate, IllegalConstructor);
2862-
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "SQLTagStore"));
2863-
tmpl->InstanceTemplate()->SetInternalFieldCount(
2864-
SQLTagStore::kInternalFieldCount);
2865-
SetProtoMethod(isolate, tmpl, "get", Get);
2866-
SetProtoMethod(isolate, tmpl, "all", All);
2867-
SetProtoMethod(isolate, tmpl, "iterate", Iterate);
2868-
SetProtoMethod(isolate, tmpl, "run", Run);
2869-
SetProtoMethod(isolate, tmpl, "clear", Clear);
2870-
SetSideEffectFreeGetter(isolate,
2871-
tmpl,
2872-
FIXED_ONE_BYTE_STRING(isolate, "capacity"),
2873-
CapacityGetter);
2874-
SetSideEffectFreeGetter(
2875-
isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "db"), DatabaseGetter);
2876-
SetSideEffectFreeGetter(isolate, tmpl, env->size_string(), SizeGetter);
2860+
env->sqlite_sql_tag_store_constructor_template();
2861+
if (tmpl.IsEmpty()) {
2862+
Isolate* isolate = env->isolate();
2863+
tmpl = NewFunctionTemplate(isolate, IllegalConstructor);
2864+
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "SQLTagStore"));
2865+
tmpl->InstanceTemplate()->SetInternalFieldCount(
2866+
SQLTagStore::kInternalFieldCount);
2867+
SetProtoMethod(isolate, tmpl, "get", Get);
2868+
SetProtoMethod(isolate, tmpl, "all", All);
2869+
SetProtoMethod(isolate, tmpl, "iterate", Iterate);
2870+
SetProtoMethod(isolate, tmpl, "run", Run);
2871+
SetProtoMethod(isolate, tmpl, "clear", Clear);
2872+
SetSideEffectFreeGetter(isolate,
2873+
tmpl,
2874+
FIXED_ONE_BYTE_STRING(isolate, "capacity"),
2875+
CapacityGetter);
2876+
SetSideEffectFreeGetter(
2877+
isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "db"), DatabaseGetter);
2878+
SetSideEffectFreeGetter(isolate, tmpl, env->size_string(), SizeGetter);
2879+
}
28772880
return tmpl;
28782881
}
28792882

0 commit comments

Comments
 (0)