diff options
author | Simon Menke <simon.menke@gmail.com> | 2019-03-21 14:48:19 +0100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-03-21 09:48:19 -0400 |
commit | 93793dc45504fcc7927354c7e4f39d6de406e9d4 (patch) | |
tree | 76b17e593142147d67d039704eca0001364cf82c /libdeno/exceptions.cc | |
parent | 94405bb61722142e8c4d90bb5f31038fc9aa5f72 (diff) |
core: Allow terminating an Isolate from another thread (#1982)
Diffstat (limited to 'libdeno/exceptions.cc')
-rw-r--r-- | libdeno/exceptions.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libdeno/exceptions.cc b/libdeno/exceptions.cc index 51f81bfce..85f0ca340 100644 --- a/libdeno/exceptions.cc +++ b/libdeno/exceptions.cc @@ -174,6 +174,25 @@ std::string EncodeExceptionAsJSON(v8::Local<v8::Context> context, void HandleException(v8::Local<v8::Context> context, v8::Local<v8::Value> exception) { v8::Isolate* isolate = context->GetIsolate(); + + // TerminateExecution was called + if (isolate->IsExecutionTerminating()) { + // cancel exception termination so that the exception can be created + isolate->CancelTerminateExecution(); + + // maybe make a new exception object + if (exception->IsNullOrUndefined()) { + exception = v8::Exception::Error(v8_str("execution terminated")); + } + + // handle the exception as if it is a regular exception + HandleException(context, exception); + + // re-enable exception termination + isolate->TerminateExecution(); + return; + } + DenoIsolate* d = DenoIsolate::FromIsolate(isolate); std::string json_str = EncodeExceptionAsJSON(context, exception); CHECK_NOT_NULL(d); @@ -183,6 +202,13 @@ void HandleException(v8::Local<v8::Context> context, void HandleExceptionMessage(v8::Local<v8::Context> context, v8::Local<v8::Message> message) { v8::Isolate* isolate = context->GetIsolate(); + + // TerminateExecution was called + if (isolate->IsExecutionTerminating()) { + HandleException(context, v8::Undefined(isolate)); + return; + } + DenoIsolate* d = DenoIsolate::FromIsolate(isolate); std::string json_str = EncodeMessageAsJSON(context, message); CHECK_NOT_NULL(d); |