Skip to content
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

Implement examples for node 4.x. #49

Closed
wants to merge 1 commit into from
Closed

Conversation

tomgco
Copy link

@tomgco tomgco commented Jan 26, 2016

Hi all,

I have implemented examples 1-7 that targets and compiles on 4.x using the style guides in the doc's.
I would like some feedback as they are very much like the 0.12 versions but the Isolate's are retrieved from the args / Handles.

Thanks 💃

@rvagg
Copy link
Member

rvagg commented Jan 26, 2016

💥

/cc @nodejs/addon-api looking for reviewers pls

void RunCallback(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();

Local<Function> cb = Local<Function>::Cast(args[0]);
Copy link
Member

Choose a reason for hiding this comment

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

You should check that args[0]->IsFunction() before casting it.

EDIT: That should probably be added to the examples for the other node versions as well. The way it's currently written is a ticking time bomb.

Copy link
Author

Choose a reason for hiding this comment

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

Would the following make sense?

if (!args[0]->IsFunction()) {
  return args.GetReturnValue().SetUndefined();
}

Copy link

Choose a reason for hiding this comment

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

Without looking at the surrounding context, I'd say yes. However, the default return value is set to Undefined, so a simple return statement would suffice.

On February 5, 2016 12:23:39 PM GMT+02:00, Tom Gallacher [email protected] wrote:

@@ -0,0 +1,18 @@
+#include <node.h>
+
+using namespace v8;
+
+void RunCallback(const FunctionCallbackInfo& args) {

  • Isolate* isolate = args.GetIsolate();
  • Local cb = Local::Cast(args[0]);

Would the following make sense?

if (!args[0]->IsFunction()) {
 return args.GetReturnValue().SetUndefined();
}

Reply to this email directly or view it on GitHub:
https://github.com/nodejs/node-addon-examples/pull/49/files#r51998512

@tomgco
Copy link
Author

tomgco commented Feb 5, 2016

Thanks for the feedback @bnoordhuis, does anyone from @nodejs/addon-api have any more feedback? I have updated the commit with your fixes and suggestions and I am going to proceed to work on number 8 and then we should hopefully be ready to rock on! :shipit:

@tomgco
Copy link
Author

tomgco commented Feb 5, 2016

Oops, just notice an issue in that last push, 7) doesn't compile, fixing that up.

@tomgco
Copy link
Author

tomgco commented Feb 5, 2016

Oops, just notice an issue in that last push, 7) doesn't compile, fixing that up.

Fixed in 4d6f2ec

@tomgco
Copy link
Author

tomgco commented Feb 5, 2016

Ok, 8 has now been added and I believe that is all of the examples so far! 👯

double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue();
MyObject* obj = new MyObject(value);
obj->Wrap(args.This());
args.GetReturnValue().Set(args.This());
Copy link
Member

Choose a reason for hiding this comment

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

Not strictly necessary in a construct call, the return value is always 'this'.

@bnoordhuis
Copy link
Member

LGTM with suggestions.

@tomgco
Copy link
Author

tomgco commented Feb 5, 2016

I have removed the calls to args.GetReturnValue().Set(args.This()); in construst calls.

@vaibhav93 vaibhav93 mentioned this pull request Feb 11, 2016
@tomgco tomgco changed the title Feedback Needed: Implement examples for node 4.x. Implement examples for node 4.x. Feb 11, 2016
@tomgco
Copy link
Author

tomgco commented Feb 16, 2016

Hey @nodejs/addon-api, any more LGTM's so we can merge this in?

@@ -0,0 +1,8 @@
'use strict';
Copy link
Member

Choose a reason for hiding this comment

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

what is this file? was this accidentally left in the commit or part of something else?

@rvagg
Copy link
Member

rvagg commented Feb 16, 2016

@tomgco great work. Would you mind comparing to https://nodejs.org/docs/latest-v4.x/api/addons.html (you can make test-addons to have these extracted and tested in test/addons/ in core btw) to make sure we're not missing any updates that may have gone in to those. I'd be keen to sync up the two versions and ensure we're taking the best of both worlds. i.e. pull in anything from those versions to here and then PR back to nodejs/node/v4.x-staging an update from here.

While there, also have a look at https://nodejs.org/docs/latest-v5.x/api/addons.html because I'm noticing that we have some nice comments inline now (I think it all may have come from nodejs/node#4320 which I apparently participated in and then promptly forgot!). Perhaps you could pull in the best of all worlds for these updates and we can push them back in to a future v4.x release.

@Knighton910
Copy link

Great job @tomgco progress is needed with this repo, and this is the way to go.

@eljefedelrodeodeljefe
Copy link

I am gonna review and merge this later today. Has anyone changed his / her mind since last viewed?

@Knighton910
Copy link

@eljefedelrodeodeljefe
review and merge this later today = LGTM

@4Z4T4R
Copy link

4Z4T4R commented Jul 29, 2017

Is anyone against forking the origin examples repo and merging all the conflict-free pull requests into that one? OR is there a real need for some fresh eyes to take command of this one as an admin?

@tomgco
Copy link
Author

tomgco commented Dec 8, 2017

Should I close this PR @eljefedelrodeodeljefe, it is now over a year old and N-API is now almost stable making this redundant?

@mhdawson
Copy link
Member

@eljefedelrodeodeljefe I'm going to close this, please let me know fi that is not the right thing to do. 4.x is passed it's LTS support date and the focus is on now on N-API examples.

@mhdawson mhdawson closed this Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants