| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bec2ede commit eda1f45
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,10 +24,6 @@ | |||
| 24 | 24 | ||
| 25 | 25 | 'use strict'; | |
| 26 | 26 | ||
| 27 | - // When using FSReqCallback, make sure to create the object only *after* all | ||
| 28 | - // parameter validation has happened, so that the objects are not kept in memory | ||
| 29 | - // in case they are created but never used due to an exception. | ||
| 30 | - | ||
| 31 | 27 | const { | |
| 32 | 28 | ArrayPrototypePush, | |
| 33 | 29 | BigIntPrototypeToString, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1429,7 +1429,7 @@ static void Query(const FunctionCallbackInfo<Value>& args) { | |||
| 1429 | 1429 | ||
| 1430 | 1430 | void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { | |
| 1431 | 1431 | auto cleanup = OnScopeLeave([&]() { uv_freeaddrinfo(res); }); | |
| 1432 | - std::unique_ptr<GetAddrInfoReqWrap> req_wrap { | ||
| 1432 | + BaseObjectPtr<GetAddrInfoReqWrap> req_wrap{ | ||
| 1433 | 1433 | static_cast<GetAddrInfoReqWrap*>(req->data)}; | |
| 1434 | 1434 | Environment* env = req_wrap->env(); | |
| 1435 | 1435 | ||
@@ -1502,7 +1502,7 @@ void AfterGetNameInfo(uv_getnameinfo_t* req, | |||
| 1502 | 1502 | int status, | |
| 1503 | 1503 | const char* hostname, | |
| 1504 | 1504 | const char* service) { | |
| 1505 | - std::unique_ptr<GetNameInfoReqWrap> req_wrap { | ||
| 1505 | + BaseObjectPtr<GetNameInfoReqWrap> req_wrap{ | ||
| 1506 | 1506 | static_cast<GetNameInfoReqWrap*>(req->data)}; | |
| 1507 | 1507 | Environment* env = req_wrap->env(); | |
| 1508 | 1508 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,9 +77,8 @@ void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle, | |||
| 77 | 77 | template <typename WrapType, typename UVType> | |
| 78 | 78 | void ConnectionWrap<WrapType, UVType>::AfterConnect(uv_connect_t* req, | |
| 79 | 79 | int status) { | |
| 80 | - std::unique_ptr<ConnectWrap> req_wrap | ||
| 81 | - (static_cast<ConnectWrap*>(req->data)); | ||
| 82 | - CHECK_NOT_NULL(req_wrap); | ||
| 80 | + BaseObjectPtr<ConnectWrap> req_wrap{static_cast<ConnectWrap*>(req->data)}; | ||
| 81 | + CHECK(req_wrap); | ||
| 83 | 82 | WrapType* wrap = static_cast<WrapType*>(req->handle->data); | |
| 84 | 83 | CHECK_EQ(req_wrap->env(), wrap->env()); | |
| 85 | 84 | Environment* env = wrap->env(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -460,8 +460,8 @@ MaybeLocal<Promise> FileHandle::ClosePromise() { | |||
| 460 | 460 | ||
| 461 | 461 | CloseReq* req = new CloseReq(env(), close_req_obj, promise, object()); | |
| 462 | 462 | auto AfterClose = uv_fs_callback_t{[](uv_fs_t* req) { | |
| 463 | - std::unique_ptr<CloseReq> close(CloseReq::from_req(req)); | ||
| 464 | - CHECK_NOT_NULL(close); | ||
| 463 | + BaseObjectPtr<CloseReq> close(CloseReq::from_req(req)); | ||
| 464 | + CHECK(close); | ||
| 465 | 465 | close->file_handle()->AfterClose(); | |
| 466 | 466 | if (!close->env()->can_call_into_js()) return; | |
| 467 | 467 | Isolate* isolate = close->env()->isolate(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,13 +20,12 @@ ReqWrap<T>::ReqWrap(Environment* env, | |||
| 20 | 20 | AsyncWrap::ProviderType provider) | |
| 21 | 21 | : AsyncWrap(env, object, provider), | |
| 22 | 22 | ReqWrapBase(env) { | |
| 23 | + MakeWeak(); | ||
| 23 | 24 | Reset(); | |
| 24 | 25 | } | |
| 25 | 26 | ||
| 26 | 27 | template <typename T> | |
| 27 | - ReqWrap<T>::~ReqWrap() { | ||
| 28 | - CHECK_EQ(false, persistent().IsEmpty()); | ||
| 29 | - } | ||
| 28 | + ReqWrap<T>::~ReqWrap() {} | ||
| 30 | 29 | ||
| 31 | 30 | template <typename T> | |
| 32 | 31 | void ReqWrap<T>::Dispatched() { | |
@@ -120,7 +119,8 @@ struct MakeLibuvRequestCallback<ReqT, void(*)(ReqT*, Args...)> { | |||
| 120 | 119 | using F = void(*)(ReqT* req, Args... args); | |
| 121 | 120 | ||
| 122 | 121 | static void Wrapper(ReqT* req, Args... args) { | |
| 123 | - ReqWrap<ReqT>* req_wrap = ReqWrap<ReqT>::from_req(req); | ||
| 122 | + BaseObjectPtr<ReqWrap<ReqT>> req_wrap{ReqWrap<ReqT>::from_req(req)}; | ||
| 123 | + req_wrap->Detach(); | ||
| 124 | 124 | req_wrap->env()->DecreaseWaitingRequestCounter(); | |
| 125 | 125 | F original_callback = reinterpret_cast<F>(req_wrap->original_callback_); | |
| 126 | 126 | original_callback(req, args...); | |
@@ -138,7 +138,6 @@ template <typename T> | |||
| 138 | 138 | template <typename LibuvFunction, typename... Args> | |
| 139 | 139 | int ReqWrap<T>::Dispatch(LibuvFunction fn, Args... args) { | |
| 140 | 140 | Dispatched(); | |
| 141 | - | ||
| 142 | 141 | // This expands as: | |
| 143 | 142 | // | |
| 144 | 143 | // int err = fn(env()->event_loop(), req(), arg1, arg2, Wrapper, arg3, ...) | |
@@ -158,8 +157,10 @@ int ReqWrap<T>::Dispatch(LibuvFunction fn, Args... args) { | |||
| 158 | 157 | env()->event_loop(), | |
| 159 | 158 | req(), | |
| 160 | 159 | MakeLibuvRequestCallback<T, Args>::For(this, args)...); | |
| 161 | - if (err >= 0) | ||
| 160 | + if (err >= 0) { | ||
| 161 | + ClearWeak(); | ||
| 162 | 162 | env()->IncreaseWaitingRequestCounter(); | |
| 163 | + } | ||
| 163 | 164 | return err; | |
| 164 | 165 | } | |
| 165 | 166 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -338,6 +338,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args, | |||
| 338 | 338 | if (err) { | |
| 339 | 339 | delete req_wrap; | |
| 340 | 340 | } else { | |
| 341 | + CHECK(args[2]->Uint32Value(env->context()).IsJust()); | ||
| 341 | 342 | int port = args[2]->Uint32Value(env->context()).FromJust(); | |
| 342 | 343 | TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(TRACING_CATEGORY_NODE2(net, native), | |
| 343 | 344 | "connect", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -665,7 +665,7 @@ int UDPWrap::RecvStop() { | |||
| 665 | 665 | ||
| 666 | 666 | ||
| 667 | 667 | void UDPWrap::OnSendDone(ReqWrap<uv_udp_send_t>* req, int status) { | |
| 668 | - std::unique_ptr<SendWrap> req_wrap{static_cast<SendWrap*>(req)}; | ||
| 668 | + BaseObjectPtr<SendWrap> req_wrap{static_cast<SendWrap*>(req)}; | ||
| 669 | 669 | if (req_wrap->have_callback()) { | |
| 670 | 670 | Environment* env = req_wrap->env(); | |
| 671 | 671 | HandleScope handle_scope(env->isolate()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments