core: set PROVIDER type as Persistent class id
authorTrevor Norris <trev.norris@gmail.com>
Mon, 18 May 2015 22:39:53 +0000 (16:39 -0600)
committerTrevor Norris <trev.norris@gmail.com>
Tue, 19 May 2015 15:36:36 +0000 (09:36 -0600)
Pass along the PROVIDER type, that is already passed to AsyncWrap, along
to BaseObject to set the handle_'s class id. This will allow all
Persistents to be transversed and uniquely identified by what type they
are using APIs such as v8::PersistentHandleVisitor.

PR-URL: https://github.com/nodejs/io.js/pull/1730
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
src/async-wrap-inl.h
src/base-object-inl.h
src/base-object.h

index bad634d..0518cd3 100644 (file)
@@ -17,7 +17,8 @@ inline AsyncWrap::AsyncWrap(Environment* env,
                             v8::Handle<v8::Object> object,
                             ProviderType provider,
                             AsyncWrap* parent)
-    : BaseObject(env, object), bits_(static_cast<uint32_t>(provider) << 1) {
+    : BaseObject(env, object, provider),
+      bits_(static_cast<uint32_t>(provider) << 1) {
   // Check user controlled flag to see if the init callback should run.
   if (!env->using_asyncwrap())
     return;
index db0daa1..775b073 100644 (file)
 
 namespace node {
 
-inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
+inline BaseObject::BaseObject(Environment* env,
+                              v8::Local<v8::Object> handle,
+                              const uint16_t class_id)
     : handle_(env->isolate(), handle),
       env_(env) {
   CHECK_EQ(false, handle.IsEmpty());
+  // Shift value 8 bits over to try avoiding conflict with anything else.
+  if (class_id != 0)
+    handle_.SetWrapperClassId(class_id << 8);
 }
 
 
index 5a7b958..90abee4 100644 (file)
@@ -9,7 +9,9 @@ class Environment;
 
 class BaseObject {
  public:
-  BaseObject(Environment* env, v8::Local<v8::Object> handle);
+  BaseObject(Environment* env,
+             v8::Local<v8::Object> handle,
+             const uint16_t class_id = 0);
   virtual ~BaseObject();
 
   // Returns the wrapped object.  Returns an empty handle when