Get prototype from a constructor without creating an instance in v8

I am writing a v8 node extension that exports object constructors, as shown in this documentation. Some of the functions take instances of other classes as arguments, so I want to check the types of those arguments, similar to what this answer suggests. One thing it suggests is comparing the object's prototype with a known-correct prototype from a temporary instance, like

Local<Object> obj = constructor->NewInstance();
prototype = Persistent<Value>::New(obj->GetPrototype());
if (instance->GetPrototype() == prototype) { //...

However, some of my constructors are complex and take instances of the other classes as arguments, so this would be very inconvenient.

My class initialization functions look like this (taken from the linked template):

void MyObject::Init(Handle<Object> exports) {
  // Prepare constructor template
  Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
  tpl->SetClassName(String::NewSymbol("MyObject"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  // Prototype
  tpl->PrototypeTemplate()->Set(String::NewSymbol("plusOne"),
      FunctionTemplate::New(PlusOne)->GetFunction());
  constructor = Persistent<Function>::New(tpl->GetFunction());
  exports->Set(String::NewSymbol("MyObject"), constructor);
}

Is it possible to get a prototype object from either the FunctionTemplate or the constructor such that if I get a new instance obj of MyObject, obj->GetPrototype() will compare equal with prototype?

I tried using tpl->PrototypeTemplate()->NewInstance() and constructor->GetPrototype(), but neither seemed to have the correct value.


This is a complete example of what I want to do:

#include <node.h>
#include <v8.h>

using namespace v8;

class MyObject : public node::ObjectWrap {
 public:
  static void Init(Handle<Object> exports);
  static Persistent<Value> prototype;

 private:
  static Handle<Value> New(const v8::Arguments& args);
  static Handle<Value> TypeTest(const v8::Arguments& args);
  static Persistent<Function> constructor;
};

Persistent<Function> MyObject::constructor;
Persistent<Value> MyObject::prototype;

void MyObject::Init(Handle<Object> exports) {
  Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
  tpl->SetClassName(String::NewSymbol("MyObject"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  tpl->PrototypeTemplate()->Set(
      String::NewSymbol("typeTest"),
      FunctionTemplate::New(TypeTest)->GetFunction());
  constructor = Persistent<Function>::New(tpl->GetFunction());
  prototype = Persistent<Value>::New(tpl->PrototypeTemplate()->NewInstance());
  exports->Set(String::NewSymbol("MyObject"),
               constructor);
}

Handle<Value> MyObject::New(const Arguments& args) {
  HandleScope scope;
  if (args.IsConstructCall()) {
    MyObject *obj = new MyObject();
    obj->Wrap(args.This());
    return args.This();
  } else {
    return scope.Close(constructor->NewInstance());
  }
}

Handle<Value> MyObject::TypeTest(const Arguments& args) {
  HandleScope scope;
  if(args.This()->GetPrototype() != prototype) {
    return ThrowException(Exception::TypeError(
        String::New("This should not happen")));
  }
  return Undefined();
}

NODE_MODULE(hello, MyObject::Init);

Currently, if I run the following code in node (after building the addon), I get the type error:

var hello = require('./build/Release/hello');
var obj = new hello.MyObject();
obj.typeTest();

Is there any way to set MyObject::prototype so that I don't get the error without constructing a temporary instance of MyObject?

Couldn't you set the static prototype value the first time you create an object, rather than inside Init? Something like this:

class MyObject : public node::ObjectWrap {
   // ... as before ...
};

Persistent<Function> MyObject::constructor;
Persistent<Value> MyObject::prototype;

void MyObject::Init(Handle<Object> exports)
   // ... as before but without setting prototype ...
}

Handle<Value> MyObject::New(const Arguments& args) {
  HandleScope scope;
  if (args.IsConstructCall()) {
    MyObject *obj = new MyObject();
    obj->Wrap(args.This());
    prototype = Persistent<Value>::New(args.This()->GetPrototype());
    return args.This();
  } else {
    return scope.Close(constructor->NewInstance());
  }
}

Handle<Value> MyObject::TypeTest(const Arguments& args) {
  HandleScope scope;
  if(args.This()->GetPrototype() != prototype) {
    return ThrowException(Exception::TypeError(
        String::New("This should not happen")));
  }
  return Undefined();
}

NODE_MODULE(hello, MyObject::Init);