Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NativeScript/napi/v8/jsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "libplatform/libplatform.h"
#include "v8-fast-api-calls.h"
#include "v8-module-loader.h"

#ifdef __ANDROID__
#include "NativeScriptAssert.h"
Expand Down Expand Up @@ -262,6 +263,9 @@ napi_status js_free_runtime(jsr_ns_runtime runtime) {
// the locker has been destroyed.
{
v8::Locker locker(jsr->isolate);
// The ES module cache holds thread-local Globals per isolate. Release them
// now; left to thread exit, they would be reset against a disposed isolate.
v8impl::CleanupESModuleSystem(jsr->isolate);
while (v8::Isolate::GetCurrent() == jsr->isolate) {
jsr->isolate->Exit();
}
Expand Down
18 changes: 18 additions & 0 deletions NativeScript/runtime/apple/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,26 @@ Runtime::~Runtime() {
napi_close_handle_scope(env_, globalScope_);
globalScope_ = nullptr;
}
#ifndef TARGET_ENGINE_V8
js_free_napi_env(env_);
#endif
}
#ifdef TARGET_ENGINE_V8
{
// NapiScope enters env_->context(), a Local that aliases the env's own
// persistent slot. Freeing the env destroys that slot, so exiting the
// scope afterwards reads a dead handle and V8 aborts with "Cannot exit
// non-entered context". Enter a HandleScope-owned copy instead, so the
// env's finalizers still run inside the context.
v8::Locker locker(env_->isolate);
v8::Isolate::Scope isolateScope(env_->isolate);
v8::HandleScope handleScope(env_->isolate);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(env_->isolate, env_->context());
v8::Context::Scope contextScope(context);
js_free_napi_env(env_);
}
#endif

js_free_runtime(runtime_);
} else {
Expand Down
Loading