Re: [v8-users] How to pass the second parameter of ObjectTemplate::New in Google V8?

2017-05-12 Thread Jakob Kummerow
Same question: http://stackoverflow.com/questions/43909594/

On Fri, May 12, 2017 at 7:40 PM, Ben Noordhuis  wrote:

> On Thu, May 11, 2017 at 11:02 AM, XadillaX Scarlet
>  wrote:
> > I know creating an ObjectTemplate and we can do several things to it.
> But my
> > question is not about those well-known things.
> >
> > I want to know how to pass the second parameter.
> >
> > As the official guide said:
> >
> > Each function template has an associated object template. This is used to
> > configure objects created with this function as their constructor.
> >
> > And the second parameter of ObjectTemplate::New is a constructor typed by
> > FunctionTemplate.
> >
> > static Local New(Isolate *isolate,
> Local
> > constructor = Local());
> >
> > That means something like this:
> >
> > void Constructor(const FunctionCallbackInfo& args)
> > {
> > // ...
> > }
> >
> > Local _constructor = FunctionTemplate::New(isolate,
> > Constructor);
> > Local tpl = ObjectTemplate::New(isolate, _constructor);
> >
> > Who can give me a demo that how to implement the Constructor function.
> >
> > I tried this, but failed:
> >
> > void Constructor(const FunctionCallbackInfo& args)
> > {
> > Isolate* isolate = args.GetIsolate();
> > args.This()->Set(String::NewFromUtf8(isolate, "value"),
> > Number::New(isolate, 233));
> > args.GetReturnValue().Set(args.This());
> > }
> >
> > By the way, I know the use case of accessors and so on, I just want to
> know
> > how to use the second parameter.
>
> When you say 'failed', what exactly do you mean?  Is the function not
> called or don't you see the .value property on the new object?
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> 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 v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
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 v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] How to pass the second parameter of ObjectTemplate::New in Google V8?

2017-05-12 Thread Ben Noordhuis
On Thu, May 11, 2017 at 11:02 AM, XadillaX Scarlet
 wrote:
> I know creating an ObjectTemplate and we can do several things to it. But my
> question is not about those well-known things.
>
> I want to know how to pass the second parameter.
>
> As the official guide said:
>
> Each function template has an associated object template. This is used to
> configure objects created with this function as their constructor.
>
> And the second parameter of ObjectTemplate::New is a constructor typed by
> FunctionTemplate.
>
> static Local New(Isolate *isolate, Local
> constructor = Local());
>
> That means something like this:
>
> void Constructor(const FunctionCallbackInfo& args)
> {
> // ...
> }
>
> Local _constructor = FunctionTemplate::New(isolate,
> Constructor);
> Local tpl = ObjectTemplate::New(isolate, _constructor);
>
> Who can give me a demo that how to implement the Constructor function.
>
> I tried this, but failed:
>
> void Constructor(const FunctionCallbackInfo& args)
> {
> Isolate* isolate = args.GetIsolate();
> args.This()->Set(String::NewFromUtf8(isolate, "value"),
> Number::New(isolate, 233));
> args.GetReturnValue().Set(args.This());
> }
>
> By the way, I know the use case of accessors and so on, I just want to know
> how to use the second parameter.

When you say 'failed', what exactly do you mean?  Is the function not
called or don't you see the .value property on the new object?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
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 v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] How to pass the second parameter of ObjectTemplate::New in Google V8?

2017-05-11 Thread XadillaX Scarlet


I know creating an ObjectTemplate and we can do several things to it. But 
my question is not about those well-known things.

I want to know how to pass the second parameter.

As the official guide said:

Each function template has an associated object template. This is used to 
configure objects created with this function as their constructor.

And the second parameter of ObjectTemplate::New is a constructor typed by 
FunctionTemplate.

static Local New(Isolate *isolate, Local 
constructor = Local());

That means something like this:

void Constructor(const FunctionCallbackInfo& args){
// ...}
Local _constructor = FunctionTemplate::New(isolate, 
Constructor);Local tpl = ObjectTemplate::New(isolate, 
_constructor);

Who can give me a demo that how to implement the Constructor function.

I tried this, but failed:

void Constructor(const FunctionCallbackInfo& args){
Isolate* isolate = args.GetIsolate();
args.This()->Set(String::NewFromUtf8(isolate, "value"), 
Number::New(isolate, 233));
args.GetReturnValue().Set(args.This());}

By the way, I know the use case of accessors and so on, I just want to know 
how to use the second parameter.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
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 v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.