Skip to content

Commit 07fec78

Browse files
authored
Merge pull request #711 from NativeScript/pete/fix-debugger-context
Use existing context in debugger instead of creating a new one
2 parents 570146a + ac1c29b commit 07fec78

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

runtime/src/main/jni/JsV8InspectorClient.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ void JsV8InspectorClient::disconnect() {
6969

7070

7171
void JsV8InspectorClient::dispatchMessage(const std::string& message) {
72-
this->doDispatchMessage(isolate_, message);
72+
Isolate::Scope isolate_scope(isolate_);
73+
v8::HandleScope handleScope(isolate_);
74+
Context::Scope context_scope(isolate_->GetCurrentContext());
7375

76+
this->doDispatchMessage(isolate_, message);
7477
}
7578

7679
void JsV8InspectorClient::runMessageLoopOnPause(int context_group_id) {
@@ -169,7 +172,7 @@ void JsV8InspectorClient::init() {
169172

170173
v8::HandleScope handle_scope(isolate_);
171174

172-
v8::Local<Context> context = Context::New(isolate_);
175+
v8::Local<Context> context = isolate_->GetCurrentContext();
173176
v8::Context::Scope context_scope(context);
174177

175178
inspector_ = V8Inspector::create(isolate_, this);
@@ -179,7 +182,7 @@ void JsV8InspectorClient::init() {
179182
v8::Persistent<v8::Context> persistentContext(context->GetIsolate(), context);
180183
context_.Reset(isolate_, persistentContext);
181184

182-
this->createInspectorSession(isolate_, JsV8InspectorClient::PersistentToLocal(isolate_, context_));
185+
this->createInspectorSession(isolate_, context);
183186
}
184187

185188
JsV8InspectorClient* JsV8InspectorClient::GetInstance() {

runtime/src/main/jni/Runtime.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
489489

490490
__android_log_print(ANDROID_LOG_DEBUG, "TNS.Native", "V8 version %s", V8::GetVersion());
491491

492-
auto globalTemplate = ObjectTemplate::New();
492+
auto globalFunctionTemplate = FunctionTemplate::New(isolate);
493+
globalFunctionTemplate->SetClassName(ArgConverter::ConvertToV8String(isolate, "NativeScriptGlobalObject"));
494+
auto globalTemplate = ObjectTemplate::New(isolate, globalFunctionTemplate);
493495

494496
const auto readOnlyFlags = static_cast<PropertyAttribute>(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
495497

0 commit comments

Comments
 (0)