Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ce5c6c9

Browse files
committedOct 8, 2020
src: remove toLocalChecked in crypto_context
Signed-off-by: James M Snell <jasnell@gmail.com>
1 parent e409e1b commit ce5c6c9

File tree

1 file changed

+58
-36
lines changed

1 file changed

+58
-36
lines changed
 

‎src/crypto/crypto_context.cc

+58-36
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ namespace node {
2121

2222
using v8::Array;
2323
using v8::ArrayBufferView;
24-
using v8::Boolean;
2524
using v8::Context;
2625
using v8::DontDelete;
2726
using v8::Exception;
@@ -551,7 +550,9 @@ void SecureContext::SetEngineKey(const FunctionCallbackInfo<Value>& args) {
551550
const Utf8Value engine_id(env->isolate(), args[1]);
552551
EnginePointer engine = LoadEngineById(*engine_id, &errors);
553552
if (!engine) {
554-
env->isolate()->ThrowException(errors.ToException(env).ToLocalChecked());
553+
Local<Value> exception;
554+
if (errors.ToException(env).ToLocal(&exception))
555+
env->isolate()->ThrowException(exception);
555556
return;
556557
}
557558

@@ -1061,7 +1062,9 @@ void SecureContext::SetClientCertEngine(
10611062
const node::Utf8Value engine_id(env->isolate(), args[0]);
10621063
EnginePointer engine = LoadEngineById(*engine_id, &errors);
10631064
if (!engine) {
1064-
env->isolate()->ThrowException(errors.ToException(env).ToLocalChecked());
1065+
Local<Value> exception;
1066+
if (errors.ToException(env).ToLocal(&exception))
1067+
env->isolate()->ThrowException(exception);
10651068
return;
10661069
}
10671070

@@ -1079,7 +1082,10 @@ void SecureContext::GetTicketKeys(const FunctionCallbackInfo<Value>& args) {
10791082
SecureContext* wrap;
10801083
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
10811084

1082-
Local<Object> buff = Buffer::New(wrap->env(), 48).ToLocalChecked();
1085+
Local<Object> buff;
1086+
if (!Buffer::New(wrap->env(), 48).ToLocal(&buff))
1087+
return;
1088+
10831089
memcpy(Buffer::Data(buff), wrap->ticket_key_name_, 16);
10841090
memcpy(Buffer::Data(buff) + 16, wrap->ticket_key_hmac_, 16);
10851091
memcpy(Buffer::Data(buff) + 32, wrap->ticket_key_aes_, 16);
@@ -1143,45 +1149,59 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
11431149
HandleScope handle_scope(env->isolate());
11441150
Context::Scope context_scope(env->context());
11451151

1146-
Local<Value> argv[] = {
1147-
Buffer::Copy(env,
1148-
reinterpret_cast<char*>(name),
1149-
kTicketPartSize).ToLocalChecked(),
1150-
Buffer::Copy(env,
1151-
reinterpret_cast<char*>(iv),
1152-
kTicketPartSize).ToLocalChecked(),
1153-
Boolean::New(env->isolate(), enc != 0)
1154-
};
1155-
1156-
Local<Value> ret = node::MakeCallback(env->isolate(),
1157-
sc->object(),
1158-
env->ticketkeycallback_string(),
1159-
arraysize(argv),
1160-
argv,
1161-
{0, 0}).ToLocalChecked();
1152+
Local<Value> argv[3];
1153+
1154+
if (!Buffer::Copy(
1155+
env,
1156+
reinterpret_cast<char*>(name),
1157+
kTicketPartSize).ToLocal(&argv[0]) ||
1158+
!Buffer::Copy(
1159+
env,
1160+
reinterpret_cast<char*>(iv),
1161+
kTicketPartSize).ToLocal(&argv[1])) {
1162+
return -1;
1163+
}
1164+
1165+
argv[2] = env != 0 ? v8::True(env->isolate()) : v8::False(env->isolate());
1166+
1167+
Local<Value> ret;
1168+
if (!node::MakeCallback(
1169+
env->isolate(),
1170+
sc->object(),
1171+
env->ticketkeycallback_string(),
1172+
arraysize(argv),
1173+
argv,
1174+
{0, 0}).ToLocal(&ret) ||
1175+
!ret->IsArray()) {
1176+
return -1;
1177+
}
11621178
Local<Array> arr = ret.As<Array>();
11631179

1164-
int r =
1165-
arr->Get(env->context(),
1166-
kTicketKeyReturnIndex).ToLocalChecked()
1167-
->Int32Value(env->context()).FromJust();
1180+
Local<Value> val;
1181+
if (!arr->Get(env->context(), kTicketKeyReturnIndex).ToLocal(&val) ||
1182+
!val->IsInt32()) {
1183+
return -1;
1184+
}
1185+
1186+
int r = val.As<Int32>()->Value();
11681187
if (r < 0)
11691188
return r;
11701189

1171-
Local<Value> hmac = arr->Get(env->context(),
1172-
kTicketKeyHMACIndex).ToLocalChecked();
1173-
Local<Value> aes = arr->Get(env->context(),
1174-
kTicketKeyAESIndex).ToLocalChecked();
1175-
if (Buffer::Length(aes) != kTicketPartSize)
1190+
Local<Value> hmac;
1191+
Local<Value> aes;
1192+
1193+
if (!arr->Get(env->context(), kTicketKeyHMACIndex).ToLocal(&hmac) ||
1194+
!arr->Get(env->context(), kTicketKeyAESIndex).ToLocal(&aes) ||
1195+
Buffer::Length(aes) != kTicketPartSize) {
11761196
return -1;
1197+
}
11771198

11781199
if (enc) {
1179-
Local<Value> name_val = arr->Get(env->context(),
1180-
kTicketKeyNameIndex).ToLocalChecked();
1181-
Local<Value> iv_val = arr->Get(env->context(),
1182-
kTicketKeyIVIndex).ToLocalChecked();
1183-
1184-
if (Buffer::Length(name_val) != kTicketPartSize ||
1200+
Local<Value> name_val;
1201+
Local<Value> iv_val;
1202+
if (!arr->Get(env->context(), kTicketKeyNameIndex).ToLocal(&name_val) ||
1203+
!arr->Get(env->context(), kTicketKeyIVIndex).ToLocal(&iv_val) ||
1204+
Buffer::Length(name_val) != kTicketPartSize ||
11851205
Buffer::Length(iv_val) != kTicketPartSize) {
11861206
return -1;
11871207
}
@@ -1272,7 +1292,9 @@ void SecureContext::GetCertificate(const FunctionCallbackInfo<Value>& args) {
12721292
return args.GetReturnValue().SetNull();
12731293

12741294
int size = i2d_X509(cert, nullptr);
1275-
Local<Object> buff = Buffer::New(env, size).ToLocalChecked();
1295+
Local<Object> buff;
1296+
if (!Buffer::New(env, size).ToLocal(&buff))
1297+
return;
12761298
unsigned char* serialized = reinterpret_cast<unsigned char*>(
12771299
Buffer::Data(buff));
12781300
i2d_X509(cert, &serialized);

0 commit comments

Comments
 (0)
Please sign in to comment.