|
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 | 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"))
|
|
0 commit comments