| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 51f01aa commit 6fdc502
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -469,18 +469,18 @@ MessagePort::MessagePort(Environment* env, | |||
| 469 | 469 | Local<Object> wrap) | |
| 470 | 470 | : HandleWrap(env, | |
| 471 | 471 | wrap, | |
| 472 | - reinterpret_cast<uv_handle_t*>(new uv_async_t()), | ||
| 472 | + reinterpret_cast<uv_handle_t*>(&async_), | ||
| 473 | 473 | AsyncWrap::PROVIDER_MESSAGEPORT), | |
| 474 | 474 | data_(new MessagePortData(this)) { | |
| 475 | 475 | auto onmessage = [](uv_async_t* handle) { | |
| 476 | 476 | // Called when data has been put into the queue. | |
| 477 | - MessagePort* channel = static_cast<MessagePort*>(handle->data); | ||
| 477 | + MessagePort* channel = ContainerOf(&MessagePort::async_, handle); | ||
| 478 | 478 | channel->OnMessage(); | |
| 479 | 479 | }; | |
| 480 | 480 | CHECK_EQ(uv_async_init(env->event_loop(), | |
| 481 | - async(), | ||
| 481 | + &async_, | ||
| 482 | 482 | onmessage), 0); | |
| 483 | - async()->data = static_cast<void*>(this); | ||
| 483 | + async_.data = static_cast<void*>(this); | ||
| 484 | 484 | ||
| 485 | 485 | Local<Value> fn; | |
| 486 | 486 | if (!wrap->Get(context, env->oninit_symbol()).ToLocal(&fn)) | |
@@ -494,17 +494,13 @@ MessagePort::MessagePort(Environment* env, | |||
| 494 | 494 | Debug(this, "Created message port"); | |
| 495 | 495 | } | |
| 496 | 496 | ||
| 497 | - uv_async_t* MessagePort::async() { | ||
| 498 | - return reinterpret_cast<uv_async_t*>(GetHandle()); | ||
| 499 | - } | ||
| 500 | - | ||
| 501 | 497 | bool MessagePort::IsDetached() const { | |
| 502 | 498 | return data_ == nullptr || IsHandleClosing(); | |
| 503 | 499 | } | |
| 504 | 500 | ||
| 505 | 501 | void MessagePort::TriggerAsync() { | |
| 506 | 502 | if (IsHandleClosing()) return; | |
| 507 | - CHECK_EQ(uv_async_send(async()), 0); | ||
| 503 | + CHECK_EQ(uv_async_send(&async_), 0); | ||
| 508 | 504 | } | |
| 509 | 505 | ||
| 510 | 506 | void MessagePort::Close(v8::Local<v8::Value> close_callback) { | |
@@ -639,7 +635,6 @@ void MessagePort::OnClose() { | |||
| 639 | 635 | data_->Disentangle(); | |
| 640 | 636 | } | |
| 641 | 637 | data_.reset(); | |
| 642 | - delete async(); | ||
| 643 | 638 | } | |
| 644 | 639 | ||
| 645 | 640 | std::unique_ptr<MessagePortData> MessagePort::Detach() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -198,9 +198,9 @@ class MessagePort : public HandleWrap { | |||
| 198 | 198 | void OnClose() override; | |
| 199 | 199 | void OnMessage(); | |
| 200 | 200 | void TriggerAsync(); | |
| 201 | - inline uv_async_t* async(); | ||
| 202 | 201 | ||
| 203 | 202 | std::unique_ptr<MessagePortData> data_ = nullptr; | |
| 203 | + uv_async_t async_; | ||
| 204 | 204 | ||
| 205 | 205 | friend class MessagePortData; | |
| 206 | 206 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments