Skip to content

Commit 0978abf

Browse files
committed
fixup: suggestion (wrapper with check)
1 parent 848b407 commit 0978abf

File tree

6 files changed

+51
-18
lines changed

6 files changed

+51
-18
lines changed

src/node_sqlite.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,10 +2273,14 @@ void StatementSync::Columns(const FunctionCallbackInfo<Value>& args) {
22732273
NullableSQLiteStringToValue(
22742274
isolate, sqlite3_column_decltype(stmt->statement_, i)),
22752275
};
2276-
if (IsAnyEntryEmpty(values)) return;
22772276

2278-
cols.emplace_back(
2279-
sqlite_column_template->NewInstance(env->context(), values));
2277+
Local<Object> values_obj;
2278+
if (!CheckedDictionaryInstance(
2279+
sqlite_column_template, env->context(), values)
2280+
.ToLocal(&values_obj)) {
2281+
return;
2282+
}
2283+
cols.emplace_back(values_obj);
22802284
}
22812285

22822286
args.GetReturnValue().Set(Array::New(isolate, cols.data(), cols.size()));

src/node_url_pattern.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,7 @@ MaybeLocal<Value> URLPattern::URLPatternResult::ToJSValue(
451451
URLPatternComponentResult::ToJSObject(env, result.search),
452452
URLPatternComponentResult::ToJSObject(env, result.hash),
453453
};
454-
if (IsAnyEntryEmpty(vals)) return {};
455-
return tmpl->NewInstance(env->context(), vals);
454+
return CheckedDictionaryInstance(tmpl, env->context(), vals);
456455
}
457456

458457
std::optional<ada::url_pattern_options>

src/node_util.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,12 @@ static void GetCallSites(const FunctionCallbackInfo<Value>& args) {
305305
Integer::NewFromUnsigned(isolate, stack_frame->GetColumn()),
306306
};
307307

308-
if (IsAnyEntryEmpty(values)) return;
309-
callsite_objects.push_back(
310-
callsite_template->NewInstance(env->context(), values));
308+
Local<Object> callsite_object;
309+
if (!CheckedDictionaryInstance(callsite_template, env->context(), values)
310+
.ToLocal(&callsite_object)) {
311+
return;
312+
}
313+
callsite_objects.emplace_back(callsite_object);
311314
}
312315

313316
Local<Array> callsites =

src/node_v8.cc

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,12 @@ static MaybeLocal<Object> ConvertHeapStatsToJSObject(
401401
isolate, static_cast<uint32_t>(object_stats.allocated_bytes)),
402402
Uint32::NewFromUnsigned(
403403
isolate, static_cast<uint32_t>(object_stats.object_count))};
404-
Local<Object> object_stats_object =
405-
object_stats_template->NewInstance(context, object_stats_values);
404+
Local<Object> object_stats_object;
405+
if (!CheckedDictionaryInstance(
406+
object_stats_template, context, object_stats_values)
407+
.ToLocal(&object_stats_object)) {
408+
return {};
409+
}
406410
object_statistics_array.emplace_back(object_stats_object);
407411
}
408412

@@ -417,8 +421,12 @@ static MaybeLocal<Object> ConvertHeapStatsToJSObject(
417421
Array::New(isolate,
418422
object_statistics_array.data(),
419423
object_statistics_array.size())};
420-
page_statistics_array.emplace_back(
421-
page_stats_tmpl->NewInstance(context, page_stats_values));
424+
Local<Object> page_stats_object;
425+
if (!CheckedDictionaryInstance(
426+
page_stats_tmpl, context, page_stats_values)
427+
.ToLocal(&page_stats_object)) {
428+
return {};
429+
}
422430
}
423431

424432
// Free List Statistics
@@ -456,8 +464,13 @@ static MaybeLocal<Object> ConvertHeapStatsToJSObject(
456464
page_statistics_array.size()),
457465
free_list_statistics_obj,
458466
};
459-
space_statistics_array.emplace_back(
460-
space_stats_tmpl->NewInstance(context, space_stats_values));
467+
Local<Object> space_stats_object;
468+
if (!CheckedDictionaryInstance(
469+
space_stats_tmpl, context, space_stats_values)
470+
.ToLocal(&space_stats_object)) {
471+
return {};
472+
}
473+
space_statistics_array.emplace_back(space_stats_object);
461474
}
462475

463476
Local<Value> type_names_value;
@@ -476,8 +489,8 @@ static MaybeLocal<Object> ConvertHeapStatsToJSObject(
476489
space_statistics_array.data(),
477490
space_statistics_array.size()),
478491
type_names_value};
479-
480-
return heap_stats_tmpl->NewInstance(context, heap_statistics_values);
492+
return CheckedDictionaryInstance(
493+
heap_stats_tmpl, context, heap_statistics_values);
481494
}
482495

483496
static void GetCppHeapStatistics(const FunctionCallbackInfo<Value>& args) {

src/node_worker.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,14 @@ void Worker::GetHeapStatistics(const FunctionCallbackInfo<Value>& args) {
11171117
Number::New(isolate, heap_stats->used_global_handles_size()),
11181118
Number::New(isolate, heap_stats->external_memory())};
11191119

1120-
Local<Value> args[] = {
1121-
tmpl->NewInstance(env->context(), heap_stats_values)};
1120+
Local<Object> heap_stats_object;
1121+
if (!CheckedDictionaryInstance(
1122+
tmpl, env->context(), heap_stats_values)
1123+
.ToLocal(&heap_stats_object)) {
1124+
return;
1125+
}
1126+
1127+
Local<Value> args[] = {heap_stats_object};
11221128
taker->get()->MakeCallback(
11231129
env->ondone_string(), arraysize(args), args);
11241130
// implicitly delete `taker`

src/util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,14 @@ inline bool IsAnyEntryEmpty(const T& t) {
10411041
return false;
10421042
}
10431043

1044+
inline v8::MaybeLocal<v8::Object> CheckedDictionaryInstance(
1045+
v8::Local<v8::DictionaryTemplate> tmpl,
1046+
v8::Local<v8::Context> context,
1047+
v8::MemorySpan<v8::MaybeLocal<v8::Value>> property_values) {
1048+
if (IsAnyEntryEmpty(property_values)) return {};
1049+
return tmpl->NewInstance(context, property_values);
1050+
}
1051+
10441052
#ifdef _WIN32
10451053
// Returns true if OS==Windows and filename ends in .bat or .cmd,
10461054
// case insensitive.

0 commit comments

Comments
 (0)