@@ -42,11 +42,13 @@ using v8::NewStringType;
42
42
using v8::Number;
43
43
using v8::Object;
44
44
using v8::Private;
45
+ using v8::Script;
45
46
using v8::SnapshotCreator;
46
47
using v8::StackTrace;
47
48
using v8::String;
48
49
using v8::Symbol;
49
50
using v8::TracingController;
51
+ using v8::TryCatch;
50
52
using v8::Undefined;
51
53
using v8::Value;
52
54
using worker::Worker;
@@ -394,9 +396,31 @@ Environment::Environment(IsolateData* isolate_data,
394
396
}
395
397
396
398
Environment::~Environment () {
397
- if (Environment** interrupt_data = interrupt_data_.load ())
399
+ if (Environment** interrupt_data = interrupt_data_.load ()) {
400
+ // There are pending RequestInterrupt() callbacks. Tell them not to run,
401
+ // then force V8 to run interrupts by compiling and running an empty script
402
+ // so as not to leak memory.
398
403
*interrupt_data = nullptr ;
399
404
405
+ Isolate::AllowJavascriptExecutionScope allow_js_here (isolate ());
406
+ HandleScope handle_scope (isolate ());
407
+ TryCatch try_catch (isolate ());
408
+ Context::Scope context_scope (context ());
409
+
410
+ #ifdef DEBUG
411
+ bool consistency_check = false ;
412
+ isolate ()->RequestInterrupt ([](Isolate*, void * data) {
413
+ *static_cast <bool *>(data) = true ;
414
+ }, &consistency_check);
415
+ #endif
416
+
417
+ Local<Script> script;
418
+ if (Script::Compile (context (), String::Empty (isolate ())).ToLocal (&script))
419
+ USE (script->Run (context ()));
420
+
421
+ DCHECK (consistency_check);
422
+ }
423
+
400
424
// FreeEnvironment() should have set this.
401
425
CHECK (is_stopping ());
402
426
0 commit comments