On Tue, Apr 23, 2013 at 2:06 AM, Mike Moening <[email protected]> wrote: > If I have an object I injected into the global using an ObjectTemplate. > The user creates one in script like this: > > var o = new MyObject(); > > That fires my SetCallAsFunctionHandler() which creates the object using the > ObjectTemplate and NewInstance() and passes it back to javascript land. > > Now the script passes that object to another function "doSomething" which > only accepts an argument of type "MyObject" > > doSomething(o); > > How can the C++ native implementation of doSomething() check the type of > object and validate it if of type "MyObject"? > > Handle<Value> > Class::doSomething(const Arguments& args) > { > //Takes 1 argument that MUST be an instance of "MyObject". > > if(args.Length()<0 > || !args[0]->IsObject() > || !args[0]->InstanceOf("MyObject")) <--- Here's the magic. How do I > test for a specific type of object?? Do I use the ObjectTemplate somehow? > { > v8::ThrowException(v8::String::New("doSomething() requires a > MyObject object for parameter 1")); > }
You want FunctionTemplate::HasInstance(), where the FunctionTemplate is the MyObject constructor. -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
