11#include <stdio.h>
22#include "../src/emnapi_internal.h"
3+ #include "../src/threadsafe_function.h"
34
45#ifdef __wasm64__
56#define WASM_BIT "64"
67#else
78#define WASM_BIT "32"
89#endif
910
10- int main () {
11- FILE * f = fopen ("src/typings/struct-wasm" WASM_BIT ".d.ts" , "w" );
12- if (f == NULL ) {
13- fprintf (stderr , "Failed to open file\n" );
14- return 1 ;
15- }
16-
11+ void print_napi_env_info (FILE * f ) {
1712 fprintf (f , "declare const enum NapiEnvOffset" WASM_BIT " {\n" );
1813 fprintf (f , " __size__ = %zu,\n" , sizeof (node_api_base_env__ ));
1914 fprintf (f , " vptr = %zu,\n" , offsetof(node_api_base_env__ , vptr ));
@@ -28,6 +23,48 @@ int main() {
2823 fprintf (f , " last_error_engine_error_code = %zu,\n" , offsetof(node_api_base_env__ , last_error ) + offsetof(napi_extended_error_info , engine_error_code ));
2924 fprintf (f , " last_error_error_code = %zu,\n" , offsetof(node_api_base_env__ , last_error ) + offsetof(napi_extended_error_info , error_code ));
3025 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 );
3168
3269 fclose (f );
3370 return 0 ;
0 commit comments