Skip to content

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

Closed
wants to merge 1 commit into from
Closed

Conversation

tomgco
Copy link
Contributor

@tomgco tomgco commented Feb 22, 2016

  • Add more explicit error checking in c++
  • Specific namespaces in headers
  • const in JS examples instead of var

cc\ @nodejs/documentation

This is based on the work that is being carried out in nodejs/node-addon-examples#49.

@mscdex mscdex added c++ Issues and PRs that require attention from people who are familiar with C++. doc Issues and PRs related to the documentations. labels Feb 22, 2016
@indutny
Copy link
Member

indutny commented Feb 22, 2016

LGTM if CI is green.

@indutny
Copy link
Member

indutny commented Feb 22, 2016

@@ -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;
Copy link
Contributor

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++?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine.

Copy link
Member

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!

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 :]

Copy link
Contributor

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.

@eljefedelrodeodeljefe
Copy link
Contributor

Looks good. I am not the biggest fan of having using node::ObjectWrap; and implicit namespaces for V8, but I am no real c++ dev though. Also it was inconsistent before, right? LGTM minus discussion about namespaces

@bnoordhuis
Copy link
Member

Specific namespaces in headers

But why?

@tomgco
Copy link
Contributor Author

tomgco commented Feb 23, 2016

But why?

To keep it consistent with the .cc files, it seems strange to me that we switch between implicit in one file and not in another.

console.log(obj1.msg+' '+obj2.msg); // 'hello world'
const obj1 = addon('hello');
const obj2 = addon('world');
console.log(obj1.msg + ', ' + obj2.msg); // 'hello world'
Copy link
Member

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});

Copy link
Member

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 ..

Copy link
Member

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.

@rvagg
Copy link
Member

rvagg commented Feb 23, 2016

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;
Copy link
Contributor

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?

Copy link
Member

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.

@jasnell
Copy link
Member

jasnell commented Mar 2, 2016

LGTM ... looks like the PR may be to be rebased tho.

@benjamingr
Copy link
Member

Ping @tomgco - are you still pursuing this?

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Apr 19, 2016
@estliberitas estliberitas force-pushed the master branch 2 times, most recently from 7da4fd4 to c7066fb Compare April 26, 2016 05:23
@addaleax
Copy link
Member

ping @tomgco again

@jasnell
Copy link
Member

jasnell commented Feb 28, 2017

Closing given the lack of forward progress on this

@jasnell jasnell closed this Feb 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. doc Issues and PRs related to the documentations. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants