34 using v8::FunctionCallbackInfo;
    35 using v8::HandleScope;
    41 void HandleWrap::Ref(
const FunctionCallbackInfo<Value>& args) {
    43   ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
    46     uv_ref(wrap->GetHandle());
    50 void HandleWrap::Unref(
const FunctionCallbackInfo<Value>& args) {
    52   ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
    55     uv_unref(wrap->GetHandle());
    59 void HandleWrap::HasRef(
const FunctionCallbackInfo<Value>& args) {
    61   ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
    62   args.GetReturnValue().Set(HasRef(wrap));
    66 void HandleWrap::Close(
const FunctionCallbackInfo<Value>& args) {
    67   Environment* env = Environment::GetCurrent(args);
    70   ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
    76   if (wrap->state_ != kInitialized)
    79   CHECK_EQ(
false, wrap->persistent().IsEmpty());
    80   uv_close(wrap->handle_, OnClose);
    81   wrap->state_ = kClosing;
    83   if (args[0]->IsFunction()) {
    84     wrap->object()->Set(env->onclose_string(), args[0]);
    85     wrap->state_ = kClosingWithCallback;
    90 HandleWrap::HandleWrap(Environment* env,
    93                        AsyncWrap::ProviderType provider)
    94     : AsyncWrap(env, object, provider),
    98   HandleScope scope(env->isolate());
   100   env->handle_wrap_queue()->PushBack(
this);
   104 HandleWrap::~HandleWrap() {
   105   CHECK(persistent().IsEmpty());
   109 void HandleWrap::OnClose(uv_handle_t* handle) {
   110   HandleWrap* wrap = 
static_cast<HandleWrap*
>(handle->data);
   111   Environment* env = wrap->env();
   112   HandleScope scope(env->isolate());
   113   Context::Scope context_scope(env->context());
   116   CHECK_EQ(wrap->persistent().IsEmpty(), 
false);
   117   CHECK(wrap->state_ >= kClosing && wrap->state_ <= kClosingWithCallback);
   119   const bool have_close_callback = (wrap->state_ == kClosingWithCallback);
   120   wrap->state_ = kClosed;
   122   if (have_close_callback)
   123     wrap->MakeCallback(env->onclose_string(), 0, 
nullptr);
   125   ClearWrap(wrap->object());
   126   wrap->persistent().Reset();