GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_process_events.cc Lines: 35 45 77.8 %
Date: 2021-06-04 04:12:13 Branches: 19 30 63.3 %

Line Branch Exec Source
1
#include <set>
2
3
#include "env-inl.h"
4
#include "node_process-inl.h"
5
#include "util.h"
6
7
namespace node {
8
using v8::Context;
9
using v8::Function;
10
using v8::HandleScope;
11
using v8::Isolate;
12
using v8::Just;
13
using v8::Local;
14
using v8::Maybe;
15
using v8::MaybeLocal;
16
using v8::Nothing;
17
using v8::Object;
18
using v8::String;
19
using v8::Value;
20
21
9309
MaybeLocal<Value> ProcessEmit(Environment* env,
22
                              const char* event,
23
                              Local<Value> message) {
24
  // Send message to enable debug in cluster workers
25
9309
  Isolate* isolate = env->isolate();
26
27
  Local<String> event_string;
28
18617
  if (!String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>(event))
29
9308
      .ToLocal(&event_string)) return MaybeLocal<Value>();
30
31
9308
  Local<Object> process = env->process_object();
32
18618
  Local<Value> argv[] = {event_string, message};
33
9309
  return MakeCallback(isolate, process, "emit", arraysize(argv), argv, {0, 0});
34
}
35
36
37
Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
37
                                      const char* warning,
38
                                      const char* type,
39
                                      const char* code) {
40
37
  if (!env->can_call_into_js()) return Just(false);
41
42
74
  HandleScope handle_scope(env->isolate());
43
37
  Context::Scope context_scope(env->context());
44
45
37
  Local<Object> process = env->process_object();
46
  Local<Value> emit_warning;
47
148
  if (!process->Get(env->context(), env->emit_warning_string())
48
37
           .ToLocal(&emit_warning)) {
49
1
    return Nothing<bool>();
50
  }
51
52
36
  if (!emit_warning->IsFunction()) return Just(false);
53
54
36
  int argc = 0;
55
144
  Local<Value> args[3];  // warning, type, code
56
57
  // The caller has to be able to handle a failure anyway, so we might as well
58
  // do proper error checking for string creation.
59
72
  if (!String::NewFromUtf8(env->isolate(), warning).ToLocal(&args[argc++]))
60
    return Nothing<bool>();
61
62
36
  if (type != nullptr) {
63
10
    if (!String::NewFromOneByte(env->isolate(),
64
5
                                reinterpret_cast<const uint8_t*>(type))
65
10
             .ToLocal(&args[argc++])) {
66
      return Nothing<bool>();
67
    }
68

14
    if (code != nullptr &&
69
13
        !String::NewFromOneByte(env->isolate(),
70
4
                                reinterpret_cast<const uint8_t*>(code))
71
8
             .ToLocal(&args[argc++])) {
72
      return Nothing<bool>();
73
    }
74
  }
75
76
  // MakeCallback() unneeded because emitWarning is internal code, it calls
77
  // process.emit('warning', ...), but does so on the nextTick.
78
144
  if (emit_warning.As<Function>()
79
144
          ->Call(env->context(), process, argc, args)
80
          .IsEmpty()) {
81
1
    return Nothing<bool>();
82
  }
83
35
  return Just(true);
84
}
85
86
87
4844
std::set<std::string> experimental_warnings;
88
89
Maybe<bool> ProcessEmitExperimentalWarning(Environment* env,
90
                                          const char* warning) {
91
  if (experimental_warnings.find(warning) != experimental_warnings.end())
92
    return Nothing<bool>();
93
94
  experimental_warnings.insert(warning);
95
  std::string message(warning);
96
  message.append(
97
      " is an experimental feature. This feature could change at any time");
98
  return ProcessEmitWarningGeneric(env, message.c_str(), "ExperimentalWarning");
99
}
100
101
4
Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
102
                                          const char* warning,
103
                                          const char* deprecation_code) {
104
  return ProcessEmitWarningGeneric(
105
4
      env, warning, "DeprecationWarning", deprecation_code);
106
}
107
108

14532
}  // namespace node