Skip to content

Commit 5d64e3d

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 2e66b8c commit 5d64e3d

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
@@ -441,6 +441,7 @@
441441
V(sqlite_statement_sync_constructor_template, v8::FunctionTemplate) \
442442
V(sqlite_statement_sync_iterator_constructor_template, v8::FunctionTemplate) \
443443
V(sqlite_session_constructor_template, v8::FunctionTemplate) \
444+
V(sqlite_sql_tag_store_constructor_template, v8::FunctionTemplate) \
444445
V(srv_record_template, v8::DictionaryTemplate) \
445446
V(streambaseoutputstream_constructor_template, v8::ObjectTemplate) \
446447
V(tcp_constructor_template, v8::FunctionTemplate) \

src/node_sqlite.cc

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

31303130
Local<FunctionTemplate> SQLTagStore::GetConstructorTemplate(Environment* env) {
3131-
Isolate* isolate = env->isolate();
31323131
Local<FunctionTemplate> tmpl =
3133-
NewFunctionTemplate(isolate, IllegalConstructor);
3134-
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "SQLTagStore"));
3135-
tmpl->InstanceTemplate()->SetInternalFieldCount(
3136-
SQLTagStore::kInternalFieldCount);
3137-
SetProtoMethod(isolate, tmpl, "get", Get);
3138-
SetProtoMethod(isolate, tmpl, "all", All);
3139-
SetProtoMethod(isolate, tmpl, "iterate", Iterate);
3140-
SetProtoMethod(isolate, tmpl, "run", Run);
3141-
SetProtoMethod(isolate, tmpl, "clear", Clear);
3142-
SetSideEffectFreeGetter(isolate,
3143-
tmpl,
3144-
FIXED_ONE_BYTE_STRING(isolate, "capacity"),
3145-
CapacityGetter);
3146-
SetSideEffectFreeGetter(
3147-
isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "db"), DatabaseGetter);
3148-
SetSideEffectFreeGetter(isolate, tmpl, env->size_string(), SizeGetter);
3132+
env->sqlite_sql_tag_store_constructor_template();
3133+
if (tmpl.IsEmpty()) {
3134+
Isolate* isolate = env->isolate();
3135+
tmpl = NewFunctionTemplate(isolate, IllegalConstructor);
3136+
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "SQLTagStore"));
3137+
tmpl->InstanceTemplate()->SetInternalFieldCount(
3138+
SQLTagStore::kInternalFieldCount);
3139+
SetProtoMethod(isolate, tmpl, "get", Get);
3140+
SetProtoMethod(isolate, tmpl, "all", All);
3141+
SetProtoMethod(isolate, tmpl, "iterate", Iterate);
3142+
SetProtoMethod(isolate, tmpl, "run", Run);
3143+
SetProtoMethod(isolate, tmpl, "clear", Clear);
3144+
SetSideEffectFreeGetter(isolate,
3145+
tmpl,
3146+
FIXED_ONE_BYTE_STRING(isolate, "capacity"),
3147+
CapacityGetter);
3148+
SetSideEffectFreeGetter(
3149+
isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "db"), DatabaseGetter);
3150+
SetSideEffectFreeGetter(isolate, tmpl, env->size_string(), SizeGetter);
3151+
}
31493152
return tmpl;
31503153
}
31513154

0 commit comments

Comments
 (0)