Skip to content

Commit ae3ca8c

Browse files
committed
fixup! src: fixup lint issues after dictionary template change
1 parent 1defd82 commit ae3ca8c

File tree

5 files changed

+87
-51
lines changed

5 files changed

+87
-51
lines changed

src/node_sqlite.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace {
124124
Local<DictionaryTemplate> getLazyIterTemplate(Environment* env) {
125125
auto iter_template = env->iter_template();
126126
if (iter_template.IsEmpty()) {
127-
std::string_view iter_keys[] = {"done", "value"};
127+
static constexpr std::string_view iter_keys[] = {"done", "value"};
128128
iter_template = DictionaryTemplate::New(env->isolate(), iter_keys);
129129
env->set_iter_template(iter_template);
130130
}
@@ -2254,7 +2254,7 @@ void StatementSync::Columns(const FunctionCallbackInfo<Value>& args) {
22542254
LocalVector<Value> cols(isolate);
22552255
auto sqlite_column_template = env->sqlite_column_template();
22562256
if (sqlite_column_template.IsEmpty()) {
2257-
std::string_view col_keys[] = {
2257+
static constexpr std::string_view col_keys[] = {
22582258
"column", "database", "name", "table", "type"};
22592259
sqlite_column_template = DictionaryTemplate::New(isolate, col_keys);
22602260
env->set_sqlite_column_template(sqlite_column_template);

src/node_url_pattern.cc

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ MaybeLocal<Value> URLPattern::URLPatternResult::ToJSValue(
399399

400400
auto tmpl = env->urlpatternresult_template();
401401
if (tmpl.IsEmpty()) {
402-
std::string_view namesVec[] = {
402+
static constexpr std::string_view namesVec[] = {
403403
"inputs",
404404
"protocol",
405405
"username",
@@ -417,29 +417,59 @@ MaybeLocal<Value> URLPattern::URLPatternResult::ToJSValue(
417417
size_t index = 0;
418418
auto context = isolate->GetCurrentContext();
419419

420+
// We are using a DictionaryTemplate to create the URLPatternResult
421+
// object. We want to make sure that the properties are created without
422+
// errors before we call NewInstance, and bail out early if any fail.
423+
424+
v8::Local<v8::Array> inputs;
425+
if (!Array::New(context,
426+
result.inputs.size(),
427+
[&index, &inputs = result.inputs, env]() {
428+
auto& input = inputs[index++];
429+
if (std::holds_alternative<std::string_view>(input)) {
430+
auto input_str = std::get<std::string_view>(input);
431+
return ToV8Value(env->context(), input_str);
432+
} else {
433+
DCHECK(
434+
std::holds_alternative<ada::url_pattern_init>(input));
435+
auto init = std::get<ada::url_pattern_init>(input);
436+
return URLPatternInit::ToJsObject(env, init);
437+
}
438+
})
439+
.ToLocal(&inputs)) {
440+
return {};
441+
}
442+
443+
Local<Object> results[8];
444+
if (!URLPatternComponentResult::ToJSObject(env, result.protocol)
445+
.ToLocal(&results[0]) ||
446+
!URLPatternComponentResult::ToJSObject(env, result.username)
447+
.ToLocal(&results[1]) ||
448+
!URLPatternComponentResult::ToJSObject(env, result.password)
449+
.ToLocal(&results[2]) ||
450+
!URLPatternComponentResult::ToJSObject(env, result.hostname)
451+
.ToLocal(&results[3]) ||
452+
!URLPatternComponentResult::ToJSObject(env, result.port)
453+
.ToLocal(&results[4]) ||
454+
!URLPatternComponentResult::ToJSObject(env, result.pathname)
455+
.ToLocal(&results[5]) ||
456+
!URLPatternComponentResult::ToJSObject(env, result.search)
457+
.ToLocal(&results[6]) ||
458+
!URLPatternComponentResult::ToJSObject(env, result.hash)
459+
.ToLocal(&results[7])) {
460+
return {};
461+
}
462+
420463
MaybeLocal<Value> vals[] = {
421-
Array::New(context,
422-
result.inputs.size(),
423-
[&index, &inputs = result.inputs, env]() {
424-
auto& input = inputs[index++];
425-
if (std::holds_alternative<std::string_view>(input)) {
426-
auto input_str = std::get<std::string_view>(input);
427-
return ToV8Value(env->context(), input_str);
428-
} else {
429-
DCHECK(
430-
std::holds_alternative<ada::url_pattern_init>(input));
431-
auto init = std::get<ada::url_pattern_init>(input);
432-
return URLPatternInit::ToJsObject(env, init);
433-
}
434-
}),
435-
URLPatternComponentResult::ToJSObject(env, result.protocol),
436-
URLPatternComponentResult::ToJSObject(env, result.username),
437-
URLPatternComponentResult::ToJSObject(env, result.password),
438-
URLPatternComponentResult::ToJSObject(env, result.hostname),
439-
URLPatternComponentResult::ToJSObject(env, result.port),
440-
URLPatternComponentResult::ToJSObject(env, result.pathname),
441-
URLPatternComponentResult::ToJSObject(env, result.search),
442-
URLPatternComponentResult::ToJSObject(env, result.hash),
464+
inputs,
465+
results[0], /** protocol */
466+
results[1], /** username */
467+
results[2], /** password */
468+
results[3], /** hostname */
469+
results[4], /** port */
470+
results[5], /** pathname */
471+
results[6], /** search */
472+
results[7], /** hash */
443473
};
444474
return tmpl->NewInstance(env->context(), vals);
445475
}

src/node_util.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,14 @@ static void GetCallSites(const FunctionCallbackInfo<Value>& args) {
267267

268268
auto callsite_template = env->callsite_template();
269269
if (callsite_template.IsEmpty()) {
270-
std::string_view names[] = {"functionName",
271-
"scriptId",
272-
"scriptName",
273-
"lineNumber",
274-
"columnNumber",
275-
// TODO(legendecas): deprecate CallSite.column.
276-
"column"};
270+
static constexpr std::string_view names[] = {
271+
"functionName",
272+
"scriptId",
273+
"scriptName",
274+
"lineNumber",
275+
"columnNumber",
276+
// TODO(legendecas): deprecate CallSite.column.
277+
"column"};
277278
callsite_template = DictionaryTemplate::New(isolate, names);
278279
env->set_callsite_template(callsite_template);
279280
}

src/node_v8.cc

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,18 @@ static MaybeLocal<Object> ConvertHeapStatsToJSObject(
337337
auto space_stats_tmpl = env->space_stats_template();
338338
auto heap_stats_tmpl = env->v8_heap_statistics_template();
339339
if (object_stats_template.IsEmpty()) {
340-
std::string_view object_stats_names[] = {"allocated_bytes", "object_count"};
340+
static constexpr std::string_view object_stats_names[] = {"allocated_bytes",
341+
"object_count"};
341342
object_stats_template =
342343
DictionaryTemplate::New(isolate, object_stats_names);
343344
env->set_object_stats_template(object_stats_template);
344345
}
345346
if (page_stats_tmpl.IsEmpty()) {
346-
std::string_view page_stats_names[] = {"committed_size_bytes",
347-
"resident_size_bytes",
348-
"used_size_bytes",
349-
"object_statistics"};
347+
static constexpr std::string_view page_stats_names[] = {
348+
"committed_size_bytes",
349+
"resident_size_bytes",
350+
"used_size_bytes",
351+
"object_statistics"};
350352
page_stats_tmpl = DictionaryTemplate::New(isolate, page_stats_names);
351353
env->set_page_stats_template(page_stats_tmpl);
352354
}
@@ -358,21 +360,23 @@ static MaybeLocal<Object> ConvertHeapStatsToJSObject(
358360
env->set_free_list_statistics_template(free_list_statistics_template);
359361
}
360362
if (space_stats_tmpl.IsEmpty()) {
361-
std::string_view space_stats_names[] = {"name",
362-
"committed_size_bytes",
363-
"resident_size_bytes",
364-
"used_size_bytes",
365-
"page_stats",
366-
"free_list_stats"};
363+
static constexpr std::string_view space_stats_names[] = {
364+
"name",
365+
"committed_size_bytes",
366+
"resident_size_bytes",
367+
"used_size_bytes",
368+
"page_stats",
369+
"free_list_stats"};
367370
space_stats_tmpl = DictionaryTemplate::New(isolate, space_stats_names);
368371
env->set_space_stats_template(space_stats_tmpl);
369372
}
370373
if (heap_stats_tmpl.IsEmpty()) {
371-
std::string_view heap_statistics_names[] = {"committed_size_bytes",
372-
"resident_size_bytes",
373-
"used_size_bytes",
374-
"space_statistics",
375-
"type_names"};
374+
static constexpr std::string_view heap_statistics_names[] = {
375+
"committed_size_bytes",
376+
"resident_size_bytes",
377+
"used_size_bytes",
378+
"space_statistics",
379+
"type_names"};
376380
heap_stats_tmpl = DictionaryTemplate::New(isolate, heap_statistics_names);
377381
env->set_v8_heap_statistics_template(heap_stats_tmpl);
378382
}

src/node_worker.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ using v8::Float64Array;
3232
using v8::FunctionCallbackInfo;
3333
using v8::FunctionTemplate;
3434
using v8::HandleScope;
35+
using v8::HeapStatistics;
3536
using v8::Integer;
3637
using v8::Isolate;
3738
using v8::Local;
@@ -877,7 +878,7 @@ void Worker::CpuUsage(const FunctionCallbackInfo<Value>& args) {
877878
} else {
878879
auto tmpl = env->cpu_usage_template();
879880
if (tmpl.IsEmpty()) {
880-
std::string_view names[] = {
881+
static constexpr std::string_view names[] = {
881882
"user",
882883
"system",
883884
};
@@ -1062,7 +1063,7 @@ void Worker::GetHeapStatistics(const FunctionCallbackInfo<Value>& args) {
10621063
env](Environment* worker_env) mutable {
10631064
// We create a unique pointer to HeapStatistics so that the actual object
10641065
// it's not copied in the lambda, but only the pointer is.
1065-
auto heap_stats = std::make_unique<v8::HeapStatistics>();
1066+
auto heap_stats = std::make_unique<HeapStatistics>();
10661067
worker_env->isolate()->GetHeapStatistics(heap_stats.get());
10671068

10681069
// Here, the worker thread temporarily owns the WorkerHeapStatisticsTaker
@@ -1095,7 +1096,7 @@ void Worker::GetHeapStatistics(const FunctionCallbackInfo<Value>& args) {
10951096
"used_global_handles_size",
10961097
"external_memory",
10971098
};
1098-
tmpl = v8::DictionaryTemplate::New(isolate, heap_stats_names);
1099+
tmpl = DictionaryTemplate::New(isolate, heap_stats_names);
10991100
env->set_heap_statistics_template(tmpl);
11001101
}
11011102

0 commit comments

Comments
 (0)