forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinding.cc
78 lines (64 loc) · 2.47 KB
/
binding.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <node.h>
#include <v8.h>
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::Value;
void TriggerReport(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
node::TriggerNodeReport(
isolate, "FooMessage", "BarTrigger", std::string(), Local<Value>());
}
void TriggerReportNoIsolate(const FunctionCallbackInfo<Value>& args) {
node::TriggerNodeReport(static_cast<Isolate*>(nullptr),
"FooMessage",
"BarTrigger",
std::string(),
Local<Value>());
}
void TriggerReportEnv(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
node::TriggerNodeReport(
node::GetCurrentEnvironment(isolate->GetCurrentContext()),
"FooMessage",
"BarTrigger",
std::string(),
Local<Value>());
}
void TriggerReportNoEnv(const FunctionCallbackInfo<Value>& args) {
node::TriggerNodeReport(static_cast<node::Environment*>(nullptr),
"FooMessage",
"BarTrigger",
std::string(),
Local<Value>());
}
void TriggerReportNoContext(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
context->Exit();
if (isolate->GetCurrentContext().IsEmpty()) {
node::TriggerNodeReport(
isolate, "FooMessage", "BarTrigger", std::string(), Local<Value>());
}
// Restore current context to avoid crashing in Context::Scope in
// SpinEventLoop.
context->Enter();
}
void TriggerReportNewContext(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = Context::New(isolate);
Context::Scope context_scope(context);
node::TriggerNodeReport(
isolate, "FooMessage", "BarTrigger", std::string(), Local<Value>());
}
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "triggerReport", TriggerReport);
NODE_SET_METHOD(exports, "triggerReportNoIsolate", TriggerReportNoIsolate);
NODE_SET_METHOD(exports, "triggerReportEnv", TriggerReportEnv);
NODE_SET_METHOD(exports, "triggerReportNoEnv", TriggerReportNoEnv);
NODE_SET_METHOD(exports, "triggerReportNoContext", TriggerReportNoContext);
NODE_SET_METHOD(exports, "triggerReportNewContext", TriggerReportNewContext);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, init)