2c23e44ed9
* use gin converter in atom_api_menu * please only put necessary includes in header Having include in header means they have dependency relationship, putting arbitrary includes really really really really really makes refacoring much harder. * remove some simple uses of callback_converter_deprecated.h * use gin callback converter in file_dialog code * use gin in ErrorThrower * use gin in atom_bundle_mover * fix mistake in node stream * deprecate native_mate version of event_emitter_caller * use gin in node_bindings * remove usages of native_mate event_emitter_caller.h except for EventEmitter * fix compilation on Windows * gin::Arguments behaves differently on GetNext * just use StringToV8
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
// Copyright (c) 2019 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/common/gin_helper/error_thrower.h"
|
|
|
|
#include "gin/converter.h"
|
|
|
|
namespace gin_helper {
|
|
|
|
ErrorThrower::ErrorThrower(v8::Isolate* isolate) : isolate_(isolate) {}
|
|
|
|
// This constructor should be rarely if ever used, since
|
|
// v8::Isolate::GetCurrent() uses atomic loads and is thus a bit
|
|
// costly to invoke
|
|
ErrorThrower::ErrorThrower() : isolate_(v8::Isolate::GetCurrent()) {}
|
|
|
|
ErrorThrower::~ErrorThrower() = default;
|
|
|
|
void ErrorThrower::ThrowError(base::StringPiece err_msg) {
|
|
Throw(v8::Exception::Error, err_msg);
|
|
}
|
|
|
|
void ErrorThrower::ThrowTypeError(base::StringPiece err_msg) {
|
|
Throw(v8::Exception::TypeError, err_msg);
|
|
}
|
|
|
|
void ErrorThrower::ThrowRangeError(base::StringPiece err_msg) {
|
|
Throw(v8::Exception::RangeError, err_msg);
|
|
}
|
|
|
|
void ErrorThrower::ThrowReferenceError(base::StringPiece err_msg) {
|
|
Throw(v8::Exception::ReferenceError, err_msg);
|
|
}
|
|
|
|
void ErrorThrower::ThrowSyntaxError(base::StringPiece err_msg) {
|
|
Throw(v8::Exception::SyntaxError, err_msg);
|
|
}
|
|
|
|
void ErrorThrower::Throw(ErrorGenerator gen, base::StringPiece err_msg) {
|
|
v8::Local<v8::Value> exception = gen(gin::StringToV8(isolate_, err_msg));
|
|
if (!isolate_->IsExecutionTerminating())
|
|
isolate_->ThrowException(exception);
|
|
}
|
|
|
|
} // namespace gin_helper
|