| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b1770bc commit 5cb78ed
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1076,10 +1076,23 @@ void DatabaseSync::CreateTagStore(const FunctionCallbackInfo<Value>& args) { | |||
| 1076 | 1076 | return; | |
| 1077 | 1077 | } | |
| 1078 | 1078 | int capacity = 1000; | |
| 1079 | - if (args.Length() > 0 && args[0]->IsNumber()) { | ||
| 1080 | - capacity = args[0].As<Number>()->Value(); | ||
| 1079 | + if (args.Length() > 0 && !args[0]->IsUndefined()) { | ||
| 1080 | + if (!args[0]->IsNumber()) { | ||
| 1081 | + THROW_ERR_INVALID_ARG_TYPE( | ||
| 1082 | + env->isolate(), | ||
| 1083 | + "The \"maxSize\" argument must be a positive integer."); | ||
| 1084 | + return; | ||
| 1085 | + } | ||
| 1086 | + double val = args[0].As<Number>()->Value(); | ||
| 1087 | + if (std::floor(val) != val || val <= 0 || | ||
| 1088 | + val > std::numeric_limits<int>::max()) { | ||
| 1089 | + THROW_ERR_OUT_OF_RANGE( | ||
| 1090 | + env->isolate(), | ||
| 1091 | + "The \"maxSize\" argument must be a positive integer."); | ||
| 1092 | + return; | ||
| 1093 | + } | ||
| 1094 | + capacity = static_cast<int>(val); | ||
| 1081 | 1095 | } | |
| 1082 | - | ||
| 1083 | 1096 | BaseObjectPtr<SQLTagStore> session = | |
| 1084 | 1097 | SQLTagStore::Create(env, BaseObjectWeakPtr<DatabaseSync>(db), capacity); | |
| 1085 | 1098 | if (!session) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -257,6 +257,40 @@ test('a finished iterator stays done and does not restart', () => { | |||
| 257 | 257 | assert.strictEqual(iter.next().done, true); | |
| 258 | 258 | }); | |
| 259 | 259 | ||
| 260 | + test('createTagStore throws on invalid maxSize', () => { | ||
| 261 | + const db = new DatabaseSync(':memory:'); | ||
| 262 | + | ||
| 263 | + assert.throws(() => db.createTagStore(0), { | ||
| 264 | + code: 'ERR_OUT_OF_RANGE', | ||
| 265 | + message: /maxSize/, | ||
| 266 | + }); | ||
| 267 | + | ||
| 268 | + assert.throws(() => db.createTagStore(-1), { | ||
| 269 | + code: 'ERR_OUT_OF_RANGE', | ||
| 270 | + message: /maxSize/, | ||
| 271 | + }); | ||
| 272 | + | ||
| 273 | + assert.throws(() => db.createTagStore(NaN), { | ||
| 274 | + code: 'ERR_OUT_OF_RANGE', | ||
| 275 | + message: /maxSize/, | ||
| 276 | + }); | ||
| 277 | + | ||
| 278 | + assert.throws(() => db.createTagStore(1.5), { | ||
| 279 | + code: 'ERR_OUT_OF_RANGE', | ||
| 280 | + message: /maxSize/, | ||
| 281 | + }); | ||
| 282 | + | ||
| 283 | + assert.throws(() => db.createTagStore('abc'), { | ||
| 284 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 285 | + message: /maxSize/, | ||
| 286 | + }); | ||
| 287 | + | ||
| 288 | + assert.throws(() => db.createTagStore(Number.MAX_SAFE_INTEGER), { | ||
| 289 | + code: 'ERR_OUT_OF_RANGE', | ||
| 290 | + message: /maxSize/, | ||
| 291 | + }); | ||
| 292 | + }); | ||
| 293 | + | ||
| 260 | 294 | test('sql.db returns the associated DatabaseSync instance', () => { | |
| 261 | 295 | assert.strictEqual(sql.db, db); | |
| 262 | 296 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments