From 7090b96cd4b7a35e5164d8c0988b3649064a05ca Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 26 Jul 2026 08:16:06 -0700 Subject: [PATCH] src: update repeated use strings to env Signed-off-by: James M Snell --- src/crypto/crypto_context.cc | 9 +++------ src/crypto/crypto_ec.cc | 8 ++++---- src/crypto/crypto_keys.cc | 26 ++++++++++---------------- src/crypto/crypto_util.cc | 10 +++------- src/crypto/crypto_util.h | 2 +- src/dtls/dtls_session.cc | 4 ++-- src/env_properties.h | 17 ++++++++++++++++- src/node_ffi.cc | 2 +- src/permission/permission.cc | 8 ++++---- 9 files changed, 44 insertions(+), 42 deletions(-) diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc index d6387a55bd78..0f61767cdbbe 100644 --- a/src/crypto/crypto_context.cc +++ b/src/crypto/crypto_context.cc @@ -2255,12 +2255,9 @@ void SecureContext::GetCertificateCompressionAlgorithms( Environment* env = Environment::GetCurrent(args); LocalVector algs(env->isolate()); #ifdef NODE_OPENSSL_HAS_CERT_COMP - if (BIO_f_zlib() != nullptr) - algs.push_back(FIXED_ONE_BYTE_STRING(env->isolate(), "zlib")); - if (BIO_f_brotli() != nullptr) - algs.push_back(FIXED_ONE_BYTE_STRING(env->isolate(), "brotli")); - if (BIO_f_zstd() != nullptr) - algs.push_back(FIXED_ONE_BYTE_STRING(env->isolate(), "zstd")); + if (BIO_f_zlib() != nullptr) algs.push_back(env->zlib_string()); + if (BIO_f_brotli() != nullptr) algs.push_back(env->brotli_string()); + if (BIO_f_zstd() != nullptr) algs.push_back(env->zstd_string()); #endif args.GetReturnValue().Set( Array::New(env->isolate(), algs.data(), algs.size())); diff --git a/src/crypto/crypto_ec.cc b/src/crypto/crypto_ec.cc index 388931c11e79..b08d4b7a9106 100644 --- a/src/crypto/crypto_ec.cc +++ b/src/crypto/crypto_ec.cc @@ -520,16 +520,16 @@ bool ExportJWKEcKey(Environment* env, const int nid = EC_GROUP_get_curve_name(group); switch (nid) { case NID_X9_62_prime256v1: - crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-256"); + crv_name = env->p256_string(); break; case NID_secp256k1: - crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "secp256k1"); + crv_name = env->secp256k1_string(); break; case NID_secp384r1: - crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-384"); + crv_name = env->p384_string(); break; case NID_secp521r1: - crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-521"); + crv_name = env->p521_string(); break; default: { THROW_ERR_CRYPTO_JWK_UNSUPPORTED_CURVE( diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index d8bdc93deff8..b4e3aa72292f 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -1796,8 +1796,7 @@ BaseObjectPtr NativeKeyObject::KeyObjectTransferData::Deserialize( return {}; Local key_ctor; - Local arg = FIXED_ONE_BYTE_STRING(env->isolate(), - "internal/crypto/keys"); + Local arg = env->internal_crypto_keys_string(); if (env->builtin_module_require() ->Call(context, Null(env->isolate()), 1, &arg) .IsEmpty()) { @@ -1875,7 +1874,7 @@ MaybeLocal NativeCryptoKey::Create(Environment* env, if (!KeyObjectHandle::Create(env, data).ToLocal(&handle)) return {}; if (env->crypto_internal_cryptokey_constructor().IsEmpty()) { - Local arg = FIXED_ONE_BYTE_STRING(isolate, "internal/crypto/keys"); + Local arg = env->internal_crypto_keys_string(); if (env->builtin_module_require() ->Call(context, Null(isolate), 1, &arg) .IsEmpty()) { @@ -2017,7 +2016,6 @@ Maybe NativeCryptoKey::FinalizeTransferRead( } CHECK(bundle_v->IsObject()); Local bundle = bundle_v.As(); - Isolate* isolate = env()->isolate(); Local obj = object(); // The partially-initialized object produced by @@ -2025,23 +2023,21 @@ Maybe NativeCryptoKey::FinalizeTransferRead( CHECK(obj->GetInternalField(kAlgorithmField).As()->IsUndefined()); Local algorithm_v; - if (!bundle->Get(context, FIXED_ONE_BYTE_STRING(isolate, "algorithm")) - .ToLocal(&algorithm_v)) { + if (!bundle->Get(context, env()->algorithm_string()).ToLocal(&algorithm_v)) { return Nothing(); } CHECK(algorithm_v->IsObject()); obj->SetInternalField(kAlgorithmField, algorithm_v); Local usages_v; - if (!bundle->Get(context, FIXED_ONE_BYTE_STRING(isolate, "usages")) - .ToLocal(&usages_v)) { + if (!bundle->Get(context, env()->usages_string()).ToLocal(&usages_v)) { return Nothing(); } CHECK(usages_v->IsUint32()); usages_mask_ = usages_v.As()->Value(); Local extractable_v; - if (!bundle->Get(context, FIXED_ONE_BYTE_STRING(isolate, "extractable")) + if (!bundle->Get(context, env()->extractable_string()) .ToLocal(&extractable_v)) { return Nothing(); } @@ -2054,21 +2050,19 @@ Maybe NativeCryptoKey::FinalizeTransferRead( Maybe NativeCryptoKey::CryptoKeyTransferData::FinalizeTransferWrite( Local context, v8::ValueSerializer* serializer) { Isolate* isolate = Isolate::GetCurrent(); + Environment* env = Environment::GetCurrent(isolate); CHECK(!algorithm_.IsEmpty()); Local bundle = Object::New(isolate); Local algorithm_v = PersistentToLocal::Strong(algorithm_); - if (bundle - ->Set( - context, FIXED_ONE_BYTE_STRING(isolate, "algorithm"), algorithm_v) - .IsNothing() || + if (bundle->Set(context, env->algorithm_string(), algorithm_v).IsNothing() || bundle ->Set(context, - FIXED_ONE_BYTE_STRING(isolate, "usages"), + env->usages_string(), Uint32::NewFromUnsigned(isolate, usages_mask_)) .IsNothing() || bundle ->Set(context, - FIXED_ONE_BYTE_STRING(isolate, "extractable"), + env->extractable_string(), v8::Boolean::New(isolate, extractable_)) .IsNothing()) { return Nothing(); @@ -2094,7 +2088,7 @@ BaseObjectPtr NativeCryptoKey::CryptoKeyTransferData::Deserialize( // Make sure internal/crypto/keys has been loaded so that the // CryptoKey constructor is registered with the Environment. Isolate* isolate = env->isolate(); - Local arg = FIXED_ONE_BYTE_STRING(isolate, "internal/crypto/keys"); + Local arg = env->internal_crypto_keys_string(); if (env->builtin_module_require() ->Call(context, Null(isolate), 1, &arg) .IsEmpty()) { diff --git a/src/crypto/crypto_util.cc b/src/crypto/crypto_util.cc index 080f2cf51cec..7c3e4b7ab5fe 100644 --- a/src/crypto/crypto_util.cc +++ b/src/crypto/crypto_util.cc @@ -267,7 +267,7 @@ MaybeLocal cryptoErrorListToException(Environment* env, // If there are no errors, it is likely a bug but we will return // an error anyway. if (errors.empty()) { - return Exception::Error(FIXED_ONE_BYTE_STRING(env->isolate(), "Ok")); + return Exception::Error(env->ok_string()); } // The last error in the list is the one that will be used as the @@ -778,13 +778,9 @@ MaybeLocal CreateWebCryptoJobError(Environment* env, CHECK(domexception_ctor->IsFunction()); Local options = Object::New(isolate); - if (options - ->Set(context, - FIXED_ONE_BYTE_STRING(isolate, "name"), - FIXED_ONE_BYTE_STRING(isolate, "OperationError")) + if (options->Set(context, env->name_string(), env->operationerror_string()) .IsNothing() || - options->Set(context, FIXED_ONE_BYTE_STRING(isolate, "cause"), cause) - .IsNothing()) { + options->Set(context, env->cause_string(), cause).IsNothing()) { return {}; } diff --git a/src/crypto/crypto_util.h b/src/crypto/crypto_util.h index 76afc3dd24a3..308e8fccba59 100644 --- a/src/crypto/crypto_util.h +++ b/src/crypto/crypto_util.h @@ -477,7 +477,7 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork { { node::errors::TryCatchScope try_catch(env); if (value->IsObject()) { - then_key = FIXED_ONE_BYTE_STRING(env->isolate(), "then"); + then_key = env->then_string(); v8::Local object = value.As(); v8::Maybe has_own_then = object->HasOwnProperty(context, then_key); diff --git a/src/dtls/dtls_session.cc b/src/dtls/dtls_session.cc index 02f1563abac7..6696b8587402 100644 --- a/src/dtls/dtls_session.cc +++ b/src/dtls/dtls_session.cc @@ -622,7 +622,7 @@ void DTLSSession::GetCipher(const FunctionCallbackInfo& args) { Local info = Object::New(env->isolate()); info->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "name"), + env->name_string(), String::NewFromUtf8(env->isolate(), SSL_CIPHER_get_name(cipher)) .ToLocalChecked()) .Check(); @@ -633,7 +633,7 @@ void DTLSSession::GetCipher(const FunctionCallbackInfo& args) { .ToLocalChecked()) .Check(); info->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "version"), + env->version_string(), String::NewFromUtf8(env->isolate(), SSL_CIPHER_get_version(cipher)) .ToLocalChecked()) .Check(); diff --git a/src/env_properties.h b/src/env_properties.h index e3179287dce4..f54efa36b6df 100644 --- a/src/env_properties.h +++ b/src/env_properties.h @@ -82,6 +82,7 @@ V(__dirname_string, "__dirname") \ V(ack_string, "ack") \ V(address_string, "address") \ + V(algorithm_string, "algorithm") \ V(aliases_string, "aliases") \ V(allow_bare_named_params_string, "allowBareNamedParameters") \ V(allow_unknown_named_params_string, "allowUnknownNamedParameters") \ @@ -93,6 +94,7 @@ V(backup_string, "backup") \ V(base_string, "base") \ V(base_url_string, "baseURL") \ + V(brotli_string, "brotli") \ V(buffer_string, "buffer") \ V(bytes_parsed_string, "bytesParsed") \ V(bytes_read_string, "bytesRead") \ @@ -100,6 +102,7 @@ V(cached_data_produced_string, "cachedDataProduced") \ V(cached_data_rejected_string, "cachedDataRejected") \ V(cached_data_string, "cachedData") \ + V(cause_string, "cause") \ V(change_string, "change") \ V(changes_string, "changes") \ V(chunks_sent_since_last_write_string, "chunksSentSinceLastWrite") \ @@ -180,6 +183,7 @@ V(exponent_string, "exponent") \ V(exports_string, "exports") \ V(external_stream_string, "_externalStream") \ + V(extractable_string, "extractable") \ V(family_string, "family") \ V(fatal_exception_string, "_fatalException") \ V(fd_string, "fd") \ @@ -215,6 +219,7 @@ V(ignore_string, "ignore") \ V(inherit_string, "inherit") \ V(input_string, "input") \ + V(internal_crypto_keys_string, "internal/crypto/keys") \ V(inverse_string, "inverse") \ V(ipv4_string, "IPv4") \ V(ipv6_string, "IPv6") \ @@ -264,6 +269,7 @@ V(node_string, "node") \ V(object_string, "Object") \ V(ocsp_request_string, "OCSPRequest") \ + V(ok_string, "ok") \ V(oncertcb_string, "oncertcb") \ V(onchange_string, "onchange") \ V(onclienthello_string, "onclienthello") \ @@ -287,10 +293,14 @@ V(onwrite_string, "onwrite") \ V(ongracefulclosecomplete_string, "ongracefulclosecomplete") \ V(openssl_error_stack, "opensslErrorStack") \ + V(operationerror_string, "OperationError") \ V(options_string, "options") \ V(original_string, "original") \ V(output_string, "output") \ V(overlapped_string, "overlapped") \ + V(p256_string, "P-256") \ + V(p384_string, "P-384") \ + V(p521_string, "P-521") \ V(parse_error_string, "Parse Error") \ V(password_string, "password") \ V(path_string, "path") \ @@ -333,6 +343,7 @@ V(return_arrays_string, "returnArrays") \ V(return_string, "return") \ V(salt_length_string, "saltLength") \ + V(secp256k1_string, "secp256k1") \ V(search_string, "search") \ V(servername_string, "servername") \ V(session_id_string, "sessionId") \ @@ -361,6 +372,7 @@ V(syscall_string, "syscall") \ V(table_string, "table") \ V(target_string, "target") \ + V(then_string, "then") \ V(thread_id_string, "threadId") \ V(thread_name_string, "threadName") \ V(tls_group_string, "TLSGroup") \ @@ -379,6 +391,7 @@ V(uid_string, "uid") \ V(unknown_string, "") \ V(url_string, "url") \ + V(usages_string, "usages") \ V(username_string, "username") \ V(value_string, "value") \ V(verify_error_string, "verifyError") \ @@ -388,7 +401,9 @@ V(wrap_string, "wrap") \ V(writable_string, "writable") \ V(write_host_object_string, "_writeHostObject") \ - V(write_queue_size_string, "writeQueueSize") + V(write_queue_size_string, "writeQueueSize") \ + V(zlib_string, "zlib") \ + V(zstd_string, "zstd") #define PER_ISOLATE_TEMPLATE_PROPERTIES(V) \ V(a_record_template, v8::DictionaryTemplate) \ diff --git a/src/node_ffi.cc b/src/node_ffi.cc index 26a8f5a610cb..638ad4feafdf 100644 --- a/src/node_ffi.cc +++ b/src/node_ffi.cc @@ -1210,7 +1210,7 @@ Local DynamicLibrary::GetConstructorTemplate( DynamicLibrary::kInternalFieldCount); tmpl->InstanceTemplate()->SetAccessorProperty( - FIXED_ONE_BYTE_STRING(isolate, "path"), + env->path_string(), FunctionTemplate::New(env->isolate(), DynamicLibrary::GetPath), Local(), attributes); diff --git a/src/permission/permission.cc b/src/permission/permission.cc index cf1174d85fa1..919edd0821fd 100644 --- a/src/permission/permission.cc +++ b/src/permission/permission.cc @@ -265,11 +265,11 @@ bool Permission::is_scope_granted(Environment* env, v8::Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0); const char* perm_str = PermissionToString(permission); msg->Set(context, - FIXED_ONE_BYTE_STRING(isolate, "permission"), + env->permission_string(), v8::String::NewFromUtf8(isolate, perm_str).ToLocalChecked()) .Check(); msg->Set(context, - FIXED_ONE_BYTE_STRING(isolate, "resource"), + env->resource_string(), v8::String::NewFromUtf8(isolate, res.data(), v8::NewStringType::kNormal, @@ -335,11 +335,11 @@ void Permission::Drop(Environment* env, v8::Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0); const char* perm_str = PermissionToString(scope); msg->Set(context, - FIXED_ONE_BYTE_STRING(isolate, "permission"), + env->permission_string(), v8::String::NewFromUtf8(isolate, perm_str).ToLocalChecked()) .Check(); msg->Set(context, - FIXED_ONE_BYTE_STRING(isolate, "resource"), + env->resource_string(), v8::String::NewFromUtf8(isolate, param.data(), v8::NewStringType::kNormal,