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

napi names for new types and methods #20170

Closed
devsnek opened this issue Apr 20, 2018 · 22 comments
Closed

napi names for new types and methods #20170

devsnek opened this issue Apr 20, 2018 · 22 comments
Labels
node-api Issues and PRs related to the Node-API.

Comments

@devsnek
Copy link
Member

devsnek commented Apr 20, 2018

I'm working on patches to add bigint and scripts and modules to napi, but the current names of types and methods are causing consistency issues.

bigint:

napi_create_double,int32,int64 instead of napi_create_number makes me unsure of what to name creating a bigint so ideas are needed.

scripts/modules:

we have the type napi_module already and it would be an inconsistency to have stuff like napi_js_module and napi_js_script so ideas are needed.

@addaleax addaleax added the node-api Issues and PRs related to the Node-API. label Apr 20, 2018
@targos
Copy link
Member

targos commented Apr 20, 2018

@nodejs/n-api

@mhdawson
Copy link
Member

Each of those refer to the native type you are starting with (double, int32, int64) they might be better named something like napi_create_number_from_int32 etc but at this we can't easily rename.

For big int I could see using something like:

napi_create_bigint_from_XXX, where XXX is the native type you want to be able to provide, along with the corresponding napi_get_XXX_from_bigint.

For modules can you show a few examples the functions that the module types would be used as I think I need a bit more context to understand.

@devsnek
Copy link
Member Author

devsnek commented Apr 20, 2018

@mhdawson that looks like a better name scheme, but it makes me wonder if we can't just use overrides?

also for modules it's a bit like

napi_module module;
napi_create_module(env, source, url, &module);

and the same for scripts but with napi_script and filename

@devsnek
Copy link
Member Author

devsnek commented Apr 20, 2018

and the get methods are actually fine because we can check what kind of value is passed (v8::Value::IsBigInt)

@mhdawson
Copy link
Member

when you mean just have napi_create_bigint, which accepts the different native types through overrides? If so that sounds reasonable.

@mhdawson
Copy link
Member

Does it need to be its own type as opposed to it being napi_value module in the example above ? I'm assuming it will be opaque to the native code once created.

@devsnek
Copy link
Member Author

devsnek commented Apr 20, 2018

@mhdawson napi_value holds a Local<Value> but modules are Local<Module> and scripts are Local<Script> and they can't be abstracted to Values as I understand it the cast isn't safe

@devsnek
Copy link
Member Author

devsnek commented Apr 20, 2018

does this api work for everyone? (TIL you can't do overrides in c :D)

@TimothyGu
Copy link
Member

TimothyGu commented Apr 20, 2018

Why do we need any create_bigint other than int64? (and also it's overloading rather than overriding)

@devsnek
Copy link
Member Author

devsnek commented Apr 20, 2018

@TimothyGu no idea, why do we need any other create_number besides double... isn't that an implementation detail of v8?

alternative:

@TimothyGu
Copy link
Member

isn't that an implementation detail of v8?

Yes, but it has performance implications and (AFAIK) is relatively universal among engines.

@devsnek
Copy link
Member Author

devsnek commented Apr 21, 2018

fwiw both chakra and spidermonkey only have double and int, jerryscript only takes double. i'd be fine with dropping the rest

@TimothyGu
Copy link
Member

TimothyGu commented Apr 21, 2018

I'm fine with dropping napi_create_int64(), as napi_create_double() suffices for that purpose. Otherwise, the current API as a least common multiple of all the different APIs out there looks just fine with me.

The other consideration is if we want to drop any APIs at all, since N-API is supposed to be API/ABI-stable.

@devsnek
Copy link
Member Author

devsnek commented Apr 21, 2018

they can be deprecated forever I suppose, i assumed that major versions of node could make major changes, since this api is directly tied to node

@addaleax
Copy link
Member

I don’t think there’s any compelling reason to remove any API here – the existing ones work and people might have use cases for those. Also, at least for V8, I don’t know whether napi_create_int32() is faster, but it definitely has a shorter path inside V8 for creating the handle.

@devsnek
Copy link
Member Author

devsnek commented Apr 21, 2018

@addaleax yea int32 is fine like i said above but uint32 and int64 seem a bit extra as v8 is the only engine that has consumers for those types and since napi_create_int64 is just a terrible terrible terrible terrible idea

@devsnek
Copy link
Member Author

devsnek commented Apr 21, 2018

also i am still unsure of what to do for scripts and modules

@mhdawson
Copy link
Member

Ignoring deprecating existing functions which we can discuss separately, the addition to the api would be:

napi_create_bigint

Right ?

@devsnek
Copy link
Member Author

devsnek commented Apr 25, 2018

@mhdawson yes, and i'd also like to add running scripts and modules in another pr as well

@TimothyGu
Copy link
Member

I would prefer naming the new function napi_create_bigint_int64 since BigInt is arbitrary-precision and there isn’t an intrinsic bit width associated with it.

@mhdawson
Copy link
Member

@devsnek you mentioned in a different issue that you already have some code for the module/script API. Can you post a link where we can look at that to add a bit more context? Might help me think of some better suggestions.

@devsnek
Copy link
Member Author

devsnek commented Apr 27, 2018

@mhdawson here's what i made so far but i think there are some design decisions here i don't think should make it into the final product https://gist.github.com/devsnek/2fd71cab12f3f077f6ee70d2efa60854

i also feel this api should support multiple contexts but i have no idea how to reason with that

@devsnek devsnek closed this as completed May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

No branches or pull requests

5 participants