On Wed, Oct 8, 2014 at 12:59 AM, Jane Chen <[email protected]> wrote:
> Picking up this thread again:
>
> I have no problem exposing the class to the global context uisng the pattern
> shown above.  My problem is that the returned value of the class constructor
> is not an instanceof that class if I construct object in it to return:
>
> static void
> foo(const v8::FunctionCallbackInfo<v8::Value>& args)
> {
>   v8::Isolate* isolate = args.GetIsolate();
>   v8::HandleScope handle_scope(isolate);
>   v8::Local<v8::ObjectTemplate> result = v8::ObjectTemplate::New(isolate);
>   result->Set(v8::String::NewFromUtf8(isolate, "print"),
>     v8::FunctionTemplate::New(isolate, Print));
>   result->SetInternalFieldCount(1);
>   v8::Local<v8::Object> builder = result->NewInstance();
>   builder->SetAlignedPointerInInternalField(0,0);
>   return args.GetReturnValue().Set(builder);
> }
>
> v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(isolate,
> foo);
> result->SetClassName(v8::String::NewFromUtf8(isolate,"Foo"));
> global->Set(v8::String::NewFromUtf8(isolate, "Foo"),result);
>
>> var x = new Foo();
>> x instanceof Foo;
> false
>
> Is there any API that allows me to construct a wrapped object in foo() that
> is an instanceof Foo?
>
> Thanks!

I think you have a small bug in your example code.  In the call to
global->Set(), the value should be result->GetFunction().

In no particular order:

- Assign prototype methods with result->PrototypeTemplate()->Set(...),
don't instantiate a new ObjectTemplate.

- args.IsConstructCall() should return true in the constructor function.

- Operate on args.This(), calling args.GetReturnValue().Set() has no effect.

Hope that helps!

-- 
-- 
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/d/optout.

Reply via email to