2019-09-06 05:52:54 +00:00
|
|
|
// Copyright (c) 2019 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_
|
|
|
|
#define ELECTRON_SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_
|
2019-09-06 05:52:54 +00:00
|
|
|
|
|
|
|
#include "base/strings/string_piece.h"
|
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
|
|
|
namespace gin_helper {
|
|
|
|
|
|
|
|
class ErrorThrower {
|
|
|
|
public:
|
|
|
|
explicit ErrorThrower(v8::Isolate* isolate);
|
|
|
|
ErrorThrower();
|
2021-06-01 04:00:09 +00:00
|
|
|
~ErrorThrower() = default;
|
2019-09-06 05:52:54 +00:00
|
|
|
|
2021-04-12 23:35:18 +00:00
|
|
|
void ThrowError(base::StringPiece err_msg) const;
|
|
|
|
void ThrowTypeError(base::StringPiece err_msg) const;
|
|
|
|
void ThrowRangeError(base::StringPiece err_msg) const;
|
|
|
|
void ThrowReferenceError(base::StringPiece err_msg) const;
|
|
|
|
void ThrowSyntaxError(base::StringPiece err_msg) const;
|
2019-09-06 05:52:54 +00:00
|
|
|
|
|
|
|
v8::Isolate* isolate() const { return isolate_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
using ErrorGenerator =
|
|
|
|
v8::Local<v8::Value> (*)(v8::Local<v8::String> err_msg);
|
2021-04-12 23:35:18 +00:00
|
|
|
void Throw(ErrorGenerator gen, base::StringPiece err_msg) const;
|
2019-09-06 05:52:54 +00:00
|
|
|
|
|
|
|
v8::Isolate* isolate_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gin_helper
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_
|