First pass at basic Node Addon API docs#268
First pass at basic Node Addon API docs#268digitalinfinity wants to merge 3 commits intonodejs:masterfrom
Conversation
NickNaso
left a comment
There was a problem hiding this comment.
I tried to give you some suggestions.
| Value is the base class of Node Addon API's fundamental object type hierarchy. | ||
| It represents a JavaScript value of an unknown type. It is a thin wrapper around | ||
| the N-API datatype `napi_value`. Methods on this class can be used to check | ||
| the JavaScript type of the underlying `napi_value` and also convert to C++ |
| - `[in] env` - The `napi_env` environment in which to construct the Value object. | ||
| - `[in] value` - The underlying JavaScript value that the `Value` instance represents | ||
|
|
||
| Used to create a Node addon API `Value` that represents the `napi_value` passed |
There was a problem hiding this comment.
Maybe here we need to use: Returns a Node addon API Value that represents the napi_value passed in.
There was a problem hiding this comment.
Agreed we to follow the standard format we should have a Returns after the parameters.
|
|
||
| - `[in] other` - The value to compare against | ||
|
|
||
| Tests if this value strictly equals another value. |
There was a problem hiding this comment.
Maybe it's better move Tests if this value strictly equals another value. on top and here something like this: Returns true if the value isn strictly equals another value, or false otherwise.
| When C++ exceptions are disabled at compile time, a method with a `Value` | ||
| return type may return an empty value to indicate a pending exception. So when | ||
| not using C++ exceptions, callers should check whether the value is empty | ||
| before attempting to use it. |
There was a problem hiding this comment.
Maybe it's better to move this part on top and here: Returns true if the Value is an empty value.
About the error if the function that you are calling doesn't return value it' more appropriate use Env::IsExceptionPending() to retrieve if there is an active error.
| napi_valuetype Type() const; | ||
| ``` | ||
|
|
||
| Gets the underlying `napi_valuetype` of the value. |
There was a problem hiding this comment.
Maybe it's more appropriate use: Returns
| Converts a `Napi::Value` to a JavasScript Object. This is a wrapper around | ||
| `napi_coerce_to_object`. This will throw a JavaScript exception if the | ||
| coercion fails. | ||
|
|
There was a problem hiding this comment.
Move this part on top and here something like this: Returns a JavaScript Object.
| ## Name | ||
|
|
||
| Names are JavaScript values that can be used as a property name. There are two | ||
| specialized types of names supported in Node Addon API- `String` and `Symbol`. |
| created. If the constructor is invoked passing in an N-API value, then a Name is | ||
| created from the JavaScript primitive. Note that the value is not coerced to a | ||
| string. | ||
|
|
There was a problem hiding this comment.
Maybe it could be better to split this two cases
| ``` | ||
|
|
||
| Returns an empy array. If an error occurs, a `Napi::Error` will get thrown. | ||
|
|
|
|
||
| Wraps a `napi_value` as a `Napi::Array`. If an error occurs, a `Napi::Error` | ||
| will get thrown. | ||
|
|
There was a problem hiding this comment.
Move this on top and here something like this: Returns the primitive top wrap.
| operator napi_value() const; | ||
| ``` | ||
|
|
||
| Returns the underlying N-API value primitive. If the instance is _empty_, |
There was a problem hiding this comment.
How about `Returns the underlying N-API napi_value'. If ...
| bool operator ==(const Value& other) const; | ||
| ``` | ||
|
|
||
| Returns `true` if this value strictly equals another value, or `false` otherwise |
There was a problem hiding this comment.
I think we need full sentences so needs a period at the end of the sentence. Say goes throughout the rest of the doc.
|
|
||
| - `[in] env` - The `napi_env` environment in which to construct the Value object. | ||
| - `[in] value` - The C++ type to represent in JavaScript. | ||
|
|
There was a problem hiding this comment.
Needs a Returns... before the explanation of how it works.
| ```cpp | ||
| template <typename T> T As() const; | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Needs Returns.... same for other places, won't mention it specifically in those other places.
| Casts to another type of `Napi::Value`, when the actual type is known or assumed. | ||
|
|
||
| This conversion does NOT coerce the type. Calling any methods inappropriate for | ||
| the actual value type will throw `Napi::Error`. |
There was a problem hiding this comment.
I think an example here would help.
| Napi::Env Env() const; | ||
| ``` | ||
|
|
||
| Gets the environment the value is associated with. See `napi_env` for more |
There was a problem hiding this comment.
This should probably reference the Env class as opposed to napi_env.
| JavaScript `null` or `undefined`, which are valid values. | ||
|
|
||
| When C++ exceptions are disabled at compile time, a method with a `Value` | ||
| return type may return an empty value to indicate a pending exception. So when |
| This method returns a native representation of a JavaScript array. If an error | ||
| occurs, a `Napi::Error` will get thrown. | ||
|
|
||
| #### New |
| @@ -39,13 +33,41 @@ operator std::u16string() const; | |||
| ``` | |||
There was a problem hiding this comment.
I think an example or more description might be useful here.
| String::New(napi_env env, const std::string& value); | ||
| String::New(napi_env env, const std::u16string& value); | ||
| String::New(napi_env env, const char* value); | ||
| String::New(napi_env env, const char16_t* value); |
There was a problem hiding this comment.
We should talk about this. Its not consistent with anything I've seen elsewhere in the node documentation
There was a problem hiding this comment.
But with overrides it does make sense to me
There was a problem hiding this comment.
Yes, that was kind of what I was thinking. Anyone else have thoughts?
|
Left a few comments but a really good first cut. |
|
@digitalinfinity are you going to get a chance to update for the comments? |
|
@mhdawson yes- so sorry, I've been sidetracked with other things for the past couple weeks but I should be able to find some cycles this week to incorporate all the great feedback provided so far. |
4a0aee8 to
f83f63f
Compare
gabrielschulhof
left a comment
There was a problem hiding this comment.
Just a few nits.
| [C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/) | ||
| Node Addon API consists of a few fundamental data types. These allow a user of | ||
| the API to create, convert and introspect fundamental JavaScript types, and | ||
| interop with their C++ counterparts. |
There was a problem hiding this comment.
I think you should expand this to "interoperate".
| Returns `true` if the value is uninitialized. | ||
|
|
||
| An empty value is invalid, and most attempts to perform an operation on an | ||
| empty value will result in an exception. Note an empty value is distinct from |
There was a problem hiding this comment.
I don't think you need "Note" here.
| bool IsBuffer() const; | ||
| ``` | ||
|
|
||
| Returns `true` if the underlying value is a Node `Buffer` or `false` |
There was a problem hiding this comment.
We should write "Node.js" instead of "Node".
|
|
||
| ## Array | ||
|
|
||
| Arrays are native representations of JavaScript Arrays. `Napi::Array` is sugar |
There was a problem hiding this comment.
I think we should say "a wrapper" instead of "sugar".
|
|
||
| Returns an empty array. | ||
|
|
||
| If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not |
There was a problem hiding this comment.
"will be thrown" might be better – here, and subsequently.
mhdawson
left a comment
There was a problem hiding this comment.
LGTM. After the few minor comments I think it is good to land and we can iterate after that if necessary.
|
I believe all comments are now addressed will land. |
PR-URL: #268 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
|
Landed as e029a07 |
PR-URL: nodejs/node-addon-api#268 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: nodejs/node-addon-api#268 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: nodejs/node-addon-api#268 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: nodejs/node-addon-api#268 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Added docs for Basic Types, Strings and Symbols. Feedback welcome, I think this will take a couple more iterations to get right.