-
-
Notifications
You must be signed in to change notification settings - Fork 32k
doc: Updating addons examples #5362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
LGTM if CI is green. |
doc/api/addons.markdown
Outdated
@@ -767,7 +793,7 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) { | |||
double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue(); | |||
MyObject* obj = new MyObject(value); | |||
obj->Wrap(args.This()); | |||
args.GetReturnValue().Set(args.This()); | |||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only return in c++
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, actually. I see your point. No need in return here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove, I personally like returning early.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove it, I think it is confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine for me anyhow. First I was wondering though why args.GetReturnValue().Set(args.This());
is not necessary anymore, but I may have missed API changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine for me anyhow. First I was wondering though why args.GetReturnValue().Set(args.This()); is not necessary anymore, but I may have missed API changes.
Same here, but nodejs/node-addon-examples#49 (comment) says that with a construct call the return value is always this
.
Please remove it, I think it is confusing.
Sure :]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, very interesting. Thanks for pointing at this. If it makes sense, have the content of Bens comment in the docs explicitly.
|
But why? |
To keep it consistent with the |
console.log(obj1.msg+' '+obj2.msg); // 'hello world' | ||
const obj1 = addon('hello'); | ||
const obj2 = addon('world'); | ||
console.log(obj1.msg + ', ' + obj2.msg); // 'hello world' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as long as we're going const
lets go console.log(
${obj1.msg}, ${obj2.msg});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then 'strict mode'
too I suppose ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, console.log
takes variable arguments so console.log(obj1.msg, obj2.msg)
would also work.
lgtm pending the various points above being sorted out |
* Add more explicit error checking in c++ * Specific namespaces in headers * `const` in JS examples instead of `var`
@@ -345,9 +345,12 @@ using v8::Value; | |||
|
|||
void RunCallback(const FunctionCallbackInfo<Value>& args) { | |||
Isolate* isolate = args.GetIsolate(); | |||
if (!args[0]->IsFunction()) { | |||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we throw here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same thing since it's done below, but in terms of a learning experience it may be better to introduce these things at a slower pace? I don't mind either way tbh.
LGTM ... looks like the PR may be to be rebased tho. |
Ping @tomgco - are you still pursuing this? |
7da4fd4
to
c7066fb
Compare
ping @tomgco again |
c133999
to
83c7a88
Compare
Closing given the lack of forward progress on this |
const
in JS examples instead ofvar
cc\ @nodejs/documentation
This is based on the work that is being carried out in nodejs/node-addon-examples#49.