mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Run callback passed to napi_module_register after dlopen returns instead of during call (#20478)
This commit is contained in:
44
test/napi/napi-app/constructor_order_addon.cpp
Normal file
44
test/napi/napi-app/constructor_order_addon.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <js_native_api.h>
|
||||
#include <node_api.h>
|
||||
#include <stdio.h>
|
||||
|
||||
napi_value register_cb(napi_env env, napi_value exports);
|
||||
|
||||
static napi_module mod = {
|
||||
1, // nm_version
|
||||
0, // nm_flags
|
||||
"constructor_order_addon.c", // nm_filename
|
||||
register_cb, // nm_register_func
|
||||
"constructor_order_addon", // nm_modname
|
||||
NULL, // nm_priv
|
||||
{NULL} // reserved
|
||||
};
|
||||
|
||||
class call_register {
|
||||
public:
|
||||
call_register() {
|
||||
// should be called first during dlopen
|
||||
printf("call_register\n");
|
||||
napi_module_register(&mod);
|
||||
}
|
||||
};
|
||||
|
||||
class init_static {
|
||||
public:
|
||||
init_static() {
|
||||
// should be called second during dlopen
|
||||
printf("init_static\n");
|
||||
}
|
||||
};
|
||||
|
||||
// declare these so their constructors run
|
||||
static call_register constructor1;
|
||||
static init_static constructor2;
|
||||
|
||||
napi_value register_cb(napi_env env, napi_value exports) {
|
||||
// should be called third, after dlopen returns and bun runs the callback
|
||||
// passed to napi_module_register
|
||||
(void)env;
|
||||
printf("register_cb\n");
|
||||
return exports;
|
||||
}
|
||||
Reference in New Issue
Block a user