Skip to content

Commit c0c743f

Browse files
committed
src: minor cleanups on OneByteString usage
* Provide a OneByteString variant that accepts std::string_view * Use FIXED_ONE_BYTE_STRING in appropriate places
1 parent b736028 commit c0c743f

18 files changed

+46
-42
lines changed

src/crypto/crypto_ec.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,16 +767,16 @@ Maybe<void> ExportJWKEcKey(Environment* env,
767767
const int nid = EC_GROUP_get_curve_name(group);
768768
switch (nid) {
769769
case NID_X9_62_prime256v1:
770-
crv_name = OneByteString(env->isolate(), "P-256");
770+
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-256");
771771
break;
772772
case NID_secp256k1:
773-
crv_name = OneByteString(env->isolate(), "secp256k1");
773+
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "secp256k1");
774774
break;
775775
case NID_secp384r1:
776-
crv_name = OneByteString(env->isolate(), "P-384");
776+
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-384");
777777
break;
778778
case NID_secp521r1:
779-
crv_name = OneByteString(env->isolate(), "P-521");
779+
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-521");
780780
break;
781781
default: {
782782
THROW_ERR_CRYPTO_JWK_UNSUPPORTED_CURVE(

src/crypto/crypto_hash.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void Hash::GetCachedAliases(const FunctionCallbackInfo<Value>& args) {
152152
names.reserve(size);
153153
values.reserve(size);
154154
for (auto& [alias, id] : env->alias_to_md_id_map) {
155-
names.push_back(OneByteString(isolate, alias.c_str(), alias.size()));
155+
names.push_back(OneByteString(isolate, alias));
156156
values.push_back(v8::Uint32::New(isolate, id));
157157
}
158158
#else

src/crypto/crypto_tls.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,7 @@ void TLSWrap::ClearOut() {
830830
if (context.IsEmpty()) [[unlikely]]
831831
return;
832832
const std::string error_str = GetBIOError();
833-
Local<String> message = OneByteString(
834-
env()->isolate(), error_str.c_str(), error_str.size());
833+
Local<String> message = OneByteString(env()->isolate(), error_str);
835834
if (message.IsEmpty()) [[unlikely]]
836835
return;
837836
error = Exception::Error(message);
@@ -1938,7 +1937,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
19381937
} else {
19391938
sig_with_md += "UNDEF";
19401939
}
1941-
ret_arr[i] = OneByteString(env->isolate(), sig_with_md.c_str());
1940+
ret_arr[i] = OneByteString(env->isolate(), sig_with_md);
19421941
}
19431942

19441943
args.GetReturnValue().Set(

src/histogram.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Local<FunctionTemplate> IntervalHistogram::GetConstructorTemplate(
341341
Isolate* isolate = env->isolate();
342342
tmpl = NewFunctionTemplate(isolate, nullptr);
343343
tmpl->Inherit(HandleWrap::GetConstructorTemplate(env));
344-
tmpl->SetClassName(OneByteString(isolate, "Histogram"));
344+
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "Histogram"));
345345
auto instance = tmpl->InstanceTemplate();
346346
instance->SetInternalFieldCount(HistogramImpl::kInternalFieldCount);
347347
HistogramImpl::AddMethods(isolate, tmpl);

src/inspector_js_api.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ void Url(const FunctionCallbackInfo<Value>& args) {
333333
if (url.empty()) {
334334
return;
335335
}
336-
args.GetReturnValue().Set(OneByteString(env->isolate(), url.c_str()));
336+
args.GetReturnValue().Set(OneByteString(env->isolate(), url));
337337
}
338338

339339
void Initialize(Local<Object> target, Local<Value> unused,

src/node_builtins.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void BuiltinLoader::GetNatives(Local<Name> property,
7878
Local<Object> out = Object::New(isolate);
7979
auto source = env->builtin_loader()->source_.read();
8080
for (auto const& x : *source) {
81-
Local<String> key = OneByteString(isolate, x.first.c_str(), x.first.size());
81+
Local<String> key = OneByteString(isolate, x.first);
8282
out->Set(context, key, x.second.ToStringChecked(isolate)).FromJust();
8383
}
8484
info.GetReturnValue().Set(out);
@@ -206,7 +206,7 @@ MaybeLocal<String> BuiltinLoader::LoadBuiltinSource(Isolate* isolate,
206206
uv_err_name(r),
207207
uv_strerror(r),
208208
filename);
209-
Local<String> message = OneByteString(isolate, buf.c_str());
209+
Local<String> message = OneByteString(isolate, buf);
210210
isolate->ThrowException(v8::Exception::Error(message));
211211
return MaybeLocal<String>();
212212
}
@@ -276,8 +276,7 @@ MaybeLocal<Function> BuiltinLoader::LookupAndCompileInternal(
276276
}
277277

278278
std::string filename_s = std::string("node:") + id;
279-
Local<String> filename =
280-
OneByteString(isolate, filename_s.c_str(), filename_s.size());
279+
Local<String> filename = OneByteString(isolate, filename_s);
281280
ScriptOrigin origin(filename, 0, 0, true);
282281

283282
BuiltinCodeCacheData cached_data{};
@@ -594,7 +593,7 @@ void BuiltinLoader::GetBuiltinCategories(
594593
return;
595594
if (result
596595
->Set(context,
597-
OneByteString(isolate, "cannotBeRequired"),
596+
FIXED_ONE_BYTE_STRING(isolate, "cannotBeRequired"),
598597
cannot_be_required_js)
599598
.IsNothing())
600599
return;
@@ -603,7 +602,7 @@ void BuiltinLoader::GetBuiltinCategories(
603602
return;
604603
if (result
605604
->Set(context,
606-
OneByteString(isolate, "canBeRequired"),
605+
FIXED_ONE_BYTE_STRING(isolate, "canBeRequired"),
607606
can_be_required_js)
608607
.IsNothing()) {
609608
return;
@@ -626,7 +625,7 @@ void BuiltinLoader::GetCacheUsage(const FunctionCallbackInfo<Value>& args) {
626625
}
627626
if (result
628627
->Set(context,
629-
OneByteString(isolate, "compiledWithCache"),
628+
FIXED_ONE_BYTE_STRING(isolate, "compiledWithCache"),
630629
builtins_with_cache_js)
631630
.IsNothing()) {
632631
return;
@@ -638,7 +637,7 @@ void BuiltinLoader::GetCacheUsage(const FunctionCallbackInfo<Value>& args) {
638637
}
639638
if (result
640639
->Set(context,
641-
OneByteString(isolate, "compiledWithoutCache"),
640+
FIXED_ONE_BYTE_STRING(isolate, "compiledWithoutCache"),
642641
builtins_without_cache_js)
643642
.IsNothing()) {
644643
return;
@@ -650,7 +649,7 @@ void BuiltinLoader::GetCacheUsage(const FunctionCallbackInfo<Value>& args) {
650649
}
651650
if (result
652651
->Set(context,
653-
OneByteString(isolate, "compiledInSnapshot"),
652+
FIXED_ONE_BYTE_STRING(isolate, "compiledInSnapshot"),
654653
builtins_in_snapshot_js)
655654
.IsNothing()) {
656655
return;

src/node_constants.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,31 +1338,31 @@ void CreatePerContextProperties(Local<Object> target,
13381338
NODE_DEFINE_CONSTANT(os_constants, UV_UDP_REUSEADDR);
13391339

13401340
os_constants->Set(env->context(),
1341-
OneByteString(isolate, "dlopen"),
1341+
FIXED_ONE_BYTE_STRING(isolate, "dlopen"),
13421342
dlopen_constants).Check();
13431343
os_constants->Set(env->context(),
1344-
OneByteString(isolate, "errno"),
1344+
FIXED_ONE_BYTE_STRING(isolate, "errno"),
13451345
err_constants).Check();
13461346
os_constants->Set(env->context(),
1347-
OneByteString(isolate, "signals"),
1347+
FIXED_ONE_BYTE_STRING(isolate, "signals"),
13481348
sig_constants).Check();
13491349
os_constants->Set(env->context(),
1350-
OneByteString(isolate, "priority"),
1350+
FIXED_ONE_BYTE_STRING(isolate, "priority"),
13511351
priority_constants).Check();
13521352
target->Set(env->context(),
1353-
OneByteString(isolate, "os"),
1353+
FIXED_ONE_BYTE_STRING(isolate, "os"),
13541354
os_constants).Check();
13551355
target->Set(env->context(),
1356-
OneByteString(isolate, "fs"),
1356+
FIXED_ONE_BYTE_STRING(isolate, "fs"),
13571357
fs_constants).Check();
13581358
target->Set(env->context(),
1359-
OneByteString(isolate, "crypto"),
1359+
FIXED_ONE_BYTE_STRING(isolate, "crypto"),
13601360
crypto_constants).Check();
13611361
target->Set(env->context(),
1362-
OneByteString(isolate, "zlib"),
1362+
FIXED_ONE_BYTE_STRING(isolate, "zlib"),
13631363
zlib_constants).Check();
13641364
target->Set(env->context(),
1365-
OneByteString(isolate, "trace"),
1365+
FIXED_ONE_BYTE_STRING(isolate, "trace"),
13661366
trace_constants).Check();
13671367
}
13681368

src/node_errors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
118118
inline v8::Local<v8::Object> code( \
119119
v8::Isolate* isolate, const char* format, Args&&... args) { \
120120
std::string message = SPrintF(format, std::forward<Args>(args)...); \
121-
v8::Local<v8::String> js_code = OneByteString(isolate, #code); \
121+
v8::Local<v8::String> js_code = FIXED_ONE_BYTE_STRING(isolate, #code); \
122122
v8::Local<v8::String> js_msg = \
123123
v8::String::NewFromUtf8(isolate, \
124124
message.c_str(), \
@@ -129,7 +129,7 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
129129
->ToObject(isolate->GetCurrentContext()) \
130130
.ToLocalChecked(); \
131131
e->Set(isolate->GetCurrentContext(), \
132-
OneByteString(isolate, "code"), \
132+
FIXED_ONE_BYTE_STRING(isolate, "code"), \
133133
js_code) \
134134
.Check(); \
135135
return e; \

src/node_http2.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ MaybeLocal<Object> Http2SessionPerformanceEntryTraits::GetDetails(
728728
if (!obj->Set(
729729
env->context(),
730730
env->type_string(),
731-
OneByteString(
731+
FIXED_ONE_BYTE_STRING(
732732
env->isolate(),
733733
(entry.details.session_type == NGHTTP2_SESSION_SERVER)
734734
? "server" : "client")).IsJust()) {

src/node_messaging.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
16601660
Local<FunctionTemplate> t = FunctionTemplate::New(isolate);
16611661
t->InstanceTemplate()->SetInternalFieldCount(
16621662
JSTransferable::kInternalFieldCount);
1663-
t->SetClassName(OneByteString(isolate, "JSTransferable"));
1663+
t->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "JSTransferable"));
16641664
isolate_data->set_js_transferable_constructor_template(t);
16651665
}
16661666

0 commit comments

Comments
 (0)