Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index cb6658082206e529c84f701a0835ca63122ad3fc..ec538cc6e9f1c434415a5e7e94746369c05ffe7a 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -182,7 +182,17 @@ class CallDepthScope { |
DCHECK(!isolate_->external_caught_exception()); |
isolate_->IncrementJsCallsFromApiCounter(); |
isolate_->handle_scope_implementer()->IncrementCallDepth(); |
- if (!context_.IsEmpty()) context_->Enter(); |
+ if (!context.IsEmpty()) { |
+ i::Handle<i::Context> env = Utils::OpenHandle(*context); |
+ i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); |
+ if (isolate->context() != nullptr && |
+ isolate->context()->native_context() == env->native_context() && |
+ impl->LastEnteredContextWas(env)) { |
+ context_ = Local<Context>(); |
+ } else { |
+ context_->Enter(); |
+ } |
+ } |
if (do_callback_) isolate_->FireBeforeCallEnteredCallback(); |
} |
~CallDepthScope() { |