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

n-api: add napi_delete_property() #13934

Merged
merged 1 commit into from Jul 1, 2017
Merged

n-api: add napi_delete_property() #13934

merged 1 commit into from Jul 1, 2017

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Jun 26, 2017

Refs: #13924

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

n-api

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. node-api Issues and PRs related to the Node-API. labels Jun 26, 2017
@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 26, 2017

@mhdawson I changed the function signature slightly. I added a return value because delete operations return a boolean.

src/node_api.cc Outdated
CHECK_TO_OBJECT(env, context, obj, object);
v8::Maybe<bool> delete_maybe = obj->Delete(context, k);
CHECK_MAYBE_NOTHING(env, delete_maybe, napi_generic_failure);
*result = delete_maybe.FromMaybe(false);
Copy link
Member

Choose a reason for hiding this comment

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

Check that result is not null before assigning to it. Some callers may not care about the result, so allow them to pass null to ignore it.

src/node_api.cc Outdated
napi_value key,
bool* result) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
Copy link
Member

Choose a reason for hiding this comment

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

NAPI_PREAMBLE(env) already calls CHECK_ENV(env), so the latter is redundant here.

doc/api/n-api.md Outdated
- `[in] env`: The environment that the N-API call is invoked under.
- `[in] object`: The object to query.
- `[in] key`: The name of the property to delete.
- `[out] result`: Whether the property deletion succeeded or not.
Copy link
Member

Choose a reason for hiding this comment

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

Mention result is optional.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM once @jasongin's comments are addressed.

@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 27, 2017

Comments addressed.


- `[in] env`: The environment that the N-API call is invoked under.
- `[in] object`: The object to query.
- `[in] key`: The name of the property to delete.
Copy link
Member

Choose a reason for hiding this comment

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

Can key be a napi number? Either way it's fine but just thought that it could be helpful to point that out in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found this section in the documentation that provides some blanket statements for all of the methods for working with properties. Specifically, see:

JavaScript value: these are represented in N-API by napi_value. This can be a napi_value representing a String, Number or Symbol.

Given that, and the surrounding documentation, I'd prefer to keep this as is in this PR. However, I think the n-api documentation as a whole should be made more consistent with the rest of the Node docs. For example, I think each method should document that key can be a number, string, or symbol. That way, users don't have to read the entire page/section/whatever to get that information.

const sym = Symbol();
const obj = { foo: 'bar', [sym]: 'baz' };

assert.strictEqual('foo' in obj, true);
Copy link
Member

Choose a reason for hiding this comment

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

why not just assert('foo' in obj)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No specific reason. Just being more explicit.

@cjihrig
Copy link
Contributor Author

cjihrig commented Jul 1, 2017

Fixes: nodejs#13924
PR-URL: nodejs#13934
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
@cjihrig cjihrig merged commit 732ae41 into nodejs:master Jul 1, 2017
@cjihrig cjihrig deleted the napi branch July 1, 2017 15:46
addaleax pushed a commit to addaleax/node that referenced this pull request Jul 3, 2017
Fixes: nodejs#13924
PR-URL: nodejs#13934
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
@addaleax addaleax mentioned this pull request Jul 3, 2017
addaleax pushed a commit that referenced this pull request Jul 11, 2017
Fixes: #13924
PR-URL: #13934
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
addaleax pushed a commit that referenced this pull request Jul 18, 2017
Fixes: #13924
PR-URL: #13934
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Apr 10, 2018
Fixes: nodejs#13924
PR-URL: nodejs#13934
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
MylesBorins pushed a commit that referenced this pull request Apr 16, 2018
Fixes: #13924
Backport-PR-URL: #19447
PR-URL: #13934
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
@MylesBorins MylesBorins mentioned this pull request Apr 16, 2018
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++. node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants