@@ -43,11 +43,13 @@ using v8::NewStringType;
43
43
using v8::Number;
44
44
using v8::Object;
45
45
using v8::Private;
46
+ using v8::Script;
46
47
using v8::SnapshotCreator;
47
48
using v8::StackTrace;
48
49
using v8::String;
49
50
using v8::Symbol;
50
51
using v8::TracingController;
52
+ using v8::TryCatch;
51
53
using v8::Undefined;
52
54
using v8::Value;
53
55
using worker::Worker;
@@ -435,9 +437,31 @@ Environment::Environment(IsolateData* isolate_data,
435
437
}
436
438
437
439
Environment::~Environment () {
438
- if (Environment** interrupt_data = interrupt_data_.load ())
440
+ if (Environment** interrupt_data = interrupt_data_.load ()) {
441
+ // There are pending RequestInterrupt() callbacks. Tell them not to run,
442
+ // then force V8 to run interrupts by compiling and running an empty script
443
+ // so as not to leak memory.
439
444
*interrupt_data = nullptr ;
440
445
446
+ Isolate::AllowJavascriptExecutionScope allow_js_here (isolate ());
447
+ HandleScope handle_scope (isolate ());
448
+ TryCatch try_catch (isolate ());
449
+ Context::Scope context_scope (context ());
450
+
451
+ #ifdef DEBUG
452
+ bool consistency_check = false ;
453
+ isolate ()->RequestInterrupt ([](Isolate*, void * data) {
454
+ *static_cast <bool *>(data) = true ;
455
+ }, &consistency_check);
456
+ #endif
457
+
458
+ Local<Script> script;
459
+ if (Script::Compile (context (), String::Empty (isolate ())).ToLocal (&script))
460
+ USE (script->Run (context ()));
461
+
462
+ DCHECK (consistency_check);
463
+ }
464
+
441
465
// FreeEnvironment() should have set this.
442
466
CHECK (is_stopping ());
443
467
0 commit comments