bare-tty 5.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.c CHANGED
@@ -20,8 +20,10 @@ typedef struct {
20
20
  js_ref_t *on_read;
21
21
  js_ref_t *on_close;
22
22
 
23
- js_deferred_teardown_t *teardown;
23
+ bool closing;
24
24
  bool exiting;
25
+
26
+ js_deferred_teardown_t *teardown;
25
27
  } bare_tty_t;
26
28
 
27
29
  static void
@@ -30,6 +32,8 @@ bare_tty__on_write(uv_write_t *req, int status) {
30
32
 
31
33
  bare_tty_t *tty = (bare_tty_t *) req->data;
32
34
 
35
+ if (tty->exiting) return;
36
+
33
37
  js_env_t *env = tty->env;
34
38
 
35
39
  js_handle_scope_t *scope;
@@ -77,6 +81,8 @@ bare_tty__on_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
77
81
 
78
82
  bare_tty_t *tty = (bare_tty_t *) stream;
79
83
 
84
+ if (tty->exiting) return;
85
+
80
86
  js_env_t *env = tty->env;
81
87
 
82
88
  js_handle_scope_t *scope;
@@ -129,7 +135,7 @@ bare_tty__on_close(uv_handle_t *handle) {
129
135
 
130
136
  js_env_t *env = tty->env;
131
137
 
132
- if (tty->exiting) goto finalize;
138
+ js_deferred_teardown_t *teardown = tty->teardown;
133
139
 
134
140
  js_handle_scope_t *scope;
135
141
  err = js_open_handle_scope(env, &scope);
@@ -143,15 +149,6 @@ bare_tty__on_close(uv_handle_t *handle) {
143
149
  err = js_get_reference_value(env, tty->on_close, &callback);
144
150
  assert(err == 0);
145
151
 
146
- js_call_function(env, ctx, callback, 0, NULL, NULL);
147
-
148
- err = js_close_handle_scope(env, scope);
149
- assert(err == 0);
150
-
151
- finalize:
152
- err = js_finish_deferred_teardown_callback(tty->teardown);
153
- assert(err == 0);
154
-
155
152
  err = js_delete_reference(env, tty->on_write);
156
153
  assert(err == 0);
157
154
 
@@ -163,6 +160,14 @@ finalize:
163
160
 
164
161
  err = js_delete_reference(env, tty->ctx);
165
162
  assert(err == 0);
163
+
164
+ if (!tty->exiting) js_call_function(env, ctx, callback, 0, NULL, NULL);
165
+
166
+ err = js_close_handle_scope(env, scope);
167
+ assert(err == 0);
168
+
169
+ err = js_finish_deferred_teardown_callback(teardown);
170
+ assert(err == 0);
166
171
  }
167
172
 
168
173
  static void
@@ -171,6 +176,8 @@ bare_tty__on_teardown(js_deferred_teardown_t *handle, void *data) {
171
176
 
172
177
  tty->exiting = true;
173
178
 
179
+ if (tty->closing) return;
180
+
174
181
  uv_close((uv_handle_t *) &tty->handle, bare_tty__on_close);
175
182
  }
176
183
 
@@ -194,7 +201,8 @@ bare_tty_init(js_env_t *env, js_callback_info_t *info) {
194
201
  assert(argc == 6);
195
202
 
196
203
  uv_loop_t *loop;
197
- js_get_env_loop(env, &loop);
204
+ err = js_get_env_loop(env, &loop);
205
+ assert(err == 0);
198
206
 
199
207
  js_value_t *handle;
200
208
 
@@ -219,6 +227,7 @@ bare_tty_init(js_env_t *env, js_callback_info_t *info) {
219
227
  (void) err;
220
228
 
221
229
  tty->env = env;
230
+ tty->closing = false;
222
231
  tty->exiting = false;
223
232
 
224
233
  err = js_get_typedarray_info(env, argv[1], NULL, (void **) &tty->read.base, (size_t *) &tty->read.len, NULL, NULL);
@@ -366,6 +375,8 @@ bare_tty_close(js_env_t *env, js_callback_info_t *info) {
366
375
  // close an output stream.
367
376
  (void) err;
368
377
 
378
+ tty->closing = true;
379
+
369
380
  uv_close((uv_handle_t *) &tty->handle, bare_tty__on_close);
370
381
 
371
382
  return NULL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-tty",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "Native TTY streams for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file