@@ -106,6 +106,8 @@ EnvInst::EnvInst(Environment* env)
106
106
107
107
er = eloop_cmds_msg_.init (event_loop_, run_event_loop_cmds_, this );
108
108
CHECK_EQ (er, 0 );
109
+ er = interrupt_msg_.init (event_loop_, run_interrupt_msg_, this );
110
+ CHECK_EQ (er, 0 );
109
111
er = metrics_handle_.init (event_loop_);
110
112
CHECK_EQ (er, 0 );
111
113
er = info_lock_.init (true );
@@ -118,10 +120,14 @@ EnvInst::EnvInst(Environment* env)
118
120
CHECK_EQ (er, 0 );
119
121
120
122
eloop_cmds_msg_.unref ();
123
+ interrupt_msg_.unref ();
121
124
metrics_handle_.unref ();
122
125
env->RegisterHandleCleanup (eloop_cmds_msg_.base_handle (),
123
126
handle_cleanup_cb_,
124
127
nullptr );
128
+ env->RegisterHandleCleanup (interrupt_msg_.base_handle (),
129
+ handle_cleanup_cb_,
130
+ nullptr );
125
131
env->RegisterHandleCleanup (metrics_handle_.base_handle (),
126
132
handle_cleanup_cb_,
127
133
nullptr );
@@ -151,9 +157,11 @@ int EnvInst::RunCommand(SharedEnvInst envinst_sp,
151
157
152
158
if (type == CommandType::Interrupt) {
153
159
EnvInst::CmdQueueStor cmd_stor = { envinst_sp, cb, data };
160
+ // Send it off to both locations. The first to run will retrieve the data
161
+ // from the queue.
154
162
envinst_sp->interrupt_cb_q_ .enqueue (std::move (cmd_stor));
155
- node::RequestInterrupt ( envinst_sp->env (), run_interrupt_, nullptr );
156
- return 0 ;
163
+ envinst_sp->isolate ()-> RequestInterrupt ( run_interrupt_, nullptr );
164
+ return envinst_sp-> interrupt_msg_ . send () ;
157
165
}
158
166
159
167
if (type == CommandType::InterruptOnly) {
@@ -452,14 +460,26 @@ void EnvInst::run_event_loop_cmds_(ns_async*, EnvInst* envinst) {
452
460
453
461
void EnvInst::run_interrupt_msg_ (ns_async*, EnvInst* envinst) {
454
462
CmdQueueStor stor;
463
+ // Need to disable access to JS from here, but first need to make sure the
464
+ // Isolate still exists before trying to disable JS access.
465
+ if (envinst->env () != nullptr ) {
466
+ Isolate::DisallowJavascriptExecutionScope scope (
467
+ envinst->isolate (),
468
+ Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE);
469
+ while (envinst->interrupt_cb_q_ .dequeue (stor)) {
470
+ stor.cb (stor.envinst_sp , stor.data );
471
+ }
472
+ return ;
473
+ }
474
+
455
475
while (envinst->interrupt_cb_q_ .dequeue (stor)) {
456
476
stor.cb (stor.envinst_sp , stor.data );
457
477
}
458
478
}
459
479
460
480
461
- void EnvInst::run_interrupt_ (void *) {
462
- SharedEnvInst envinst_sp = GetCurrent (Isolate::GetCurrent () );
481
+ void EnvInst::run_interrupt_ (Isolate* isolate, void *) {
482
+ SharedEnvInst envinst_sp = GetCurrent (isolate );
463
483
if (!envinst_sp) {
464
484
return ;
465
485
}
0 commit comments