mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
src: use custom TryCatch subclass
PR-URL: https://github.com/nodejs/node/pull/24751 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
@@ -14,8 +14,6 @@
|
||||
|
||||
namespace node {
|
||||
|
||||
void DecorateErrorStack(Environment* env, const v8::TryCatch& try_catch);
|
||||
|
||||
enum ErrorHandlingMode { CONTEXTIFY_ERROR, FATAL_ERROR, MODULE_ERROR };
|
||||
void AppendExceptionLine(Environment* env,
|
||||
v8::Local<v8::Value> er,
|
||||
@@ -167,6 +165,35 @@ inline v8::Local<v8::Value> ERR_STRING_TOO_LONG(v8::Isolate* isolate) {
|
||||
prefix " must be a string"); \
|
||||
} while (0)
|
||||
|
||||
namespace errors {
|
||||
|
||||
class TryCatchScope : public v8::TryCatch {
|
||||
public:
|
||||
enum class CatchMode { kNormal, kFatal };
|
||||
|
||||
explicit TryCatchScope(Environment* env, CatchMode mode = CatchMode::kNormal)
|
||||
: v8::TryCatch(env->isolate()), env_(env), mode_(mode) {}
|
||||
~TryCatchScope();
|
||||
|
||||
// Since the dtor is not virtual we need to make sure no one creates
|
||||
// object of it in the free store that might be held by polymorphic pointers.
|
||||
void* operator new(std::size_t count) = delete;
|
||||
void* operator new[](std::size_t count) = delete;
|
||||
TryCatchScope(TryCatchScope&) = delete;
|
||||
TryCatchScope(TryCatchScope&&) = delete;
|
||||
TryCatchScope operator=(TryCatchScope&) = delete;
|
||||
TryCatchScope operator=(TryCatchScope&&) = delete;
|
||||
|
||||
private:
|
||||
Environment* env_;
|
||||
CatchMode mode_;
|
||||
};
|
||||
|
||||
} // namespace errors
|
||||
|
||||
void DecorateErrorStack(Environment* env,
|
||||
const errors::TryCatchScope& try_catch);
|
||||
|
||||
} // namespace node
|
||||
|
||||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
|
||||
Reference in New Issue
Block a user