FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

n-api: add napi_get_own_property_names by himself65 · Pull Request #28944 · nodejs/node · GitHub

/ node Public

n-api: add napi_get_own_property_names - #28944

Closed
himself65 wants to merge 3 commits into
nodejs:masterfrom
himself65:28942
Closed

n-api: add napi_get_own_property_names#28944
himself65 wants to merge 3 commits into
nodejs:masterfrom
himself65:28942

Conversation

himself65 commented Aug 2, 2019
edited
Loading

Copy link
Copy Markdown
Member

fix #28942, and this pr should after #30006

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

nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Aug 2, 2019
addaleax added node-api Issues and PRs related to the Node-API. semver-minor PRs that contain new features and should be released in the next minor version. labels Aug 2, 2019
Comment thread test/js-native-api/test_object/test.js Outdated

addaleax commented Aug 2, 2019

Copy link
Copy Markdown
Member

@nodejs/n-api

I feel like this approach kind of leads to questions like “what if we also want symbols/inherited properties/no indices/…”, and we might want to come up with something that has flexibility which is similar to the V8 API?

himself65 force-pushed the 28942 branch 3 times, most recently from e5c0692 to 2e62342 Compare August 2, 2019 18:24
Comment thread src/js_native_api.h Outdated

Copy link
Copy Markdown
Member

+1 to making it more flexible as long as the options supported are part of the standard and will be supported by all engines.

Trott commented Aug 25, 2019

Copy link
Copy Markdown
Member

@addaleax @mhdawson @nodejs/n-api Are we likely to land this? If not, I'd like to close it. If we're likely to land it, I'd like to nudge it forward. /ping @himself65! Or maybe reviewers can perhaps push fixup changes to the branch to get it where it needs to go and expedite things a bit?

Copy link
Copy Markdown
Member

@Trott Yes, but @mhdawson’s comment need to be addressed and we do need somebody (e.g. @himself65) to figure out in what way we expose the other option flags, if we do so.

Copy link
Copy Markdown
Member Author

I will push fixed changes later :)

Comment thread doc/api/n-api.md Outdated
Comment thread doc/api/n-api.md Outdated
Comment thread src/js_native_api_v8.cc Outdated

gabrielschulhof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The PR is good, but we really need to return napi_pending_exception whenever there is the possibility that an exception has occurred on the JS side.

Comment thread src/js_native_api_v8.cc Outdated
himself65 force-pushed the 28942 branch 2 times, most recently from ffd2f2e to b505c1d Compare October 8, 2019 02:42
Comment thread src/js_native_api_v8.h Outdated
himself65 force-pushed the 28942 branch 2 times, most recently from 2564901 to d596434 Compare October 9, 2019 16:17

Copy link
Copy Markdown
Collaborator

Trott commented Oct 16, 2019

Copy link
Copy Markdown
Member

@mhdawson @addaleax LGTY now?

addaleax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

So, code-wise this LGTM, but I still feel like the API should expose flags similar to the ones we get from V8, otherwise this just begs for Yet Another Function That Does The Same Thing.

Comment thread doc/api/n-api.md Outdated

Copy link
Copy Markdown
Contributor

@himself65 can you please check whether other engines, such as JerryScript, have the facilities to retrieve property names as selectively as V8? That is, could the kind of flexibility that V8 provides (skipping/not skipping symbols, rendering as string/leaving as number) be implemented

  • on top of other engines (preferably), or
  • into other engines,

if needed?

Copy link
Copy Markdown
Member

@gabrielschulhof From a look at JerryScript’s API docs, the API only exposes a way to get enumerable properties. But I wouldn’t care too much for that here – any spec-compatible JS implementation needs to have a way to provide all properties, because it could always be implemented in terms of JS builtin functions.

devsnek commented Oct 16, 2019

Copy link
Copy Markdown
Member

the js spec has operations that ask for a filtered subset of own properties, so I think it's reasonable that we can provide something similar here. Even if a napi wrapper has to do the work instead of the engine.

Copy link
Copy Markdown
Contributor

@devsnek @addaleax sounds like we can safely expose the full flexibility provided by V8 because on other engines this same flexibility can be implemented by either filtering after then engine's native API returns, or calling a spec-compliant JS API if the native API is incapable of returning unfiltered results.

Similarly, I guess we can use type coercion in post-processing to address the flexibility in the second parameter.

@himself65 would you mind exposing the two parameters provided by V8?

I suppose we'll have to add a napi_get_all_property_names()(name eminently negotiable 😀) to correspond to napi_get_property_names().

Honestly, I'm not sure whether we shouldn't just go with

typedef enum {
  napi_key_own,
  napi_key_all
} napi_key_collection_mode;

typedef enum {
  napi_key_strings = 1,
  napi_key_symbols = 1 << 1
} napi_key_types;

typedef enum {
  napi_keep_numbers,
  napi_numbers_to_strings
} napi_key_coercion;

napi_status napi_get_all_property_names(napi_env env,
                                        napi_value object,
                                        napi_key_collection_mode key_mode,
                                        napi_key_types key_types,
                                        napi_key_coercion key_coercion,
                                        napi_value* result);

and basically expose v8::Object::GetPropertyNames() pretty much as-is, given that the resulting N-API can be implemented on any spec-compliant engine, if only by calling into JS.

We can then re-implement napi_get_property_names() as a call to this new function.

Copy link
Copy Markdown
Member

Would filter ONLY_ENUMERABLE be reasonable to be supported in this API? Since napi_get_property_names() only expects enumerable property names, if napi_get_property_names() would be re-implemented as a call to this new function, it has to be supported too.

Copy link
Copy Markdown
Contributor

@legendecas right, we need one more enum for one more flag to the method.

Copy link
Copy Markdown
Member Author

I will open a new pull request about that later 🤔

fhinkel commented Nov 1, 2019

Copy link
Copy Markdown
Contributor

ping @himself65

Copy link
Copy Markdown
Member Author

Would filter ONLY_ENUMERABLE be reasonable to be supported in this API? Since napi_get_property_names() only expects enumerable property names, if napi_get_property_names() would be re-implemented as a call to this new function, it has to be supported too.

How to implement that? 🤔

Copy link
Copy Markdown
Member

napi_key_enumerable in #30006 could be used to get enumerable keys on the object. BTW, should this PR be succeeded by #30006? Since #30006 covers every part of this API.

Copy link
Copy Markdown
Member Author

@legendecas Fixed and this pr should after #30006 for now

himself65 force-pushed the 28942 branch 4 times, most recently from 876d845 to ad4a54a Compare November 23, 2019 04:16
himself65 force-pushed the 28942 branch 2 times, most recently from 9bf1126 to d93c285 Compare December 3, 2019 10:43

Copy link
Copy Markdown
Contributor

IINM this PR is superseded by #30006, so I will close it. Please re-open if I am mistaken.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

n-api: add method to get own property names

9 participants


Back | FazBrowse Home | New Git URL