Skip to content

Commit 0179359

Browse files
committed
src: update repeated use strings to env
Signed-off-by: James M Snell <jasnell@gmail.com>
1 parent 4a5eb1c commit 0179359

9 files changed

Lines changed: 44 additions & 33 deletions

File tree

src/crypto/crypto_context.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,11 +2248,11 @@ void SecureContext::GetCertificateCompressionAlgorithms(
22482248
LocalVector<Value> algs(env->isolate());
22492249
#ifdef NODE_OPENSSL_HAS_CERT_COMP
22502250
if (BIO_f_zlib() != nullptr)
2251-
algs.push_back(FIXED_ONE_BYTE_STRING(env->isolate(), "zlib"));
2251+
algs.push_back(env->zlib_string());
22522252
if (BIO_f_brotli() != nullptr)
2253-
algs.push_back(FIXED_ONE_BYTE_STRING(env->isolate(), "brotli"));
2253+
algs.push_back(env->brotli_string());
22542254
if (BIO_f_zstd() != nullptr)
2255-
algs.push_back(FIXED_ONE_BYTE_STRING(env->isolate(), "zstd"));
2255+
algs.push_back(env->zstd_string());
22562256
#endif
22572257
args.GetReturnValue().Set(
22582258
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
@@ -518,16 +518,16 @@ bool ExportJWKEcKey(Environment* env,
518518
const int nid = EC_GROUP_get_curve_name(group);
519519
switch (nid) {
520520
case NID_X9_62_prime256v1:
521-
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-256");
521+
crv_name = env->p256_string();
522522
break;
523523
case NID_secp256k1:
524-
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "secp256k1");
524+
crv_name = env->secp256k1_string();
525525
break;
526526
case NID_secp384r1:
527-
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-384");
527+
crv_name = env->p384_string();
528528
break;
529529
case NID_secp521r1:
530-
crv_name = FIXED_ONE_BYTE_STRING(env->isolate(), "P-521");
530+
crv_name = env->p521_string();
531531
break;
532532
default: {
533533
THROW_ERR_CRYPTO_JWK_UNSUPPORTED_CURVE(

src/crypto/crypto_keys.cc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,8 +1686,7 @@ BaseObjectPtr<BaseObject> NativeKeyObject::KeyObjectTransferData::Deserialize(
16861686
return {};
16871687

16881688
Local<Function> key_ctor;
1689-
Local<Value> arg = FIXED_ONE_BYTE_STRING(env->isolate(),
1690-
"internal/crypto/keys");
1689+
Local<Value> arg = env->internal_crypto_keys_string();
16911690
if (env->builtin_module_require()
16921691
->Call(context, Null(env->isolate()), 1, &arg)
16931692
.IsEmpty()) {
@@ -1765,7 +1764,7 @@ MaybeLocal<Value> NativeCryptoKey::Create(Environment* env,
17651764
if (!KeyObjectHandle::Create(env, data).ToLocal(&handle)) return {};
17661765

17671766
if (env->crypto_internal_cryptokey_constructor().IsEmpty()) {
1768-
Local<Value> arg = FIXED_ONE_BYTE_STRING(isolate, "internal/crypto/keys");
1767+
Local<Value> arg = env->internal_crypto_keys_string();
17691768
if (env->builtin_module_require()
17701769
->Call(context, Null(isolate), 1, &arg)
17711770
.IsEmpty()) {
@@ -1915,23 +1914,23 @@ Maybe<void> NativeCryptoKey::FinalizeTransferRead(
19151914
CHECK(obj->GetInternalField(kAlgorithmField).As<Value>()->IsUndefined());
19161915

19171916
Local<Value> algorithm_v;
1918-
if (!bundle->Get(context, FIXED_ONE_BYTE_STRING(isolate, "algorithm"))
1917+
if (!bundle->Get(context, env()->algorithm_string())
19191918
.ToLocal(&algorithm_v)) {
19201919
return Nothing<void>();
19211920
}
19221921
CHECK(algorithm_v->IsObject());
19231922
obj->SetInternalField(kAlgorithmField, algorithm_v);
19241923

19251924
Local<Value> usages_v;
1926-
if (!bundle->Get(context, FIXED_ONE_BYTE_STRING(isolate, "usages"))
1925+
if (!bundle->Get(context, env()->usages_string()))
19271926
.ToLocal(&usages_v)) {
19281927
return Nothing<void>();
19291928
}
19301929
CHECK(usages_v->IsUint32());
19311930
usages_mask_ = usages_v.As<Uint32>()->Value();
19321931

19331932
Local<Value> extractable_v;
1934-
if (!bundle->Get(context, FIXED_ONE_BYTE_STRING(isolate, "extractable"))
1933+
if (!bundle->Get(context, env()->extractable_string())
19351934
.ToLocal(&extractable_v)) {
19361935
return Nothing<void>();
19371936
}
@@ -1944,21 +1943,20 @@ Maybe<void> NativeCryptoKey::FinalizeTransferRead(
19441943
Maybe<bool> NativeCryptoKey::CryptoKeyTransferData::FinalizeTransferWrite(
19451944
Local<Context> context, v8::ValueSerializer* serializer) {
19461945
Isolate* isolate = Isolate::GetCurrent();
1946+
Environment* env = Environment::GetCurrent(isolate);
19471947
CHECK(!algorithm_.IsEmpty());
19481948
Local<Object> bundle = Object::New(isolate);
19491949
Local<Value> algorithm_v = PersistentToLocal::Strong(algorithm_);
19501950
if (bundle
19511951
->Set(
1952-
context, FIXED_ONE_BYTE_STRING(isolate, "algorithm"), algorithm_v)
1952+
context, env->algorithm_string(), algorithm_v)
19531953
.IsNothing() ||
19541954
bundle
1955-
->Set(context,
1956-
FIXED_ONE_BYTE_STRING(isolate, "usages"),
1955+
->Set(context, env->usages_string(),
19571956
Uint32::NewFromUnsigned(isolate, usages_mask_))
19581957
.IsNothing() ||
19591958
bundle
1960-
->Set(context,
1961-
FIXED_ONE_BYTE_STRING(isolate, "extractable"),
1959+
->Set(context, env->extractable_string(),
19621960
v8::Boolean::New(isolate, extractable_))
19631961
.IsNothing()) {
19641962
return Nothing<bool>();
@@ -1984,7 +1982,7 @@ BaseObjectPtr<BaseObject> NativeCryptoKey::CryptoKeyTransferData::Deserialize(
19841982
// Make sure internal/crypto/keys has been loaded so that the
19851983
// CryptoKey constructor is registered with the Environment.
19861984
Isolate* isolate = env->isolate();
1987-
Local<Value> arg = FIXED_ONE_BYTE_STRING(isolate, "internal/crypto/keys");
1985+
Local<Value> arg = env->internal_crypto_keys_string();
19881986
if (env->builtin_module_require()
19891987
->Call(context, Null(isolate), 1, &arg)
19901988
.IsEmpty()) {

src/crypto/crypto_util.cc

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

255255
// The last error in the list is the one that will be used as the
@@ -761,11 +761,9 @@ MaybeLocal<Value> CreateWebCryptoJobError(Environment* env,
761761

762762
Local<Object> options = Object::New(isolate);
763763
if (options
764-
->Set(context,
765-
FIXED_ONE_BYTE_STRING(isolate, "name"),
766-
FIXED_ONE_BYTE_STRING(isolate, "OperationError"))
764+
->Set(context, env->name_string(), env->operationerror_string())
767765
.IsNothing() ||
768-
options->Set(context, FIXED_ONE_BYTE_STRING(isolate, "cause"), cause)
766+
options->Set(context, env->cause_string(), cause)
769767
.IsNothing()) {
770768
return {};
771769
}

src/crypto/crypto_util.h

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

src/dtls/dtls_session.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ void DTLSSession::GetCipher(const FunctionCallbackInfo<Value>& args) {
541541

542542
Local<Object> info = Object::New(env->isolate());
543543
info->Set(env->context(),
544-
FIXED_ONE_BYTE_STRING(env->isolate(), "name"),
544+
env->name_string(),
545545
String::NewFromUtf8(env->isolate(), SSL_CIPHER_get_name(cipher))
546546
.ToLocalChecked())
547547
.Check();
@@ -552,7 +552,7 @@ void DTLSSession::GetCipher(const FunctionCallbackInfo<Value>& args) {
552552
.ToLocalChecked())
553553
.Check();
554554
info->Set(env->context(),
555-
FIXED_ONE_BYTE_STRING(env->isolate(), "version"),
555+
env->version_string(),
556556
String::NewFromUtf8(env->isolate(), SSL_CIPHER_get_version(cipher))
557557
.ToLocalChecked())
558558
.Check();

src/env_properties.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
V(__dirname_string, "__dirname") \
8383
V(ack_string, "ack") \
8484
V(address_string, "address") \
85+
V(algorithm_string, "algorithm") \
8586
V(aliases_string, "aliases") \
8687
V(allow_bare_named_params_string, "allowBareNamedParameters") \
8788
V(allow_unknown_named_params_string, "allowUnknownNamedParameters") \
@@ -93,13 +94,15 @@
9394
V(backup_string, "backup") \
9495
V(base_string, "base") \
9596
V(base_url_string, "baseURL") \
97+
V(brotli_string, "brotli") \
9698
V(buffer_string, "buffer") \
9799
V(bytes_parsed_string, "bytesParsed") \
98100
V(bytes_read_string, "bytesRead") \
99101
V(bytes_written_string, "bytesWritten") \
100102
V(cached_data_produced_string, "cachedDataProduced") \
101103
V(cached_data_rejected_string, "cachedDataRejected") \
102104
V(cached_data_string, "cachedData") \
105+
V(cause_string, "cause") \
103106
V(change_string, "change") \
104107
V(changes_string, "changes") \
105108
V(chunks_sent_since_last_write_string, "chunksSentSinceLastWrite") \
@@ -180,6 +183,7 @@
180183
V(exponent_string, "exponent") \
181184
V(exports_string, "exports") \
182185
V(external_stream_string, "_externalStream") \
186+
V(extractable_string, "extractable") \
183187
V(family_string, "family") \
184188
V(fatal_exception_string, "_fatalException") \
185189
V(fd_string, "fd") \
@@ -215,6 +219,7 @@
215219
V(ignore_string, "ignore") \
216220
V(inherit_string, "inherit") \
217221
V(input_string, "input") \
222+
V(internal_crypto_keys_string, "internal/crypto/keys") \
218223
V(inverse_string, "inverse") \
219224
V(ipv4_string, "IPv4") \
220225
V(ipv6_string, "IPv6") \
@@ -264,6 +269,7 @@
264269
V(node_string, "node") \
265270
V(object_string, "Object") \
266271
V(ocsp_request_string, "OCSPRequest") \
272+
V(ok_string, "ok") \
267273
V(oncertcb_string, "oncertcb") \
268274
V(onchange_string, "onchange") \
269275
V(onclienthello_string, "onclienthello") \
@@ -287,10 +293,14 @@
287293
V(onwrite_string, "onwrite") \
288294
V(ongracefulclosecomplete_string, "ongracefulclosecomplete") \
289295
V(openssl_error_stack, "opensslErrorStack") \
296+
V(operationerror_string, "OperationError") \
290297
V(options_string, "options") \
291298
V(original_string, "original") \
292299
V(output_string, "output") \
293300
V(overlapped_string, "overlapped") \
301+
V(p256_string, "P-256") \
302+
V(p384_string, "P-384") \
303+
V(p521_string, "P-521") \
294304
V(parse_error_string, "Parse Error") \
295305
V(password_string, "password") \
296306
V(path_string, "path") \
@@ -333,6 +343,7 @@
333343
V(return_arrays_string, "returnArrays") \
334344
V(return_string, "return") \
335345
V(salt_length_string, "saltLength") \
346+
V(secp256k1_string, "secp256k1") \
336347
V(search_string, "search") \
337348
V(servername_string, "servername") \
338349
V(session_id_string, "sessionId") \
@@ -361,6 +372,7 @@
361372
V(syscall_string, "syscall") \
362373
V(table_string, "table") \
363374
V(target_string, "target") \
375+
V(then_string, "then") \
364376
V(thread_id_string, "threadId") \
365377
V(thread_name_string, "threadName") \
366378
V(tls_group_string, "TLSGroup") \
@@ -379,6 +391,7 @@
379391
V(uid_string, "uid") \
380392
V(unknown_string, "<unknown>") \
381393
V(url_string, "url") \
394+
V(usages_string, "usages") \
382395
V(username_string, "username") \
383396
V(value_string, "value") \
384397
V(verify_error_string, "verifyError") \
@@ -388,7 +401,9 @@
388401
V(wrap_string, "wrap") \
389402
V(writable_string, "writable") \
390403
V(write_host_object_string, "_writeHostObject") \
391-
V(write_queue_size_string, "writeQueueSize")
404+
V(write_queue_size_string, "writeQueueSize") \
405+
V(zlib_string, "zlib") \
406+
V(zstd_string, "zstd")
392407

393408
#define PER_ISOLATE_TEMPLATE_PROPERTIES(V) \
394409
V(a_record_template, v8::DictionaryTemplate) \

src/node_ffi.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ Local<FunctionTemplate> DynamicLibrary::GetConstructorTemplate(
11731173
DynamicLibrary::kInternalFieldCount);
11741174

11751175
tmpl->InstanceTemplate()->SetAccessorProperty(
1176-
FIXED_ONE_BYTE_STRING(isolate, "path"),
1176+
env->path_string(),
11771177
FunctionTemplate::New(env->isolate(), DynamicLibrary::GetPath),
11781178
Local<FunctionTemplate>(),
11791179
attributes);

src/permission/permission.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ bool Permission::is_scope_granted(Environment* env,
257257
v8::Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0);
258258
const char* perm_str = PermissionToString(permission);
259259
msg->Set(context,
260-
FIXED_ONE_BYTE_STRING(isolate, "permission"),
260+
env->permission_string(),
261261
v8::String::NewFromUtf8(isolate, perm_str).ToLocalChecked())
262262
.Check();
263263
msg->Set(context,
264-
FIXED_ONE_BYTE_STRING(isolate, "resource"),
264+
env->resource_string(),
265265
v8::String::NewFromUtf8(isolate,
266266
res.data(),
267267
v8::NewStringType::kNormal,
@@ -327,11 +327,11 @@ void Permission::Drop(Environment* env,
327327
v8::Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0);
328328
const char* perm_str = PermissionToString(scope);
329329
msg->Set(context,
330-
FIXED_ONE_BYTE_STRING(isolate, "permission"),
330+
env->permission_string(),
331331
v8::String::NewFromUtf8(isolate, perm_str).ToLocalChecked())
332332
.Check();
333333
msg->Set(context,
334-
FIXED_ONE_BYTE_STRING(isolate, "resource"),
334+
env->resource_string(),
335335
v8::String::NewFromUtf8(isolate,
336336
param.data(),
337337
v8::NewStringType::kNormal,

0 commit comments

Comments
 (0)