@@ -41,11 +41,13 @@ using v8::NewStringType;
41
41
using v8::Number;
42
42
using v8::Object;
43
43
using v8::Private;
44
+ using v8::Script;
44
45
using v8::SnapshotCreator;
45
46
using v8::StackTrace;
46
47
using v8::String;
47
48
using v8::Symbol;
48
49
using v8::TracingController;
50
+ using v8::TryCatch;
49
51
using v8::Undefined;
50
52
using v8::Value;
51
53
using worker::Worker;
@@ -412,11 +414,30 @@ Environment::Environment(IsolateData* isolate_data,
412
414
}
413
415
414
416
Environment::~Environment () {
415
- if (Environment** interrupt_data = interrupt_data_.load ())
417
+ if (Environment** interrupt_data = interrupt_data_.load ()) {
418
+ // There are pending RequestInterrupt() callbacks. Tell them not to run,
419
+ // then force V8 to run interrupts by compiling and running an empty script
420
+ // so as not to leak memory.
416
421
*interrupt_data = nullptr ;
417
422
418
- // FreeEnvironment() should have set this.
419
- CHECK (is_stopping ());
423
+ Isolate::AllowJavascriptExecutionScope allow_js_here (isolate ());
424
+ HandleScope handle_scope (isolate ());
425
+ TryCatch try_catch (isolate ());
426
+ Context::Scope context_scope (context ());
427
+
428
+ #ifdef DEBUG
429
+ bool consistency_check = false ;
430
+ isolate ()->RequestInterrupt ([](Isolate*, void * data) {
431
+ *static_cast <bool *>(data) = true ;
432
+ }, &consistency_check);
433
+ #endif
434
+
435
+ Local<Script> script;
436
+ if (Script::Compile (context (), String::Empty (isolate ())).ToLocal (&script))
437
+ USE (script->Run (context ()));
438
+
439
+ DCHECK (consistency_check);
440
+ }
420
441
421
442
isolate ()->GetHeapProfiler ()->RemoveBuildEmbedderGraphCallback (
422
443
BuildEmbedderGraph, this );
0 commit comments