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
|
|
|
|
2024-01-11 01:00:37 +00:00
|
|
|
#include <string_view>
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2024-07-29 17:42:57 +00:00
|
|
|
#include "v8/include/v8-forward.h"
|
2019-09-06 05:52:54 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2024-01-11 01:00:37 +00:00
|
|
|
void ThrowError(std::string_view err_msg) const;
|
|
|
|
void ThrowTypeError(std::string_view err_msg) const;
|
|
|
|
void ThrowRangeError(std::string_view err_msg) const;
|
|
|
|
void ThrowReferenceError(std::string_view err_msg) const;
|
|
|
|
void ThrowSyntaxError(std::string_view err_msg) const;
|
2019-09-06 05:52:54 +00:00
|
|
|
|
|
|
|
v8::Isolate* isolate() const { return isolate_; }
|
|
|
|
|
|
|
|
private:
|
2023-10-02 22:01:07 +00:00
|
|
|
using ErrorGenerator = v8::Local<v8::Value> (*)(v8::Local<v8::String> err_msg,
|
|
|
|
v8::Local<v8::Value> options);
|
2024-01-11 01:00:37 +00:00
|
|
|
void Throw(ErrorGenerator gen, std::string_view err_msg) const;
|
2019-09-06 05:52:54 +00:00
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<v8::Isolate> isolate_;
|
2019-09-06 05:52:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gin_helper
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_COMMON_GIN_HELPER_ERROR_THROWER_H_
|