From 0e95c5a35f719559c56f56783fd4a435a3587e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 25 Feb 2023 21:36:13 +0000 Subject: [PATCH] src: fix useless call in permission.cc FromMaybe() has no side effects and the return value is ignored. Instead, if Set() fails, then another exception is pending, so return early. --- src/permission/permission.cc | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/permission/permission.cc b/src/permission/permission.cc index c156133e64a13d..f92dd7e03ff1e7 100644 --- a/src/permission/permission.cc +++ b/src/permission/permission.cc @@ -136,22 +136,23 @@ void Permission::ThrowAccessDenied(Environment* env, const std::string_view& res) { Local err = ERR_ACCESS_DENIED(env->isolate()); CHECK(err->IsObject()); - err.As() - ->Set(env->context(), - env->permission_string(), - v8::String::NewFromUtf8(env->isolate(), - PermissionToString(perm), - v8::NewStringType::kNormal) - .ToLocalChecked()) - .FromMaybe(false); - err.As() - ->Set(env->context(), - env->resource_string(), - v8::String::NewFromUtf8(env->isolate(), - std::string(res).c_str(), - v8::NewStringType::kNormal) - .ToLocalChecked()) - .FromMaybe(false); + if (err.As() + ->Set(env->context(), + env->permission_string(), + v8::String::NewFromUtf8(env->isolate(), + PermissionToString(perm), + v8::NewStringType::kNormal) + .ToLocalChecked()) + .IsNothing() || + err.As() + ->Set(env->context(), + env->resource_string(), + v8::String::NewFromUtf8(env->isolate(), + std::string(res).c_str(), + v8::NewStringType::kNormal) + .ToLocalChecked()) + .IsNothing()) + return; env->isolate()->ThrowException(err); }