Skip to content

Conversation

@cjihrig
Copy link
Contributor

Refs: #13925

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-botnodejs-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 Jul 3, 2017
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest being explicit about Symbol support here

Copy link
Member

Choose a reason for hiding this comment

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

Can we add a note about side effects? E.g., what if the object is a revoked proxy? If the key is not to name?

Copy link
Member

Choose a reason for hiding this comment

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

Can we add a test case where the key is not a name?

src/node_api.cc Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Rather than returning false, shouldn't we call the ToPrimitive method on the key? I'm thinking of an example like this:

var x ={hello: 17} var o ={[Symbol.toPrimitive] : function(){return 'hello'}} x.hasOwnProperty(o) // true 

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@fhinkel what ToPrimitive() method? I'm not seeing anything exposed by the V8 API except for retrieving the symbol itself, but maybe I'm just missing it.

Also cc @nodejs/n-api as this case isn't handled anywhere else in n-api.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we expose it by itself. According to the spec, the key is converted to a name, which calls toPrimitive, toPropertyKey.

So, I think we should delete the return false if not IsName(), and let V8 handle it in a spec compliant way. V8 only needs a value, not a string/symbol here.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I'm all for letting V8 handle this, but I get a compiler error passing in a Value :-/

../src/node_api.cc:1042:60: note: in instantiation of function template specialization 'v8::Local<v8::Name>::Local<v8::Value>' requested here v8::Maybe<bool> has_maybe = obj->HasOwnProperty(context, k); 

It looks like V8 expects a Name.

Copy link
Member

@fhinkelfhinkelJul 6, 2017

Choose a reason for hiding this comment

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

You're right, I was looking at a comment for has(). Sorry for the confusion. I think we should make sure though that it's obvious that the n-api function is not identical to JS behavior, in particular, that we'll never use the ToPrimitive symbol if the key is an object. (We should probably point that out in the V8 API, but there it might be less of an issue because we only allow names.)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@fhinkel I added a note to the docs that no type conversions will be performed. That should cover ToPrimitive and any other implicit conversions.

@cjihrig
Copy link
ContributorAuthor

Nits addressed, minus the ToPrimitive() piece.

src/node_api.cc Outdated
Copy link
Member

@fhinkelfhinkelJul 6, 2017

Choose a reason for hiding this comment

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

You're right, I was looking at a comment for has(). Sorry for the confusion. I think we should make sure though that it's obvious that the n-api function is not identical to JS behavior, in particular, that we'll never use the ToPrimitive symbol if the key is an object. (We should probably point that out in the V8 API, but there it might be less of an issue because we only allow names.)

@cjihrig
Copy link
ContributorAuthor

Refs: nodejs#13925 PR-URL: nodejs#14063 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
@cjihrigcjihrig merged commit 9c6804c into nodejs:masterJul 6, 2017
@cjihrigcjihrig deleted the has-own branch July 6, 2017 19:29
addaleax pushed a commit that referenced this pull request Jul 11, 2017
Refs: #13925 PR-URL: #14063 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
@addaleaxaddaleax mentioned this pull request Jul 11, 2017
addaleax pushed a commit that referenced this pull request Jul 18, 2017
Refs: #13925 PR-URL: #14063 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Fishrock123 pushed a commit that referenced this pull request Jul 19, 2017
Refs: #13925 PR-URL: #14063 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Apr 10, 2018
Refs: nodejs#13925 PR-URL: nodejs#14063 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 16, 2018
Refs: #13925 Backport-PR-URL: #19447 PR-URL: #14063 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
@MylesBorinsMylesBorins mentioned this pull request Apr 16, 2018
Sign up for freeto 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-apiIssues and PRs related to the Node-API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@cjihrig@fhinkel@addaleax@MylesBorins@nodejs-github-bot