-
Notifications
You must be signed in to change notification settings - Fork 9
/
bare.h
159 lines (134 loc) · 3.75 KB
/
bare.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef BARE_H
#define BARE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <js.h>
#include <stddef.h>
#include <uv.h>
#include "bare/module.h"
#include "bare/target.h"
#include "bare/version.h"
typedef struct bare_s bare_t;
typedef struct bare_options_s bare_options_t;
typedef void (*bare_before_exit_cb)(bare_t *);
typedef void (*bare_exit_cb)(bare_t *);
typedef void (*bare_teardown_cb)(bare_t *);
typedef void (*bare_suspend_cb)(bare_t *, int linger);
typedef void (*bare_idle_cb)(bare_t *);
typedef void (*bare_resume_cb)(bare_t *);
typedef void (*bare_thread_cb)(bare_t *, js_env_t *);
/** @version 0 */
struct bare_options_s {
int version;
/**
* The memory limit of each JavaScript heap. By default, the limit will be
* inferred based on the amount of physical memory of the device.
*
* Note that the limit applies individually to each thread, including the
* main thread.
*
* @since 0
*/
size_t memory_limit;
};
/**
* Get the current Bare version. Useful for cases where embedders are
* dynamically linking Bare.
*/
int
bare_version(int *major, int *minor, int *patch);
/**
* Set up the Bare process. To get a reference to the JavaScript environment of
* the process, pass the `env` pointer.
*/
int
bare_setup(uv_loop_t *loop, js_platform_t *platform, js_env_t **env, int argc, const char *argv[], const bare_options_t *options, bare_t **result);
/**
* Tear down the Bare process. The exit code will be stored in `exit_code` if
* provided. The JavaScript environment of the process must not be used after
* this function returns.
*/
int
bare_teardown(bare_t *bare, int *exit_code);
/**
* Immediately terminate the process with an exit status of `exit_code`.
*/
int
bare_exit(bare_t *bare, int exit_code);
/**
* Load the module identified by `filename`, which may be any of the formats
* supported by the module system. Unless `source` is provided, the contents
* of `filename` will be read from disk.
*
* See https://github.com/holepunchto/bare-module for more information on the
* supported module formats.
*/
int
bare_load(bare_t *bare, const char *filename, const uv_buf_t *source, js_value_t **result);
/**
* Run the I/O event loop.
*/
int
bare_run(bare_t *bare);
/**
* Terminate the process as soon as possible. It's safe to call this function
* from any thread.
*/
int
bare_terminate(bare_t *bare);
/**
* Suspend the process as soon as possible. Once the process has suspended
* successfully, `bare_run()` will not return until another thread resumes the
* process. It's safe to call this function from any thread.
*/
int
bare_suspend(bare_t *bare, int linger);
/**
* Resume the process as soon as possible. If the process is not yet idle after
* being suspended the suspension will be cancelled. It's safe to call this
* function from any thread.
*/
int
bare_resume(bare_t *bare);
/**
* Equivalent to `Bare.on('beforeExit', cb)`.
*/
int
bare_on_before_exit(bare_t *bare, bare_before_exit_cb cb);
/**
* Equivalent to `Bare.on('exit', cb)`.
*/
int
bare_on_exit(bare_t *bare, bare_exit_cb cb);
/**
* Equivalent to `Bare.on('teardown', cb)`.
*/
int
bare_on_teardown(bare_t *bare, bare_teardown_cb cb);
/**
* Equivalent to `Bare.on('suspend', cb)`.
*/
int
bare_on_suspend(bare_t *bare, bare_suspend_cb cb);
/**
* Equivalent to `Bare.on('idle', cb)`.
*/
int
bare_on_idle(bare_t *bare, bare_idle_cb cb);
/**
* Equivalent to `Bare.on('resume', cb)`.
*/
int
bare_on_resume(bare_t *bare, bare_resume_cb cb);
/**
* Attach a thread listener which will invoked with the JavaScript environment
* of each thread created with the `Thread` constructor. Use this to modify the
* environment of the thread before it runs any JavaScript.
*/
int
bare_on_thread(bare_t *bare, bare_thread_cb cb);
#ifdef __cplusplus
}
#endif
#endif // BARE_H