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:
Gus Caplan
2018-11-30 08:13:45 -06:00
parent dbdc9081fa
commit f084e06de7
10 changed files with 116 additions and 75 deletions

View File

@@ -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