diff --git a/NativeScript/NativeScript-Prefix.pch b/NativeScript/NativeScript-Prefix.pch index 0144e935..ba363e3f 100644 --- a/NativeScript/NativeScript-Prefix.pch +++ b/NativeScript/NativeScript-Prefix.pch @@ -1,7 +1,7 @@ #ifndef NativeScript_Prefix_pch #define NativeScript_Prefix_pch -#define NATIVESCRIPT_VERSION "8.2.2" +#define NATIVESCRIPT_VERSION "8.2.3-alpha.0" #ifdef DEBUG #define SIZEOF_OFF_T 8 diff --git a/NativeScript/inspector/InspectorServer.mm b/NativeScript/inspector/InspectorServer.mm index a770071e..5a645577 100644 --- a/NativeScript/inspector/InspectorServer.mm +++ b/NativeScript/inspector/InspectorServer.mm @@ -78,10 +78,7 @@ if (size) { NSString* payload = [[NSString alloc] initWithData:(NSData*)data encoding:NSUTF16LittleEndianStringEncoding]; - if (payload) { - std::string result = [payload UTF8String]; - onMessage(result); - } + onMessage([payload UTF8String]); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-retain-cycles" diff --git a/NativeScript/inspector/JsV8InspectorClient.h b/NativeScript/inspector/JsV8InspectorClient.h index 406bfb52..d16f7c9d 100644 --- a/NativeScript/inspector/JsV8InspectorClient.h +++ b/NativeScript/inspector/JsV8InspectorClient.h @@ -44,6 +44,7 @@ class JsV8InspectorClient : V8InspectorClient, V8Inspector::Channel { std::vector messages_; bool runningNestedLoops_; dispatch_queue_t messagesQueue_; + dispatch_queue_t messageLoopQueue_; dispatch_semaphore_t messageArrived_; std::function sender_; bool isWaitingForDebugger_; @@ -51,7 +52,7 @@ class JsV8InspectorClient : V8InspectorClient, V8Inspector::Channel { void enableInspector(int argc, char** argv); void notify(std::unique_ptr message); void onFrontendConnected(std::function sender); - void onFrontendMessageReceived(std::string &message); + void onFrontendMessageReceived(std::string message); template static v8::Local PersistentToLocal(v8::Isolate* isolate, const v8::Persistent& persistent); std::string PumpMessage(); diff --git a/NativeScript/inspector/JsV8InspectorClient.mm b/NativeScript/inspector/JsV8InspectorClient.mm index a3cd2de8..43b379fa 100644 --- a/NativeScript/inspector/JsV8InspectorClient.mm +++ b/NativeScript/inspector/JsV8InspectorClient.mm @@ -82,7 +82,8 @@ : runtime_(runtime), messages_(), runningNestedLoops_(false) { - this->messagesQueue_ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + this->messagesQueue_ = dispatch_queue_create("NativeScript.v8.inspector.message_queue", DISPATCH_QUEUE_SERIAL); + this->messageLoopQueue_ = dispatch_queue_create("NativeScript.v8.inspector.message_loop_queue", DISPATCH_QUEUE_SERIAL); this->messageArrived_ = dispatch_semaphore_create(0); } @@ -101,22 +102,27 @@ this->disconnect(); } -void JsV8InspectorClient::onFrontendMessageReceived(std::string &message) { - __block std::string strCopy = message; +void JsV8InspectorClient::onFrontendMessageReceived(std::string message) { dispatch_sync(this->messagesQueue_, ^{ - this->messages_.push_back(strCopy); + this->messages_.push_back(message); dispatch_semaphore_signal(messageArrived_); }); tns::ExecuteOnMainThread([this, message]() { - dispatch_sync(this->messagesQueue_, ^{ - while (this->messages_.size() > 0) { - std::string message = this->PumpMessage(); + dispatch_sync(this->messageLoopQueue_, ^{ + // prevent execution if we're already pumping messages + if (runningNestedLoops_ && !terminated_) { + return; + }; + std::string message; + do { + message = this->PumpMessage(); if (!message.empty()) { this->dispatchMessage(message); } - } + } while (!message.empty()); }); + }); } @@ -163,12 +169,20 @@ } void JsV8InspectorClient::runMessageLoopOnPause(int contextGroupId) { - if (runningNestedLoops_) { + __block auto loopsRunning = false; + dispatch_sync(this->messageLoopQueue_, ^{ + loopsRunning = runningNestedLoops_; + terminated_ = false; + if (runningNestedLoops_) { + return; + } + this->runningNestedLoops_ = true; + }); + + if (loopsRunning) { return; } - - terminated_ = false; - this->runningNestedLoops_ = true; + bool shouldWait = false; while (!terminated_) { std::string message = this->PumpMessage(); @@ -183,16 +197,20 @@ Isolate* isolate = runtime_->GetIsolate(); platform::PumpMessageLoop(platform.get(), isolate, platform::MessageLoopBehavior::kDoNotWait); if(shouldWait && !terminated_) { - dispatch_semaphore_wait(messageArrived_, dispatch_time(DISPATCH_TIME_NOW, 1000000)); // 1ms in ns + dispatch_semaphore_wait(messageArrived_, dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_MSEC)); // 1ms } } - - terminated_ = false; - runningNestedLoops_ = false; + + dispatch_sync(this->messageLoopQueue_, ^{ + terminated_ = false; + runningNestedLoops_ = false; + }); } void JsV8InspectorClient::quitMessageLoopOnPause() { - terminated_ = true; + dispatch_sync(this->messageLoopQueue_, ^{ + terminated_ = true; + }); } void JsV8InspectorClient::sendResponse(int callId, std::unique_ptr message) { diff --git a/package.json b/package.json index 1a41e73d..7978f8a5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@nativescript/ios", "description": "NativeScript Runtime for iOS", - "version": "8.2.2", + "version": "8.2.3-alpha.0", "keywords": [ "NativeScript", "iOS",