diff options
author | Gus Caplan <me@gus.host> | 2018-11-30 17:13:45 +0300 |
---|---|---|
committer | Gus Caplan <me@gus.host> | 2018-12-03 19:25:06 +0300 |
commit | f084e06de7b03750a80925a7aa1aefe3aed47504 (patch) | |
tree | a014956efe76cd2c1273811eb5efd4d30f784b94 /src/node_errors.h | |
parent | dbdc9081fa723f62126ef857ee9365425e41dd9f (diff) |
src: use custom TryCatch subclass
PR-URL: https://github.com/nodejs/node/pull/24751
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/node_errors.h')
-rw-r--r-- | src/node_errors.h | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/node_errors.h b/src/node_errors.h index 44dc1d8094f..7638ff4251f 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -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 |