sqlite: make `SQLTagStore.prototype.size` a getter · nodejs/node@9d993be
@@ -2700,11 +2700,13 @@ Local<FunctionTemplate> SQLTagStore::GetConstructorTemplate(Environment* env) {
27002700SetProtoMethod(isolate, tmpl, "iterate", Iterate);
27012701SetProtoMethod(isolate, tmpl, "run", Run);
27022702SetProtoMethod(isolate, tmpl, "clear", Clear);
2703-SetProtoMethod(isolate, tmpl, "size", Size);
2704-SetSideEffectFreeGetter(
2705- isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "capacity"), Capacity);
2703+SetSideEffectFreeGetter(isolate,
2704+ tmpl,
2705+FIXED_ONE_BYTE_STRING(isolate, "capacity"),
2706+ CapacityGetter);
27062707SetSideEffectFreeGetter(
27072708 isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "db"), DatabaseGetter);
2709+SetSideEffectFreeGetter(isolate, tmpl, env->size_string(), SizeGetter);
27082710return tmpl;
27092711}
27102712@@ -2720,32 +2722,44 @@ BaseObjectPtr<SQLTagStore> SQLTagStore::Create(
27202722return MakeBaseObject<SQLTagStore>(env, obj, std::move(database), capacity);
27212723}
272227242725+void SQLTagStore::CapacityGetter(const FunctionCallbackInfo<Value>& args) {
2726+ SQLTagStore* store;
2727+ASSIGN_OR_RETURN_UNWRAP(&store, args.This());
2728+ args.GetReturnValue().Set(static_cast<double>(store->sql_tags_.Capacity()));
2729+}
2730+27232731void SQLTagStore::DatabaseGetter(const FunctionCallbackInfo<Value>& args) {
27242732 SQLTagStore* store;
27252733ASSIGN_OR_RETURN_UNWRAP(&store, args.This());
27262734 args.GetReturnValue().Set(store->database_->object());
27272735}
272827362729-void SQLTagStore::Run(const FunctionCallbackInfo<Value>& info) {
2737+void SQLTagStore::SizeGetter(const FunctionCallbackInfo<Value>& args) {
2738+ SQLTagStore* store;
2739+ASSIGN_OR_RETURN_UNWRAP(&store, args.This());
2740+ args.GetReturnValue().Set(static_cast<double>(store->sql_tags_.Size()));
2741+}
2742+2743+void SQLTagStore::Run(const FunctionCallbackInfo<Value>& args) {
27302744 SQLTagStore* session;
2731-ASSIGN_OR_RETURN_UNWRAP(&session, info.This());
2732- Environment* env = Environment::GetCurrent(info);
2745+ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
2746+ Environment* env = Environment::GetCurrent(args);
2733274727342748THROW_AND_RETURN_ON_BAD_STATE(
27352749 env, !session->database_->IsOpen(), "database is not open");
273627502737- BaseObjectPtr<StatementSync> stmt = PrepareStatement(info);
2751+ BaseObjectPtr<StatementSync> stmt = PrepareStatement(args);
2738275227392753if (!stmt) {
27402754return;
27412755 }
274227562743-uint32_t n_params = info.Length() - 1;
2757+uint32_t n_params = args.Length() - 1;
27442758int r = sqlite3_reset(stmt->statement_);
27452759CHECK_ERROR_OR_THROW(env->isolate(), stmt->db_.get(), r, SQLITE_OK, void());
27462760int param_count = sqlite3_bind_parameter_count(stmt->statement_);
27472761for (int i = 0; i < static_cast<int>(n_params) && i < param_count; ++i) {
2748- Local<Value> value = info[i + 1];
2762+ Local<Value> value = args[i + 1];
27492763if (!stmt->BindValue(value, i + 1)) {
27502764return;
27512765 }
@@ -2755,7 +2769,7 @@ void SQLTagStore::Run(const FunctionCallbackInfo<Value>& info) {
27552769if (StatementExecutionHelper::Run(
27562770 env, stmt->db_.get(), stmt->statement_, stmt->use_big_ints_)
27572771 .ToLocal(&result)) {
2758-info.GetReturnValue().Set(result);
2772+args.GetReturnValue().Set(result);
27592773 }
27602774}
27612775@@ -2873,23 +2887,9 @@ void SQLTagStore::All(const FunctionCallbackInfo<Value>& args) {
28732887 }
28742888}
287528892876-void SQLTagStore::Size(const FunctionCallbackInfo<Value>& info) {
2890+void SQLTagStore::Clear(const FunctionCallbackInfo<Value>& args) {
28772891 SQLTagStore* store;
2878-ASSIGN_OR_RETURN_UNWRAP(&store, info.This());
2879- info.GetReturnValue().Set(
2880-Integer::New(info.GetIsolate(), store->sql_tags_.Size()));
2881-}
2882-2883-void SQLTagStore::Capacity(const FunctionCallbackInfo<Value>& info) {
2884- SQLTagStore* store;
2885-ASSIGN_OR_RETURN_UNWRAP(&store, info.This());
2886- info.GetReturnValue().Set(
2887-Integer::New(info.GetIsolate(), store->sql_tags_.Capacity()));
2888-}
2889-2890-void SQLTagStore::Clear(const FunctionCallbackInfo<Value>& info) {
2891- SQLTagStore* store;
2892-ASSIGN_OR_RETURN_UNWRAP(&store, info.This());
2892+ASSIGN_OR_RETURN_UNWRAP(&store, args.This());
28932893 store->sql_tags_.Clear();
28942894}
28952895