Skip to content

Commit

Permalink
src: fix useless call in permission.cc
Browse files Browse the repository at this point in the history
FromMaybe() has no side effects and the return value is ignored.
Instead, if Set() fails, then another exception is pending, so
return early.

PR-URL: #46833
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
tniessen authored Feb 27, 2023
1 parent d610096 commit 3abbc38
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/permission/permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,23 @@ void Permission::ThrowAccessDenied(Environment* env,
const std::string_view& res) {
Local<Value> err = ERR_ACCESS_DENIED(env->isolate());
CHECK(err->IsObject());
err.As<Object>()
->Set(env->context(),
env->permission_string(),
v8::String::NewFromUtf8(env->isolate(),
PermissionToString(perm),
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromMaybe(false);
err.As<Object>()
->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<Object>()
->Set(env->context(),
env->permission_string(),
v8::String::NewFromUtf8(env->isolate(),
PermissionToString(perm),
v8::NewStringType::kNormal)
.ToLocalChecked())
.IsNothing() ||
err.As<Object>()
->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);
}

Expand Down

0 comments on commit 3abbc38

Please sign in to comment.