| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8234d04 commit cd233e3
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | #include "diagnosticfilename-inl.h" | |
| 5 | 5 | #include "memory_tracker-inl.h" | |
| 6 | 6 | #include "node_file.h" | |
| 7 | + #include "node_errors.h" | ||
| 7 | 8 | #include "node_internals.h" | |
| 8 | 9 | #include "util-inl.h" | |
| 9 | 10 | #include "v8-inspector.h" | |
@@ -13,6 +14,7 @@ | |||
| 13 | 14 | namespace node { | |
| 14 | 15 | namespace profiler { | |
| 15 | 16 | ||
| 17 | + using errors::TryCatchScope; | ||
| 16 | 18 | using v8::Context; | |
| 17 | 19 | using v8::Function; | |
| 18 | 20 | using v8::FunctionCallbackInfo; | |
@@ -219,12 +221,21 @@ void V8CoverageConnection::WriteProfile(Local<String> message) { | |||
| 219 | 221 | } | |
| 220 | 222 | ||
| 221 | 223 | // append source-map cache information to coverage object: | |
| 222 | - Local<Function> source_map_cache_getter = env_->source_map_cache_getter(); | ||
| 223 | 224 | Local<Value> source_map_cache_v; | |
| 224 | - if (!source_map_cache_getter->Call(env()->context(), | ||
| 225 | - Undefined(isolate), 0, nullptr) | ||
| 226 | - .ToLocal(&source_map_cache_v)) { | ||
| 227 | - return; | ||
| 225 | + { | ||
| 226 | + TryCatchScope try_catch(env()); | ||
| 227 | + { | ||
| 228 | + Isolate::AllowJavascriptExecutionScope allow_js_here(isolate); | ||
| 229 | + Local<Function> source_map_cache_getter = env_->source_map_cache_getter(); | ||
| 230 | + if (!source_map_cache_getter->Call( | ||
| 231 | + context, Undefined(isolate), 0, nullptr) | ||
| 232 | + .ToLocal(&source_map_cache_v)) { | ||
| 233 | + return; | ||
| 234 | + } | ||
| 235 | + } | ||
| 236 | + if (try_catch.HasCaught() && !try_catch.HasTerminated()) { | ||
| 237 | + PrintCaughtException(isolate, context, try_catch); | ||
| 238 | + } | ||
| 228 | 239 | } | |
| 229 | 240 | // Avoid writing to disk if no source-map data: | |
| 230 | 241 | if (!source_map_cache_v->IsUndefined()) { | |
@@ -351,7 +362,7 @@ void V8HeapProfilerConnection::End() { | |||
| 351 | 362 | ||
| 352 | 363 | // For now, we only support coverage profiling, but we may add more | |
| 353 | 364 | // in the future. | |
| 354 | - void EndStartedProfilers(Environment* env) { | ||
| 365 | + static void EndStartedProfilers(Environment* env) { | ||
| 355 | 366 | Debug(env, DebugCategory::INSPECTOR_PROFILER, "EndStartedProfilers\n"); | |
| 356 | 367 | V8ProfilerConnection* connection = env->cpu_profiler_connection(); | |
| 357 | 368 | if (connection != nullptr && !connection->ending()) { | |
@@ -390,6 +401,10 @@ std::string GetCwd(Environment* env) { | |||
| 390 | 401 | } | |
| 391 | 402 | ||
| 392 | 403 | void StartProfilers(Environment* env) { | |
| 404 | + AtExit(env, [](void* env) { | ||
| 405 | + EndStartedProfilers(static_cast<Environment*>(env)); | ||
| 406 | + }, env); | ||
| 407 | + | ||
| 393 | 408 | Isolate* isolate = env->isolate(); | |
| 394 | 409 | Local<String> coverage_str = env->env_vars()->Get( | |
| 395 | 410 | isolate, FIXED_ONE_BYTE_STRING(isolate, "NODE_V8_COVERAGE")) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -168,7 +168,6 @@ static const unsigned kMaxSignal = 32; | |||
| 168 | 168 | ||
| 169 | 169 | void WaitForInspectorDisconnect(Environment* env) { | |
| 170 | 170 | #if HAVE_INSPECTOR | |
| 171 | - profiler::EndStartedProfilers(env); | ||
| 172 | 171 | ||
| 173 | 172 | if (env->inspector_agent()->IsActive()) { | |
| 174 | 173 | // Restore signal dispositions, the app is done and is no longer | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -993,9 +993,7 @@ void TriggerUncaughtException(Isolate* isolate, | |||
| 993 | 993 | ||
| 994 | 994 | // Now we are certain that the exception is fatal. | |
| 995 | 995 | ReportFatalException(env, error, message, EnhanceFatalException::kEnhance); | |
| 996 | - #if HAVE_INSPECTOR | ||
| 997 | - profiler::EndStartedProfilers(env); | ||
| 998 | - #endif | ||
| 996 | + RunAtExit(env); | ||
| 999 | 997 | ||
| 1000 | 998 | // If the global uncaught exception handler sets process.exitCode, | |
| 1001 | 999 | // exit with that code. Otherwise, exit with 1. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -318,7 +318,6 @@ void SetIsolateCreateParamsForNode(v8::Isolate::CreateParams* params); | |||
| 318 | 318 | #if HAVE_INSPECTOR | |
| 319 | 319 | namespace profiler { | |
| 320 | 320 | void StartProfilers(Environment* env); | |
| 321 | - void EndStartedProfilers(Environment* env); | ||
| 322 | 321 | } | |
| 323 | 322 | #endif // HAVE_INSPECTOR | |
| 324 | 323 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -172,11 +172,15 @@ static void Kill(const FunctionCallbackInfo<Value>& args) { | |||
| 172 | 172 | if (!args[0]->Int32Value(context).To(&pid)) return; | |
| 173 | 173 | int sig; | |
| 174 | 174 | if (!args[1]->Int32Value(context).To(&sig)) return; | |
| 175 | - // TODO(joyeecheung): white list the signals? | ||
| 176 | 175 | ||
| 177 | - #if HAVE_INSPECTOR | ||
| 178 | - profiler::EndStartedProfilers(env); | ||
| 179 | - #endif | ||
| 176 | + uv_pid_t own_pid = uv_os_getpid(); | ||
| 177 | + if (sig > 0 && | ||
| 178 | + (pid == 0 || pid == -1 || pid == own_pid || pid == -own_pid) && | ||
| 179 | + !HasSignalJSHandler(sig)) { | ||
| 180 | + // This is most likely going to terminate this process. | ||
| 181 | + // It's not an exact method but it might be close enough. | ||
| 182 | + RunAtExit(env); | ||
| 183 | + } | ||
| 180 | 184 | ||
| 181 | 185 | int err = uv_kill(pid, sig); | |
| 182 | 186 | args.GetReturnValue().Set(err); | |
@@ -428,6 +432,7 @@ static void DebugEnd(const FunctionCallbackInfo<Value>& args) { | |||
| 428 | 432 | ||
| 429 | 433 | static void ReallyExit(const FunctionCallbackInfo<Value>& args) { | |
| 430 | 434 | Environment* env = Environment::GetCurrent(args); | |
| 435 | + RunAtExit(env); | ||
| 431 | 436 | WaitForInspectorDisconnect(env); | |
| 432 | 437 | int code = args[0]->Int32Value(env->context()).FromMaybe(0); | |
| 433 | 438 | env->Exit(code); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -400,9 +400,6 @@ void Worker::Run() { | |||
| 400 | 400 | if (exit_code_ == 0 && !stopped) | |
| 401 | 401 | exit_code_ = exit_code; | |
| 402 | 402 | ||
| 403 | - #if HAVE_INSPECTOR | ||
| 404 | - profiler::EndStartedProfilers(env_.get()); | ||
| 405 | - #endif | ||
| 406 | 403 | Debug(this, "Exiting thread for worker %llu with exit code %d", | |
| 407 | 404 | thread_id_, exit_code_); | |
| 408 | 405 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments