Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/crypto/crypto_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2247,12 +2247,9 @@ void SecureContext::GetCertificateCompressionAlgorithms(
Environment* env = Environment::GetCurrent(args);
LocalVector<Value> 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()));
Expand Down
8 changes: 4 additions & 4 deletions src/crypto/crypto_ec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,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(
Expand Down
25 changes: 10 additions & 15 deletions src/crypto/crypto_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1686,8 +1686,7 @@ BaseObjectPtr<BaseObject> NativeKeyObject::KeyObjectTransferData::Deserialize(
return {};

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

if (env->crypto_internal_cryptokey_constructor().IsEmpty()) {
Local<Value> arg = FIXED_ONE_BYTE_STRING(isolate, "internal/crypto/keys");
Local<Value> arg = env->internal_crypto_keys_string();
if (env->builtin_module_require()
->Call(context, Null(isolate), 1, &arg)
.IsEmpty()) {
Expand Down Expand Up @@ -1915,23 +1914,21 @@ Maybe<void> NativeCryptoKey::FinalizeTransferRead(
CHECK(obj->GetInternalField(kAlgorithmField).As<Value>()->IsUndefined());

Local<Value> 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<void>();
}
CHECK(algorithm_v->IsObject());
obj->SetInternalField(kAlgorithmField, algorithm_v);

Local<Value> 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<void>();
}
CHECK(usages_v->IsUint32());
usages_mask_ = usages_v.As<Uint32>()->Value();

Local<Value> extractable_v;
if (!bundle->Get(context, FIXED_ONE_BYTE_STRING(isolate, "extractable"))
if (!bundle->Get(context, env()->extractable_string())
.ToLocal(&extractable_v)) {
return Nothing<void>();
}
Expand All @@ -1944,21 +1941,19 @@ Maybe<void> NativeCryptoKey::FinalizeTransferRead(
Maybe<bool> NativeCryptoKey::CryptoKeyTransferData::FinalizeTransferWrite(
Local<Context> context, v8::ValueSerializer* serializer) {
Isolate* isolate = Isolate::GetCurrent();
Environment* env = Environment::GetCurrent(isolate);
CHECK(!algorithm_.IsEmpty());
Local<Object> bundle = Object::New(isolate);
Local<Value> 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<bool>();
Expand All @@ -1984,7 +1979,7 @@ BaseObjectPtr<BaseObject> 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<Value> arg = FIXED_ONE_BYTE_STRING(isolate, "internal/crypto/keys");
Local<Value> arg = env->internal_crypto_keys_string();
if (env->builtin_module_require()
->Call(context, Null(isolate), 1, &arg)
.IsEmpty()) {
Expand Down
10 changes: 3 additions & 7 deletions src/crypto/crypto_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ MaybeLocal<Value> 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
Expand Down Expand Up @@ -760,13 +760,9 @@ MaybeLocal<Value> CreateWebCryptoJobError(Environment* env,
CHECK(domexception_ctor->IsFunction());

Local<Object> 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 {};
}

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,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<v8::Object> object = value.As<v8::Object>();
v8::Maybe<bool> has_own_then =
object->HasOwnProperty(context, then_key);
Expand Down
4 changes: 2 additions & 2 deletions src/dtls/dtls_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ void DTLSSession::GetCipher(const FunctionCallbackInfo<Value>& args) {

Local<Object> 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();
Expand All @@ -552,7 +552,7 @@ void DTLSSession::GetCipher(const FunctionCallbackInfo<Value>& 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();
Expand Down
17 changes: 16 additions & 1 deletion src/env_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -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") \
Expand All @@ -93,13 +94,15 @@
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") \
V(bytes_written_string, "bytesWritten") \
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") \
Expand Down Expand Up @@ -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") \
Expand Down Expand Up @@ -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") \
Expand Down Expand Up @@ -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") \
Expand All @@ -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") \
Expand Down Expand Up @@ -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") \
Expand Down Expand Up @@ -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") \
Expand All @@ -379,6 +391,7 @@
V(uid_string, "uid") \
V(unknown_string, "<unknown>") \
V(url_string, "url") \
V(usages_string, "usages") \
V(username_string, "username") \
V(value_string, "value") \
V(verify_error_string, "verifyError") \
Expand All @@ -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) \
Expand Down
2 changes: 1 addition & 1 deletion src/node_ffi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ Local<FunctionTemplate> DynamicLibrary::GetConstructorTemplate(
DynamicLibrary::kInternalFieldCount);

tmpl->InstanceTemplate()->SetAccessorProperty(
FIXED_ONE_BYTE_STRING(isolate, "path"),
env->path_string(),
FunctionTemplate::New(env->isolate(), DynamicLibrary::GetPath),
Local<FunctionTemplate>(),
attributes);
Expand Down
8 changes: 4 additions & 4 deletions src/permission/permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,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,
Expand Down Expand Up @@ -327,11 +327,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,
Expand Down
Loading