|
| 1 | +#include <stdio.h> |
| 2 | +#include "../src/emnapi_internal.h" |
| 3 | +#include "../src/threadsafe_function.h" |
| 4 | + |
| 5 | +#ifdef __wasm64__ |
| 6 | +#define WASM_BIT "64" |
| 7 | +#else |
| 8 | +#define WASM_BIT "32" |
| 9 | +#endif |
| 10 | + |
| 11 | +void print_napi_env_info(FILE* f) { |
| 12 | + fprintf(f, "declare const enum NapiEnvOffset" WASM_BIT " {\n"); |
| 13 | + fprintf(f, " __size__ = %zu,\n", sizeof(node_api_base_env__)); |
| 14 | + fprintf(f, " vptr = %zu,\n", offsetof(node_api_base_env__, vptr)); |
| 15 | + fprintf(f, " sentinel = %zu,\n", offsetof(node_api_base_env__, sentinel)); |
| 16 | + fprintf(f, " js_vtable = %zu,\n", offsetof(node_api_base_env__, js_vtable)); |
| 17 | + fprintf(f, " module_vtable = %zu,\n", offsetof(node_api_base_env__, module_vtable)); |
| 18 | + fprintf(f, " id = %zu,\n", offsetof(node_api_base_env__, id)); |
| 19 | + fprintf(f, " last_error = %zu,\n", offsetof(node_api_base_env__, last_error)); |
| 20 | + fprintf(f, " last_error___size__ = %zu,\n", sizeof(napi_extended_error_info)); |
| 21 | + fprintf(f, " last_error_error_message = %zu,\n", offsetof(node_api_base_env__, last_error) + offsetof(napi_extended_error_info, error_message)); |
| 22 | + fprintf(f, " last_error_engine_reserved = %zu,\n", offsetof(node_api_base_env__, last_error) + offsetof(napi_extended_error_info, engine_reserved)); |
| 23 | + fprintf(f, " last_error_engine_error_code = %zu,\n", offsetof(node_api_base_env__, last_error) + offsetof(napi_extended_error_info, engine_error_code)); |
| 24 | + fprintf(f, " last_error_error_code = %zu,\n", offsetof(node_api_base_env__, last_error) + offsetof(napi_extended_error_info, error_code)); |
| 25 | + fprintf(f, "}\n"); |
| 26 | +} |
| 27 | + |
| 28 | +void print_napi_threadsafe_function_info(FILE* f) { |
| 29 | + fprintf(f, "declare const enum NapiTSFNOffset" WASM_BIT " {\n"); |
| 30 | + fprintf(f, " __size__ = %zu,\n", sizeof(struct napi_threadsafe_function__)); |
| 31 | + fprintf(f, " async_resource = %zu,\n", offsetof(struct napi_threadsafe_function__, async_resource)); |
| 32 | + fprintf(f, " async_resource___size__ = %zu,\n", sizeof(optional_async_resource)); |
| 33 | + fprintf(f, " async_resource_resource = %zu,\n", offsetof(struct napi_threadsafe_function__, async_resource) + offsetof(optional_async_resource, resource_)); |
| 34 | + fprintf(f, " async_resource_async_context = %zu,\n", offsetof(struct napi_threadsafe_function__, async_resource) + offsetof(optional_async_resource, async_context_)); |
| 35 | + fprintf(f, " async_resource_async_context___size__ = %zu,\n", sizeof(async_context)); |
| 36 | + fprintf(f, " async_resource_async_context_async_id = %zu,\n", offsetof(struct napi_threadsafe_function__, async_resource) + offsetof(optional_async_resource, async_context_) + offsetof(async_context, async_id)); |
| 37 | + fprintf(f, " async_resource_async_context_trigger_async_id = %zu,\n", offsetof(struct napi_threadsafe_function__, async_resource) + offsetof(optional_async_resource, async_context_) + offsetof(async_context, trigger_async_id)); |
| 38 | + fprintf(f, " async_resource_is_some = %zu,\n", offsetof(struct napi_threadsafe_function__, async_resource) + offsetof(optional_async_resource, is_some)); |
| 39 | + fprintf(f, " mutex = %zu,\n", offsetof(struct napi_threadsafe_function__, mutex)); |
| 40 | + fprintf(f, " cond = %zu,\n", offsetof(struct napi_threadsafe_function__, cond)); |
| 41 | + fprintf(f, " queue_size = %zu,\n", offsetof(struct napi_threadsafe_function__, queue_size)); |
| 42 | + fprintf(f, " queue = %zu,\n", offsetof(struct napi_threadsafe_function__, queue)); |
| 43 | + fprintf(f, " async = %zu,\n", offsetof(struct napi_threadsafe_function__, async)); |
| 44 | + fprintf(f, " thread_count = %zu,\n", offsetof(struct napi_threadsafe_function__, thread_count)); |
| 45 | + fprintf(f, " state = %zu,\n", offsetof(struct napi_threadsafe_function__, state)); |
| 46 | + fprintf(f, " dispatch_state = %zu,\n", offsetof(struct napi_threadsafe_function__, dispatch_state)); |
| 47 | + fprintf(f, " context = %zu,\n", offsetof(struct napi_threadsafe_function__, context)); |
| 48 | + fprintf(f, " max_queue_size = %zu,\n", offsetof(struct napi_threadsafe_function__, max_queue_size)); |
| 49 | + fprintf(f, " ref = %zu,\n", offsetof(struct napi_threadsafe_function__, ref)); |
| 50 | + fprintf(f, " env = %zu,\n", offsetof(struct napi_threadsafe_function__, env)); |
| 51 | + fprintf(f, " finalize_data = %zu,\n", offsetof(struct napi_threadsafe_function__, finalize_data)); |
| 52 | + fprintf(f, " finalize_cb = %zu,\n", offsetof(struct napi_threadsafe_function__, finalize_cb)); |
| 53 | + fprintf(f, " call_js_cb = %zu,\n", offsetof(struct napi_threadsafe_function__, call_js_cb)); |
| 54 | + fprintf(f, " handles_closing = %zu,\n", offsetof(struct napi_threadsafe_function__, handles_closing)); |
| 55 | + fprintf(f, " async_ref = %zu,\n", offsetof(struct napi_threadsafe_function__, async_ref)); |
| 56 | + fprintf(f, "}\n"); |
| 57 | +} |
| 58 | + |
| 59 | +int main() { |
| 60 | + FILE* f = fopen("src/typings/struct-wasm" WASM_BIT ".d.ts", "w"); |
| 61 | + if (f == NULL) { |
| 62 | + fprintf(stderr, "Failed to open file\n"); |
| 63 | + return 1; |
| 64 | + } |
| 65 | + |
| 66 | + print_napi_env_info(f); |
| 67 | + print_napi_threadsafe_function_info(f); |
| 68 | + |
| 69 | + fclose(f); |
| 70 | + return 0; |
| 71 | +} |
0 commit comments