Skip to content

Commit 8c11bea

Browse files
jasnelladuh95
authored andcommitted
src: update repeated use strings to env
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #64760 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent b48699e commit 8c11bea

7 files changed

Lines changed: 41 additions & 39 deletions

File tree

‎src/crypto/crypto_context.cc‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,12 +2247,9 @@ void SecureContext::GetCertificateCompressionAlgorithms(
22472247
Environment* env = Environment::GetCurrent(args);
22482248
LocalVector<Value> algs(env->isolate());
22492249
#ifdef NODE_OPENSSL_HAS_CERT_COMP
2250-
if (BIO_f_zlib() != nullptr)
2251-
algs.push_back(FIXED_ONE_BYTE_STRING(env->isolate(), "zlib"));
2252-
if (BIO_f_brotli() != nullptr)
2253-
algs.push_back(FIXED_ONE_BYTE_STRING(env->isolate(), "brotli"));
2254-
if (BIO_f_zstd() != nullptr)
2255-
algs.push_back(FIXED_ONE_BYTE_STRING(env->isolate(), "zstd"));
2250+
if (BIO_f_zlib() != nullptr) algs.push_back(env->zlib_string());
2251+
if (BIO_f_brotli() != nullptr) algs.push_back(env->brotli_string());
2252+
if (BIO_f_zstd() != nullptr) algs.push_back(env->zstd_string());
22562253
#endif
22572254
args.GetReturnValue().Set(
22582255
Array::New(env->isolate(), algs.data(), algs.size()));

‎src/crypto/crypto_ec.cc‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,16 +657,16 @@ bool ExportJWKEcKey(Environment* env,
657657
const int nid = EC_GROUP_get_curve_name(group);
658658
switch (nid) {
659659
case NID_X9_62_prime256v1:
660-
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-256");
660+
crv_name = env->p256_string();
661661
break;
662662
case NID_secp256k1:
663-
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "secp256k1");
663+
crv_name = env->secp256k1_string();
664664
break;
665665
case NID_secp384r1:
666-
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-384");
666+
crv_name = env->p384_string();
667667
break;
668668
case NID_secp521r1:
669-
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-521");
669+
crv_name = env->p521_string();
670670
break;
671671
default: {
672672
THROW_ERR_CRYPTO_JWK_UNSUPPORTED_CURVE(

‎src/crypto/crypto_keys.cc‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,8 +1797,7 @@ BaseObjectPtr<BaseObject> NativeKeyObject::KeyObjectTransferData::Deserialize(
17971797
return {};
17981798

17991799
Local<Function> key_ctor;
1800-
Local<Value> arg = FIXED_ONE_BYTE_STRING(env->isolate(),
1801-
"internal/crypto/keys");
1800+
Local<Value> arg = env->internal_crypto_keys_string();
18021801
if (env->builtin_module_require()
18031802
->Call(context, Null(env->isolate()), 1, &arg)
18041803
.IsEmpty()) {
@@ -1902,7 +1901,7 @@ MaybeLocal<Value> NativeCryptoKey::Create(Environment* env,
19021901
if (!KeyObjectHandle::Create(env, data).ToLocal(&handle)) return {};
19031902

19041903
if (env->crypto_internal_cryptokey_constructor().IsEmpty()) {
1905-
Local<Value> arg = FIXED_ONE_BYTE_STRING(isolate, "internal/crypto/keys");
1904+
Local<Value> arg = env->internal_crypto_keys_string();
19061905
if (env->builtin_module_require()
19071906
->Call(context, Null(isolate), 1, &arg)
19081907
.IsEmpty()) {
@@ -2044,31 +2043,28 @@ Maybe<void> NativeCryptoKey::FinalizeTransferRead(
20442043
}
20452044
CHECK(bundle_v->IsObject());
20462045
Local<Object> bundle = bundle_v.As<Object>();
2047-
Isolate* isolate = env()->isolate();
20482046
Local<Object> obj = object();
20492047

20502048
// The partially-initialized object produced by
20512049
// CryptoKeyTransferData::Deserialize should not have algorithm set yet.
20522050
CHECK(obj->GetInternalField(kAlgorithmField).As<Value>()->IsUndefined());
20532051

20542052
Local<Value> algorithm_v;
2055-
if (!bundle->Get(context, FIXED_ONE_BYTE_STRING(isolate, "algorithm"))
2056-
.ToLocal(&algorithm_v)) {
2053+
if (!bundle->Get(context, env()->algorithm_string()).ToLocal(&algorithm_v)) {
20572054
return Nothing<void>();
20582055
}
20592056
CHECK(algorithm_v->IsObject());
20602057
obj->SetInternalField(kAlgorithmField, algorithm_v);
20612058

20622059
Local<Value> usages_v;
2063-
if (!bundle->Get(context, FIXED_ONE_BYTE_STRING(isolate, "usages"))
2064-
.ToLocal(&usages_v)) {
2060+
if (!bundle->Get(context, env()->usages_string()).ToLocal(&usages_v)) {
20652061
return Nothing<void>();
20662062
}
20672063
CHECK(usages_v->IsUint32());
20682064
usages_mask_ = usages_v.As<Uint32>()->Value();
20692065

20702066
Local<Value> extractable_v;
2071-
if (!bundle->Get(context, FIXED_ONE_BYTE_STRING(isolate, "extractable"))
2067+
if (!bundle->Get(context, env()->extractable_string())
20722068
.ToLocal(&extractable_v)) {
20732069
return Nothing<void>();
20742070
}
@@ -2081,21 +2077,19 @@ Maybe<void> NativeCryptoKey::FinalizeTransferRead(
20812077
Maybe<bool> NativeCryptoKey::CryptoKeyTransferData::FinalizeTransferWrite(
20822078
Local<Context> context, v8::ValueSerializer* serializer) {
20832079
Isolate* isolate = Isolate::GetCurrent();
2080+
Environment* env = Environment::GetCurrent(isolate);
20842081
CHECK(!algorithm_.IsEmpty());
20852082
Local<Object> bundle = Object::New(isolate);
20862083
Local<Value> algorithm_v = PersistentToLocal::Strong(algorithm_);
2087-
if (bundle
2088-
->Set(
2089-
context, FIXED_ONE_BYTE_STRING(isolate, "algorithm"), algorithm_v)
2090-
.IsNothing() ||
2084+
if (bundle->Set(context, env->algorithm_string(), algorithm_v).IsNothing() ||
20912085
bundle
20922086
->Set(context,
2093-
FIXED_ONE_BYTE_STRING(isolate, "usages"),
2087+
env->usages_string(),
20942088
Uint32::NewFromUnsigned(isolate, usages_mask_))
20952089
.IsNothing() ||
20962090
bundle
20972091
->Set(context,
2098-
FIXED_ONE_BYTE_STRING(isolate, "extractable"),
2092+
env->extractable_string(),
20992093
v8::Boolean::New(isolate, extractable_))
21002094
.IsNothing()) {
21012095
return Nothing<bool>();
@@ -2121,7 +2115,7 @@ BaseObjectPtr<BaseObject> NativeCryptoKey::CryptoKeyTransferData::Deserialize(
21212115
// Make sure internal/crypto/keys has been loaded so that the
21222116
// CryptoKey constructor is registered with the Environment.
21232117
Isolate* isolate = env->isolate();
2124-
Local<Value> arg = FIXED_ONE_BYTE_STRING(isolate, "internal/crypto/keys");
2118+
Local<Value> arg = env->internal_crypto_keys_string();
21252119
if (env->builtin_module_require()
21262120
->Call(context, Null(isolate), 1, &arg)
21272121
.IsEmpty()) {

‎src/crypto/crypto_util.cc‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ MaybeLocal<Value> cryptoErrorListToException(Environment* env,
248248
// If there are no errors, it is likely a bug but we will return
249249
// an error anyway.
250250
if (errors.empty()) {
251-
return Exception::Error(FIXED_ONE_BYTE_STRING(env->isolate(), "Ok"));
251+
return Exception::Error(env->ok_string());
252252
}
253253

254254
// The last error in the list is the one that will be used as the
@@ -739,13 +739,9 @@ MaybeLocal<Value> CreateWebCryptoJobError(Environment* env,
739739
CHECK(domexception_ctor->IsFunction());
740740

741741
Local<Object> options = Object::New(isolate);
742-
if (options
743-
->Set(context,
744-
FIXED_ONE_BYTE_STRING(isolate, "name"),
745-
FIXED_ONE_BYTE_STRING(isolate, "OperationError"))
742+
if (options->Set(context, env->name_string(), env->operationerror_string())
746743
.IsNothing() ||
747-
options->Set(context, FIXED_ONE_BYTE_STRING(isolate, "cause"), cause)
748-
.IsNothing()) {
744+
options->Set(context, env->cause_string(), cause).IsNothing()) {
749745
return {};
750746
}
751747

‎src/crypto/crypto_util.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
463463
{
464464
node::errors::TryCatchScope try_catch(env);
465465
if (value->IsObject()) {
466-
then_key = FIXED_ONE_BYTE_STRING(env->isolate(), "then");
466+
then_key = env->then_string();
467467
v8::Local<v8::Object> object = value.As<v8::Object>();
468468
v8::Maybe<bool> has_own_then =
469469
object->HasOwnProperty(context, then_key);

‎src/env_properties.h‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
V(__dirname_string, "__dirname") \
7575
V(ack_string, "ack") \
7676
V(address_string, "address") \
77+
V(algorithm_string, "algorithm") \
7778
V(aliases_string, "aliases") \
7879
V(allow_bare_named_params_string, "allowBareNamedParameters") \
7980
V(allow_unknown_named_params_string, "allowUnknownNamedParameters") \
@@ -84,13 +85,15 @@
8485
V(backup_string, "backup") \
8586
V(base_string, "base") \
8687
V(base_url_string, "baseURL") \
88+
V(brotli_string, "brotli") \
8789
V(buffer_string, "buffer") \
8890
V(bytes_parsed_string, "bytesParsed") \
8991
V(bytes_read_string, "bytesRead") \
9092
V(bytes_written_string, "bytesWritten") \
9193
V(cached_data_produced_string, "cachedDataProduced") \
9294
V(cached_data_rejected_string, "cachedDataRejected") \
9395
V(cached_data_string, "cachedData") \
96+
V(cause_string, "cause") \
9497
V(change_string, "change") \
9598
V(changes_string, "changes") \
9699
V(chunks_sent_since_last_write_string, "chunksSentSinceLastWrite") \
@@ -171,6 +174,7 @@
171174
V(exponent_string, "exponent") \
172175
V(exports_string, "exports") \
173176
V(external_stream_string, "_externalStream") \
177+
V(extractable_string, "extractable") \
174178
V(family_string, "family") \
175179
V(fatal_exception_string, "_fatalException") \
176180
V(fd_string, "fd") \
@@ -206,6 +210,7 @@
206210
V(ignore_string, "ignore") \
207211
V(inherit_string, "inherit") \
208212
V(input_string, "input") \
213+
V(internal_crypto_keys_string, "internal/crypto/keys") \
209214
V(inverse_string, "inverse") \
210215
V(ipv4_string, "IPv4") \
211216
V(ipv6_string, "IPv6") \
@@ -255,6 +260,7 @@
255260
V(node_string, "node") \
256261
V(object_string, "Object") \
257262
V(ocsp_request_string, "OCSPRequest") \
263+
V(ok_string, "ok") \
258264
V(oncertcb_string, "oncertcb") \
259265
V(onchange_string, "onchange") \
260266
V(onclienthello_string, "onclienthello") \
@@ -278,10 +284,14 @@
278284
V(onwrite_string, "onwrite") \
279285
V(ongracefulclosecomplete_string, "ongracefulclosecomplete") \
280286
V(openssl_error_stack, "opensslErrorStack") \
287+
V(operationerror_string, "OperationError") \
281288
V(options_string, "options") \
282289
V(original_string, "original") \
283290
V(output_string, "output") \
284291
V(overlapped_string, "overlapped") \
292+
V(p256_string, "P-256") \
293+
V(p384_string, "P-384") \
294+
V(p521_string, "P-521") \
285295
V(parse_error_string, "Parse Error") \
286296
V(password_string, "password") \
287297
V(path_string, "path") \
@@ -322,6 +332,7 @@
322332
V(result_string, "result") \
323333
V(return_arrays_string, "returnArrays") \
324334
V(salt_length_string, "saltLength") \
335+
V(secp256k1_string, "secp256k1") \
325336
V(search_string, "search") \
326337
V(servername_string, "servername") \
327338
V(session_id_string, "sessionId") \
@@ -350,6 +361,7 @@
350361
V(syscall_string, "syscall") \
351362
V(table_string, "table") \
352363
V(target_string, "target") \
364+
V(then_string, "then") \
353365
V(thread_id_string, "threadId") \
354366
V(thread_name_string, "threadName") \
355367
V(tls_group_string, "TLSGroup") \
@@ -368,6 +380,7 @@
368380
V(uid_string, "uid") \
369381
V(unknown_string, "<unknown>") \
370382
V(url_string, "url") \
383+
V(usages_string, "usages") \
371384
V(username_string, "username") \
372385
V(value_string, "value") \
373386
V(verify_error_string, "verifyError") \
@@ -377,7 +390,9 @@
377390
V(wrap_string, "wrap") \
378391
V(writable_string, "writable") \
379392
V(write_host_object_string, "_writeHostObject") \
380-
V(write_queue_size_string, "writeQueueSize")
393+
V(write_queue_size_string, "writeQueueSize") \
394+
V(zlib_string, "zlib") \
395+
V(zstd_string, "zstd")
381396

382397
#define PER_ISOLATE_TEMPLATE_PROPERTIES(V) \
383398
V(a_record_template, v8::DictionaryTemplate) \

‎src/permission/permission.cc‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ bool Permission::is_scope_granted(Environment* env,
251251
v8::Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0);
252252
const char* perm_str = PermissionToString(permission);
253253
msg->Set(context,
254-
FIXED_ONE_BYTE_STRING(isolate, "permission"),
254+
env->permission_string(),
255255
v8::String::NewFromUtf8(isolate, perm_str).ToLocalChecked())
256256
.Check();
257257
msg->Set(context,
258-
FIXED_ONE_BYTE_STRING(isolate, "resource"),
258+
env->resource_string(),
259259
v8::String::NewFromUtf8(isolate,
260260
res.data(),
261261
v8::NewStringType::kNormal,
@@ -321,11 +321,11 @@ void Permission::Drop(Environment* env,
321321
v8::Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0);
322322
const char* perm_str = PermissionToString(scope);
323323
msg->Set(context,
324-
FIXED_ONE_BYTE_STRING(isolate, "permission"),
324+
env->permission_string(),
325325
v8::String::NewFromUtf8(isolate, perm_str).ToLocalChecked())
326326
.Check();
327327
msg->Set(context,
328-
FIXED_ONE_BYTE_STRING(isolate, "resource"),
328+
env->resource_string(),
329329
v8::String::NewFromUtf8(isolate,
330330
param.data(),
331331
v8::NewStringType::kNormal,

0 commit comments

Comments
 (0)