chore: add error throwing utility (#19803)

* chore: add error throwing utility

* feedback from review

* DRY out repeated isolate calls
This commit is contained in:
Shelley Vohr 2019-08-19 09:10:18 -07:00 committed by GitHub
parent 8f1c51eaea
commit 43e6d7fe88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 118 additions and 4 deletions

View file

@ -12,6 +12,7 @@
#include "base/values.h"
#include "native_mate/handle.h"
#include "shell/browser/api/event_emitter.h"
#include "shell/common/error_util.h"
#include "shell/common/promise_util.h"
#if defined(OS_WIN)
@ -95,7 +96,8 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
void RemoveUserDefault(const std::string& name);
bool IsSwipeTrackingFromScrollEventsEnabled();
std::string GetSystemColor(const std::string& color, mate::Arguments* args);
std::string GetSystemColor(util::ErrorThrower thrower,
const std::string& color);
bool CanPromptTouchID();
v8::Local<v8::Promise> PromptTouchID(v8::Isolate* isolate,

View file

@ -405,8 +405,8 @@ std::string SystemPreferences::GetAccentColor() {
return base::SysNSStringToUTF8([sysColor RGBAValue]);
}
std::string SystemPreferences::GetSystemColor(const std::string& color,
mate::Arguments* args) {
std::string SystemPreferences::GetSystemColor(util::ErrorThrower thrower,
const std::string& color) {
NSColor* sysColor = nil;
if (color == "blue") {
sysColor = [NSColor systemBlueColor];
@ -427,7 +427,7 @@ std::string SystemPreferences::GetSystemColor(const std::string& color,
} else if (color == "yellow") {
sysColor = [NSColor systemYellowColor];
} else {
args->ThrowError("Unknown system color: " + color);
thrower.ThrowError("Unknown system color: " + color);
return "";
}