From 110a9cd8db515c4d1a9ac5cd8837291da7c6c5ea Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 3 Jul 2013 04:23:44 +0200 Subject: lib, src: upgrade after v8 api change This is a big commit that touches just about every file in the src/ directory. The V8 API has changed in significant ways. The most important changes are: * Binding functions take a const v8::FunctionCallbackInfo& argument rather than a const v8::Arguments& argument. * Binding functions return void rather than v8::Handle. The return value is returned with the args.GetReturnValue().Set() family of functions. * v8::Persistent no longer derives from v8::Handle and no longer allows you to directly dereference the object that the persistent handle points to. This means that the common pattern of caching oft-used JS values in a persistent handle no longer quite works, you first need to reconstruct a v8::Local from the persistent handle with the Local::New(isolate, persistent) factory method. A handful of (internal) convenience classes and functions have been added to make dealing with the new API a little easier. The most visible one is node::Cached, which wraps a v8::Persistent with some template sugar. It can hold arbitrary types but so far it's exclusively used for v8::Strings (which was by far the most commonly cached handle type.) --- src/handle_wrap.h | 57 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'src/handle_wrap.h') diff --git a/src/handle_wrap.h b/src/handle_wrap.h index 3a42148a626..d8194b97b0a 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -53,31 +53,38 @@ namespace node { args.This()->GetAlignedPointerFromInternalField(0)); class HandleWrap { - public: - static void Initialize(v8::Handle target); - static v8::Handle Close(const v8::Arguments& args); - static v8::Handle Ref(const v8::Arguments& args); - static v8::Handle Unref(const v8::Arguments& args); - - inline uv_handle_t* GetHandle() { return handle__; }; - - protected: - HandleWrap(v8::Handle object, uv_handle_t* handle); - virtual ~HandleWrap(); - - v8::Persistent object_; - - private: - friend v8::Handle GetActiveHandles(const v8::Arguments&); - static void OnClose(uv_handle_t* handle); - QUEUE handle_wrap_queue_; - // Using double underscore due to handle_ member in tcp_wrap. Probably - // tcp_wrap should rename it's member to 'handle'. - uv_handle_t* handle__; - unsigned int flags_; - - static const unsigned int kUnref = 1; - static const unsigned int kCloseCallback = 2; +public: + static void Initialize(v8::Handle target); + static void Close(const v8::FunctionCallbackInfo& args); + static void Ref(const v8::FunctionCallbackInfo& args); + static void Unref(const v8::FunctionCallbackInfo& args); + + inline uv_handle_t* GetHandle() { return handle__; }; + +protected: + HandleWrap(v8::Handle object, uv_handle_t* handle); + virtual ~HandleWrap(); + + inline v8::Local object() { + return v8::Local::New(node_isolate, persistent()); + } + + inline v8::Persistent& persistent() { + return object_; + } + +private: + friend void GetActiveHandles(const v8::FunctionCallbackInfo&); + static void OnClose(uv_handle_t* handle); + v8::Persistent object_; + QUEUE handle_wrap_queue_; + // Using double underscore due to handle_ member in tcp_wrap. Probably + // tcp_wrap should rename it's member to 'handle'. + uv_handle_t* handle__; + unsigned int flags_; + + static const unsigned int kUnref = 1; + static const unsigned int kCloseCallback = 2; }; -- cgit v1.2.3