From 93793dc45504fcc7927354c7e4f39d6de406e9d4 Mon Sep 17 00:00:00 2001 From: Simon Menke Date: Thu, 21 Mar 2019 14:48:19 +0100 Subject: core: Allow terminating an Isolate from another thread (#1982) --- libdeno/exceptions.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'libdeno/exceptions.cc') 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 context, void HandleException(v8::Local context, v8::Local 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 context, void HandleExceptionMessage(v8::Local context, v8::Local 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); -- cgit v1.2.3