Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
n-api: update the comment for string api changes
  • Loading branch information
Sampson Gao
Sampson Gao committed Apr 12, 2017
commit f5065794bb19ecacdf75d7734669c3b239c88f43
16 changes: 8 additions & 8 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1734,8 +1734,8 @@ napi_status napi_get_value_string_length(napi_env env,
}

// Copies a JavaScript string into a LATIN-1 string buffer. The result is the
// number of bytes copied into buf, including the null terminator. If bufsize
// is insufficient, the string will be truncated, including a null terminator.
// number of bytes (excluding the null terminator) copied into buf.
// If bufsize is insufficient, the string will be truncated and null terminated.
// If buf is NULL, this method returns the length of the string (in bytes)
// via the result parameter.

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.

Can we clarify here that the length of the string does not include space for the terminator and that you should pass in a buffer of length+1 to avoid truncation ?

// The result argument is optional unless buf is NULL.
Expand Down Expand Up @@ -1767,8 +1767,8 @@ napi_status napi_get_value_string_latin1(napi_env env,
}

// Copies a JavaScript string into a UTF-8 string buffer. The result is the
// number of bytes copied into buf, including the null terminator. If bufsize
// is insufficient, the string will be truncated, including a null terminator.
// number of bytes (excluding the null terminator) copied into buf.
// If bufsize is insufficient, the string will be truncated and null terminated.
// If buf is NULL, this method returns the length of the string (in bytes)
// via the result parameter.
// The result argument is optional unless buf is NULL.
Expand Down Expand Up @@ -1800,10 +1800,10 @@ napi_status napi_get_value_string_utf8(napi_env env,
}

// Copies a JavaScript string into a UTF-16 string buffer. The result is the
// number of 2-byte code units copied into buf, including the null terminator.
// If bufsize is insufficient, the string will be truncated, including a null
// terminator. If buf is NULL, this method returns the length of the string
// (in 2-byte code units) via the result parameter.
// number of 2-byte code units (excluding the null terminator) copied into buf.
// If bufsize is insufficient, the string will be truncated and null terminated.
// If buf is NULL, this method returns the length of the string (in 2-byte

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.

Same comment here as above to explain a buffer of length+1 should be passed in

// code units) via the result parameter.
// The result argument is optional unless buf is NULL.
napi_status napi_get_value_string_utf16(napi_env env,
napi_value value,
Expand Down