title: Unwrapping objects members with V8/Node.JS
body: <p>I'm learning V8/Node.JS through one of my project and I'm wondering if there is a way to unwrap a C++ object inherited from <code>node::OjectWrap</code> (from the Node.JS API) <strong>and</strong> its members at the same time.</p>
  
  <p>All examples I can found have <code>int</code> members for instance and any of them try to wrap C++ object members. Here is a code explanation of what I want to do:</p>
  
  <pre><code>// A very basic class which only contains a vector member
  // Note that it does not interact with any V8 or Node.JS code
  class B
  {
    public:
    // Constructors and methods...
    size_t getSize(void) { return vec_.size(); };
  
    private:
      std::vector&lt;int&gt; vec_;
  } 
  
  // The class I instanciate correctly in my Javascript code
  class A : public node::ObjectWrap
  {
    public:
      static void Init(v8::Handle&lt;v8::Value&gt; exports);
      static v8::Handle&lt;v8::Value&gt; New(const v8::Arguments&amp; args); // The method I use to instanciate my JS object
      static v8::Handle&lt;v8::Value&gt; Update(const v8::Arguments&amp; args); // A method I call
  
    private:
      A(B b) : b_(b) {};
      ~A(void);
  
    private:
      static v8::Persistent&lt;v8::Function&gt; constructor_;
      B b_;
  }
  </code></pre>
  
  <p>To keep things simple, here is the definitions of <code>A::New</code> and <code>A::Update</code>. I'm using the Google V8 documentation sample code for the others methods.</p>
  
  <pre><code>v8::Handle&lt;v8::Value&gt; A::New(const v8::Arguments&amp; args)
  {
    v8::HandleScope scope;
  
    if (args.IsConstructorCall())
    {
      B b;
      // Fill the vector of B with n elements...
      // If I print here the size of a-&gt;b_.size(), I get n
  
      A* a = new A(b);
      A-&gt;Wrap(args.This());
  
      return args.This();
    }
    else
      // ...
  }
  
  v8::Handle&lt;v8::Value&gt; A::Update(const v8::Arguments&amp; args)
  {
    v8::HandleScope scope;
  
    A* a = ObjectWrap::Unwrap&lt;A&gt;(args.This());
    // If I print here the size of a-&gt;b_.size(), I get a garbage value
  }
  </code></pre>
  
  <p>Finally, my JavaScript code:</p>
  
  <pre><code>var a = new addon.A(/* Constructor parameters *); // Will print the good size value
  a.Update(); // Will print the garbage value
  </code></pre>
  
  <p>It seems that the <code>B</code> member of <code>A</code> is not wrapped correctly. So my question is: is it possible to wrap the object members without inherited them of <code>node::ObjectWrap</code> ?</p>
  
  <p>Thanks for your help.</p>