Skip to content

Commit

Permalink
Initialization working properly on NodeJS.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Dec 4, 2024
1 parent d9604dd commit 83de553
Show file tree
Hide file tree
Showing 13 changed files with 340 additions and 245 deletions.
2 changes: 2 additions & 0 deletions source/loader/include/loader/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ LOADER_API void loader_initialization_register(loader_impl impl);

LOADER_API int loader_initialize(void);

LOADER_NO_EXPORT int loader_initialize_host(const loader_tag tag);

LOADER_API int loader_is_initialized(const loader_tag tag);

LOADER_API int loader_register(const char *name, loader_register_invoke invoke, function *func, type_id return_type, size_t arg_size, type_id args_type_id[]);
Expand Down
2 changes: 2 additions & 0 deletions source/loader/include/loader/loader_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ extern "C" {

/* -- Methods -- */

LOADER_NO_EXPORT int loader_impl_initialize(plugin_manager manager, plugin p, loader_impl impl);

LOADER_API int loader_impl_is_initialized(loader_impl impl);

LOADER_API loader_impl loader_impl_create(const loader_tag tag);
Expand Down
12 changes: 12 additions & 0 deletions source/loader/source/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ void loader_initialization_register_plugin(plugin p)
}
}

int loader_initialize_host(const loader_tag tag)
{
plugin p = plugin_manager_get(&loader_manager, tag);

if (p == NULL)
{
return 1;
}

return loader_impl_initialize(&loader_manager, p, plugin_impl_type(p, loader_impl));
}

int loader_is_initialized(const loader_tag tag)
{
plugin p = plugin_manager_get(&loader_manager, tag);
Expand Down
2 changes: 0 additions & 2 deletions source/loader/source/loader_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ static configuration loader_impl_initialize_configuration(plugin p);

static int loader_impl_initialize_registered(plugin_manager manager, plugin p);

static int loader_impl_initialize(plugin_manager manager, plugin p, loader_impl impl);

static loader_handle_impl loader_impl_load_handle(loader_impl impl, loader_impl_interface iface, loader_handle module, const char *path, size_t size);

static int loader_impl_handle_init(loader_impl impl, const char *path, loader_handle_impl handle_impl, void **handle_ptr, int populated);
Expand Down
2 changes: 1 addition & 1 deletion source/loaders/node_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ target_link_libraries(${target}
${META_PROJECT_NAME}::metacall # MetaCall library

# TODO: Implement delayed load
${NodeJS_LIBRARY} # NodeJS library
# ${NodeJS_LIBRARY} # NodeJS library

PUBLIC
${DEFAULT_LIBRARIES}
Expand Down
20 changes: 17 additions & 3 deletions source/loaders/node_loader/bootstrap/lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,20 @@ function node_loader_trampoline_await_future(trampoline) {
};
}

module.exports = ((impl, ptr) => {
const startup = (impl, ptr, trampoline_exports) => {
try {
if (typeof impl === 'undefined' || typeof ptr === 'undefined') {
throw new Error('Process arguments (process.argv[2], process.argv[3]) not defined.');
throw new Error('Bootstrap startup arguments impl or ptr are not defined.');
}

// Get trampoline from list of linked bindings
const trampoline = process._linkedBinding('node_loader_trampoline_module');
const trampoline = (() => {
if (trampoline_exports) {
return trampoline_exports;
}

return process._linkedBinding('node_loader_trampoline_module');
})();

const node_loader_ptr = trampoline.register(impl, ptr, {
'initialize': node_loader_trampoline_initialize,
Expand All @@ -433,4 +439,12 @@ module.exports = ((impl, ptr) => {
} catch (ex) {
console.log('Exception in bootstrap.js trampoline initialization:', ex);
}
};

module.exports = ((impl, ptr) => {
if (impl === undefined || ptr === undefined) {
return startup;
} else {
return startup(impl, ptr);
}
})(process.argv[2], process.argv[3]);
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ NODE_LOADER_NO_EXPORT void node_loader_impl_print_handles(loader_impl_node node_

NODE_LOADER_NO_EXPORT int64_t node_loader_impl_user_async_handles_count(loader_impl_node node_impl);

NODE_LOADER_NO_EXPORT napi_value node_loader_impl_register_bootstrap_startup(loader_impl_node node_impl, napi_env env);

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ typedef void *(*node_loader_trampoline_register_ptr)(void *, void *, void *);

NODE_LOADER_NO_EXPORT napi_value node_loader_trampoline_initialize(napi_env env, napi_value exports);

NODE_LOADER_NO_EXPORT napi_value node_loader_trampoline_initialize_object(napi_env env);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 83de553

Please sign in to comment.