Skip to content

Commit

Permalink
restore test_null_init test
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoroz committed Feb 3, 2023
1 parent fbe67a9 commit a742f4a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/node-api/test_null_init/binding.gyp
@@ -0,0 +1,8 @@
{
'targets': [
{
'target_name': 'test_null_init',
'sources': [ 'test_null_init.c' ]
}
]
}
7 changes: 7 additions & 0 deletions test/node-api/test_null_init/test.js
@@ -0,0 +1,7 @@
'use strict';
const common = require('../../common');
const assert = require('assert');

assert.throws(
() => require(`./build/${common.buildType}/test_null_init`),
/Module has no declared entry point[.]/);
47 changes: 47 additions & 0 deletions test/node-api/test_null_init/test_null_init.c
@@ -0,0 +1,47 @@
#include <node_api.h>

#if defined(_MSC_VER)
#if defined(__cplusplus)
#define NAPI_C_CTOR(fn) \
static void NAPI_CDECL fn(void); \
namespace { \
struct fn##_ { \
fn##_() { fn(); } \
} fn##_v_; \
} \
static void NAPI_CDECL fn(void)
#else // !defined(__cplusplus)
#pragma section(".CRT$XCU", read)
// The NAPI_C_CTOR macro defines a function fn that is called during CRT
// initialization.
// C does not support dynamic initialization of static variables and this code
// simulates C++ behavior. Exporting the function pointer prevents it from being
// optimized. See for details:
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-initialization?view=msvc-170
#define NAPI_C_CTOR(fn) \
static void NAPI_CDECL fn(void); \
__declspec(dllexport, allocate(".CRT$XCU")) void(NAPI_CDECL * fn##_)(void) = \
fn; \
static void NAPI_CDECL fn(void)
#endif // defined(__cplusplus)
#else
#define NAPI_C_CTOR(fn) \
static void fn(void) __attribute__((constructor)); \
static void fn(void)
#endif

#define NAPI_MODULE_TEST(modname, regfunc) \
EXTERN_C_START \
static napi_module _module = { \
NAPI_MODULE_VERSION, \
0, \
__FILE__, \
regfunc, \
#modname, \
NULL, \
{0}, \
}; \
NAPI_C_CTOR(_register_##modname) { napi_module_register(&_module); } \
EXTERN_C_END

NAPI_MODULE_TEST(NODE_GYP_MODULE_NAME, NULL)

0 comments on commit a742f4a

Please sign in to comment.