If I don't set return value, and only operate on This, how do I associate a
different C++ object to the newly constructed JS object?
The reason that I kept trying to return something other than This was
because I need to dynamically create objects backed by different C++
objects each time the constructor's callback is called. Even when I create
a new function template inheriting the original, and set the return value
to be the inheriting template's function, instanecof still returns false:
v8::Local<v8::FunctionTemplate> subTemp =
v8::FunctionTemplate::New(isolate,createBuilder,builder);
subTemp->Inherit(builderTemp);
return args.GetReturnValue().Set(subTemp->GetFunction());
On Saturday, October 11, 2014 4:01:23 AM UTC-7, Ben Noordhuis wrote:
>
> On Fri, Oct 10, 2014 at 11:14 PM, Jane Chen <[email protected]
> <javascript:>> wrote:
> > One more try:
> >
> > In my constructor function foo:
> >
> > static void
> > foo(const v8::FunctionCallbackInfo<v8::Value>& args)
> > {
> > v8::Isolate* isolate = args.GetIsolate();
> > v8::HandleScope handleScope(isolate);
> > args.GetReturnValue().Set(
> > v8::Local<v8::Function>::Cast(args.This())->New(isolate,bar));
> > }
> >
> >> var f = new Foo();
> >> f instanceof Foo;
> > false
> >
> > Now if I change New to NewInstance, I get a crash from V8. I don't see
> why
> > an instance new'ed from the function still isn't "instanceof" the
> function.
>
> Jane, I'm not sure what you expect that to do but .This() is an
> object, not a function. You _can_ override the return value but I
> don't think you're really supposed to.
>
--
--
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.