11cb0ef41Sopenharmony_ci#include <node.h>
21cb0ef41Sopenharmony_ci#include <v8.h>
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_cistatic void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
51cb0ef41Sopenharmony_ci  v8::Isolate* isolate = args.GetIsolate();
61cb0ef41Sopenharmony_ci  args.GetReturnValue().Set(v8::String::NewFromUtf8(
71cb0ef41Sopenharmony_ci        isolate, "world").ToLocalChecked());
81cb0ef41Sopenharmony_ci}
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// Not using the full NODE_MODULE_INIT() macro here because we want to test the
111cb0ef41Sopenharmony_ci// addon loader's reaction to the FakeInit() entry point below.
121cb0ef41Sopenharmony_ciextern "C" NODE_MODULE_EXPORT void
131cb0ef41Sopenharmony_ciNODE_MODULE_INITIALIZER(v8::Local<v8::Object> exports,
141cb0ef41Sopenharmony_ci                        v8::Local<v8::Value> module,
151cb0ef41Sopenharmony_ci                        v8::Local<v8::Context> context) {
161cb0ef41Sopenharmony_ci  NODE_SET_METHOD(exports, "hello", Method);
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cistatic void FakeInit(v8::Local<v8::Object> exports,
201cb0ef41Sopenharmony_ci                     v8::Local<v8::Value> module,
211cb0ef41Sopenharmony_ci                     v8::Local<v8::Context> context) {
221cb0ef41Sopenharmony_ci  auto isolate = context->GetIsolate();
231cb0ef41Sopenharmony_ci  auto exception = v8::Exception::Error(v8::String::NewFromUtf8(isolate,
241cb0ef41Sopenharmony_ci      "FakeInit should never run!").ToLocalChecked());
251cb0ef41Sopenharmony_ci  isolate->ThrowException(exception);
261cb0ef41Sopenharmony_ci}
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci// Define a Node.js module, but with the wrong version. Node.js should still be
291cb0ef41Sopenharmony_ci// able to load this module, multiple times even, because it exposes the
301cb0ef41Sopenharmony_ci// specially named initializer above.
311cb0ef41Sopenharmony_ci#undef NODE_MODULE_VERSION
321cb0ef41Sopenharmony_ci#define NODE_MODULE_VERSION 3
331cb0ef41Sopenharmony_ciNODE_MODULE(NODE_GYP_MODULE_NAME, FakeInit)
34