11cb0ef41Sopenharmony_ci#include <node.h>
21cb0ef41Sopenharmony_ci#include <v8.h>
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciusing v8::Context;
51cb0ef41Sopenharmony_ciusing v8::FunctionCallbackInfo;
61cb0ef41Sopenharmony_ciusing v8::Isolate;
71cb0ef41Sopenharmony_ciusing v8::Local;
81cb0ef41Sopenharmony_ciusing v8::Object;
91cb0ef41Sopenharmony_ciusing v8::Value;
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_civoid TriggerReport(const FunctionCallbackInfo<Value>& args) {
121cb0ef41Sopenharmony_ci  Isolate* isolate = args.GetIsolate();
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  node::TriggerNodeReport(
151cb0ef41Sopenharmony_ci      isolate, "FooMessage", "BarTrigger", std::string(), Local<Value>());
161cb0ef41Sopenharmony_ci}
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_civoid TriggerReportNoIsolate(const FunctionCallbackInfo<Value>& args) {
191cb0ef41Sopenharmony_ci  node::TriggerNodeReport(static_cast<Isolate*>(nullptr),
201cb0ef41Sopenharmony_ci                          "FooMessage",
211cb0ef41Sopenharmony_ci                          "BarTrigger",
221cb0ef41Sopenharmony_ci                          std::string(),
231cb0ef41Sopenharmony_ci                          Local<Value>());
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_civoid TriggerReportEnv(const FunctionCallbackInfo<Value>& args) {
271cb0ef41Sopenharmony_ci  Isolate* isolate = args.GetIsolate();
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  node::TriggerNodeReport(
301cb0ef41Sopenharmony_ci      node::GetCurrentEnvironment(isolate->GetCurrentContext()),
311cb0ef41Sopenharmony_ci      "FooMessage",
321cb0ef41Sopenharmony_ci      "BarTrigger",
331cb0ef41Sopenharmony_ci      std::string(),
341cb0ef41Sopenharmony_ci      Local<Value>());
351cb0ef41Sopenharmony_ci}
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_civoid TriggerReportNoEnv(const FunctionCallbackInfo<Value>& args) {
381cb0ef41Sopenharmony_ci  node::TriggerNodeReport(static_cast<node::Environment*>(nullptr),
391cb0ef41Sopenharmony_ci                          "FooMessage",
401cb0ef41Sopenharmony_ci                          "BarTrigger",
411cb0ef41Sopenharmony_ci                          std::string(),
421cb0ef41Sopenharmony_ci                          Local<Value>());
431cb0ef41Sopenharmony_ci}
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_civoid TriggerReportNoContext(const FunctionCallbackInfo<Value>& args) {
461cb0ef41Sopenharmony_ci  Isolate* isolate = args.GetIsolate();
471cb0ef41Sopenharmony_ci  Local<Context> context = isolate->GetCurrentContext();
481cb0ef41Sopenharmony_ci  context->Exit();
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci  if (isolate->GetCurrentContext().IsEmpty()) {
511cb0ef41Sopenharmony_ci    node::TriggerNodeReport(
521cb0ef41Sopenharmony_ci        isolate, "FooMessage", "BarTrigger", std::string(), Local<Value>());
531cb0ef41Sopenharmony_ci  }
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  // Restore current context to avoid crashing in Context::Scope in
561cb0ef41Sopenharmony_ci  // SpinEventLoop.
571cb0ef41Sopenharmony_ci  context->Enter();
581cb0ef41Sopenharmony_ci}
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_civoid TriggerReportNewContext(const FunctionCallbackInfo<Value>& args) {
611cb0ef41Sopenharmony_ci  Isolate* isolate = args.GetIsolate();
621cb0ef41Sopenharmony_ci  Local<Context> context = Context::New(isolate);
631cb0ef41Sopenharmony_ci  Context::Scope context_scope(context);
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci  node::TriggerNodeReport(
661cb0ef41Sopenharmony_ci      isolate, "FooMessage", "BarTrigger", std::string(), Local<Value>());
671cb0ef41Sopenharmony_ci}
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_civoid init(Local<Object> exports) {
701cb0ef41Sopenharmony_ci  NODE_SET_METHOD(exports, "triggerReport", TriggerReport);
711cb0ef41Sopenharmony_ci  NODE_SET_METHOD(exports, "triggerReportNoIsolate", TriggerReportNoIsolate);
721cb0ef41Sopenharmony_ci  NODE_SET_METHOD(exports, "triggerReportEnv", TriggerReportEnv);
731cb0ef41Sopenharmony_ci  NODE_SET_METHOD(exports, "triggerReportNoEnv", TriggerReportNoEnv);
741cb0ef41Sopenharmony_ci  NODE_SET_METHOD(exports, "triggerReportNoContext", TriggerReportNoContext);
751cb0ef41Sopenharmony_ci  NODE_SET_METHOD(exports, "triggerReportNewContext", TriggerReportNewContext);
761cb0ef41Sopenharmony_ci}
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ciNODE_MODULE(NODE_GYP_MODULE_NAME, init)
79