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

Convert all locals and parameter names to snake_case #193

Merged
merged 5 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
995 changes: 497 additions & 498 deletions src/node_api.cc

Large diffs are not rendered by default.

68 changes: 28 additions & 40 deletions src/node_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ NAPI_EXTERN const napi_extended_error_info* napi_get_last_error_info();
// Getters for defined singletons
NAPI_EXTERN napi_status napi_get_undefined(napi_env env, napi_value* result);
NAPI_EXTERN napi_status napi_get_null(napi_env env, napi_value* result);
NAPI_EXTERN napi_status napi_get_false(napi_env env, napi_value* result);
NAPI_EXTERN napi_status napi_get_true(napi_env env, napi_value* result);
NAPI_EXTERN napi_status napi_get_global(napi_env env, napi_value* result);
NAPI_EXTERN napi_status napi_get_boolean(napi_env env,
bool value,
napi_value* result);

// Methods to create Primitive types/Objects
NAPI_EXTERN napi_status napi_create_object(napi_env env, napi_value* result);
Expand All @@ -116,21 +117,18 @@ NAPI_EXTERN napi_status napi_create_array_with_length(napi_env env,
size_t length,
napi_value* result);
NAPI_EXTERN napi_status napi_create_number(napi_env env,
double val,
double value,
napi_value* result);
NAPI_EXTERN napi_status napi_create_string_utf8(napi_env env,
const char* s,
const char* str,
size_t length,
napi_value* result);
NAPI_EXTERN napi_status napi_create_string_utf16(napi_env env,
const char16_t* s,
const char16_t* str,
size_t length,
napi_value* result);
NAPI_EXTERN napi_status napi_create_boolean(napi_env env,
bool b,
napi_value* result);
NAPI_EXTERN napi_status napi_create_symbol(napi_env env,
const char* s,
napi_value description,
napi_value* result);
NAPI_EXTERN napi_status napi_create_function(napi_env env,
const char* utf8name,
Expand All @@ -148,9 +146,9 @@ NAPI_EXTERN napi_status napi_create_range_error(napi_env env,
napi_value* result);

// Methods to get the the native napi_value from Primitive type
NAPI_EXTERN napi_status napi_get_type_of_value(napi_env env,
napi_value value,
napi_valuetype* result);
NAPI_EXTERN napi_status napi_typeof(napi_env env,
napi_value value,
napi_valuetype* result);
NAPI_EXTERN napi_status napi_get_value_double(napi_env env,
napi_value value,
double* result);
Expand All @@ -172,24 +170,13 @@ NAPI_EXTERN napi_status napi_get_value_string_length(napi_env env,
napi_value value,
size_t* result);

// Gets the number of BYTES in the UTF-8 encoded representation of the string.
NAPI_EXTERN napi_status napi_get_value_string_utf8_length(napi_env env,
napi_value value,
size_t* result);

// Copies UTF-8 encoded bytes from a string into a buffer.
NAPI_EXTERN napi_status napi_get_value_string_utf8(napi_env env,
napi_value value,
char* buf,
size_t bufsize,
size_t* result);

// Gets the number of 2-byte code units in the UTF-16 encoded
// representation of the string.
NAPI_EXTERN napi_status napi_get_value_string_utf16_length(napi_env env,
napi_value value,
size_t* result);

// Copies UTF-16 encoded bytes from a string into a buffer.
NAPI_EXTERN napi_status napi_get_value_string_utf16(napi_env env,
napi_value value,
Expand Down Expand Up @@ -317,8 +304,8 @@ NAPI_EXTERN napi_status napi_get_cb_args_length(napi_env env,
size_t* result);
NAPI_EXTERN napi_status napi_get_cb_args(napi_env env,
napi_callback_info cbinfo,
napi_value* buffer,
size_t bufferlength);
napi_value* buf,
size_t bufsize);
NAPI_EXTERN napi_status napi_get_cb_this(napi_env env,
napi_callback_info cbinfo,
napi_value* result);
Expand All @@ -343,13 +330,13 @@ napi_define_class(napi_env env,

// Methods to work with external data objects
NAPI_EXTERN napi_status napi_wrap(napi_env env,
napi_value jsObject,
void* nativeObj,
napi_value js_object,
void* native_object,
napi_finalize finalize_cb,
void* finalize_hint,
napi_ref* result);
NAPI_EXTERN napi_status napi_unwrap(napi_env env,
napi_value jsObject,
napi_value js_object,
void** result);
NAPI_EXTERN napi_status napi_create_external(napi_env env,
void* data,
Expand All @@ -375,23 +362,23 @@ NAPI_EXTERN napi_status napi_delete_reference(napi_env env, napi_ref ref);
// Increments the reference count, optionally returning the resulting count.
// After this call the reference will be a strong reference because its
// refcount is >0, and the referenced object is effectively "pinned".
// Calling this when the refcount is 0 and the object isunavailable
// Calling this when the refcount is 0 and the object is unavailable
// results in an error.
NAPI_EXTERN napi_status napi_reference_addref(napi_env env,
napi_ref ref,
int* result);
NAPI_EXTERN napi_status napi_reference_ref(napi_env env,
napi_ref ref,
int* result);

// Decrements the reference count, optionally returning the resulting count.
// If the result is 0 the reference is now weak and the object may be GC'd
// at any time if there are no other references. Calling this when the
// refcount is already 0 results in an error.
NAPI_EXTERN napi_status napi_reference_release(napi_env env,
napi_ref ref,
int* result);
// refcount is already 0 results in an error.
NAPI_EXTERN napi_status napi_reference_unref(napi_env env,
napi_ref ref,
int* result);

// Attempts to get a referenced value. If the reference is weak,
// the value might no longer be available, in that case the call
// is still successful but the result is NULL.
// is still successful but the result is NULL.
NAPI_EXTERN napi_status napi_get_reference_value(napi_env env,
napi_ref ref,
napi_value* result);
Expand Down Expand Up @@ -428,18 +415,19 @@ NAPI_EXTERN napi_status napi_get_and_clear_last_exception(napi_env env,

// Methods to provide node::Buffer functionality with napi types
NAPI_EXTERN napi_status napi_create_buffer(napi_env env,
size_t size,
size_t length,
void** data,
napi_value* result);
NAPI_EXTERN napi_status napi_create_external_buffer(napi_env env,
size_t size,
size_t length,
void* data,
napi_finalize finalize_cb,
void* finalize_hint,
napi_value* result);
NAPI_EXTERN napi_status napi_create_buffer_copy(napi_env env,
size_t length,
const void* data,
size_t size,
void** result_data,
napi_value* result);
NAPI_EXTERN napi_status napi_is_buffer(napi_env env,
napi_value value,
Expand Down
1 change: 1 addition & 0 deletions src/node_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ typedef enum {
napi_function_expected,
napi_number_expected,
napi_boolean_expected,
napi_array_expected,
napi_generic_failure,
napi_pending_exception,
napi_status_last
Expand Down
4 changes: 2 additions & 2 deletions test/addons-napi/2_function_arguments/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ void Add(napi_env env, napi_callback_info info) {
if (status != napi_ok) return;

napi_valuetype valuetype0;
status = napi_get_type_of_value(env, args[0], &valuetype0);
status = napi_typeof(env, args[0], &valuetype0);
if (status != napi_ok) return;

napi_valuetype valuetype1;
status = napi_get_type_of_value(env, args[1], &valuetype1);
status = napi_typeof(env, args[1], &valuetype1);
if (status != napi_ok) return;

if (valuetype0 != napi_number || valuetype1 != napi_number) {
Expand Down
4 changes: 2 additions & 2 deletions test/addons-napi/6_object_wrap/myobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void MyObject::New(napi_env env, napi_callback_info info) {
double value = 0;

napi_valuetype valuetype;
status = napi_get_type_of_value(env, args[0], &valuetype);
status = napi_typeof(env, args[0], &valuetype);
if (status != napi_ok) return;

if (valuetype != napi_undefined) {
Expand Down Expand Up @@ -164,7 +164,7 @@ void MyObject::Multiply(napi_env env, napi_callback_info info) {
if (status != napi_ok) return;

napi_valuetype valuetype;
status = napi_get_type_of_value(env, args[0], &valuetype);
status = napi_typeof(env, args[0], &valuetype);
if (status != napi_ok) return;

double multiple = 1;
Expand Down
2 changes: 1 addition & 1 deletion test/addons-napi/7_factory_wrap/myobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void MyObject::New(napi_env env, napi_callback_info info) {
if (status != napi_ok) return;

napi_valuetype valuetype;
status = napi_get_type_of_value(env, args[0], &valuetype);
status = napi_typeof(env, args[0], &valuetype);
if (status != napi_ok) return;

MyObject* obj = new MyObject();
Expand Down
2 changes: 1 addition & 1 deletion test/addons-napi/8_passing_wrapped/myobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void MyObject::New(napi_env env, napi_callback_info info) {
MyObject* obj = new MyObject();

napi_valuetype valuetype;
status = napi_get_type_of_value(env, args[0], &valuetype);
status = napi_typeof(env, args[0], &valuetype);
if (status != napi_ok) return;

if (valuetype == napi_undefined) {
Expand Down
6 changes: 3 additions & 3 deletions test/addons-napi/test_array/test_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void Test(napi_env env, napi_callback_info info) {
if (status != napi_ok) return;

napi_valuetype valuetype0;
status = napi_get_type_of_value(env, args[0], &valuetype0);
status = napi_typeof(env, args[0], &valuetype0);
if (status != napi_ok) return;

if (valuetype0 != napi_object) {
Expand All @@ -28,7 +28,7 @@ void Test(napi_env env, napi_callback_info info) {
}

napi_valuetype valuetype1;
status = napi_get_type_of_value(env, args[1], &valuetype1);
status = napi_typeof(env, args[1], &valuetype1);
if (status != napi_ok) return;

if (valuetype1 != napi_number) {
Expand Down Expand Up @@ -88,7 +88,7 @@ void New(napi_env env, napi_callback_info info) {
if (status != napi_ok) return;

napi_valuetype valuetype;
status = napi_get_type_of_value(env, args[0], &valuetype);
status = napi_typeof(env, args[0], &valuetype);
if (status != napi_ok) return;

if (valuetype != napi_object) {
Expand Down
12 changes: 6 additions & 6 deletions test/addons-napi/test_buffer/test_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void getDeleterCallCount(napi_env env, napi_callback_info info) {

void copyBuffer(napi_env env, napi_callback_info info) {
napi_value theBuffer;
NAPI_CALL(env,
napi_create_buffer_copy(env, theText, sizeof(theText), &theBuffer));
NAPI_CALL(env, napi_create_buffer_copy(
env, sizeof(theText), theText, NULL, &theBuffer));
NAPI_CALL(env, napi_set_return_value(env, info, theBuffer));
}

Expand All @@ -85,14 +85,14 @@ void bufferHasInstance(napi_env env, napi_callback_info info) {
NAPI_CALL(env, napi_get_cb_args(env, info, &theBuffer, 1));
bool hasInstance;
napi_valuetype theType;
NAPI_CALL(env, napi_get_type_of_value(env, theBuffer, &theType));
NAPI_CALL(env, napi_typeof(env, theBuffer, &theType));
JS_ASSERT(env,
theType == napi_object,
"bufferHasInstance: instance is not an object");
NAPI_CALL(env, napi_is_buffer(env, theBuffer, &hasInstance));
JS_ASSERT(env, hasInstance, "bufferHasInstance: instance is not a buffer");
napi_value returnValue;
NAPI_CALL(env, napi_create_boolean(env, hasInstance, &returnValue));
NAPI_CALL(env, napi_get_boolean(env, hasInstance, &returnValue));
NAPI_CALL(env, napi_set_return_value(env, info, returnValue));
}

Expand All @@ -110,7 +110,7 @@ void bufferInfo(napi_env env, napi_callback_info info) {
theBuffer,
(void **)(&bufferData),
&bufferLength));
NAPI_CALL(env, napi_create_boolean(env,
NAPI_CALL(env, napi_get_boolean(env,
!strcmp(bufferData, theText) && bufferLength == sizeof(theText),
&returnValue));
NAPI_CALL(env, napi_set_return_value(env, info, returnValue));
Expand All @@ -122,7 +122,7 @@ void staticBuffer(napi_env env, napi_callback_info info) {
env,
napi_create_external_buffer(env,
sizeof(theText),
(const char *)(theText),
theText,
noopDeleter,
NULL, // finalize_hint
&theBuffer));
Expand Down
6 changes: 1 addition & 5 deletions test/addons-napi/test_error/test_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ void checkError(napi_env e, napi_callback_info info) {
if (status != napi_ok) return;

napi_value result;
if (r) {
status = napi_get_true(e, &result);
} else {
status = napi_get_false(e, &result);
}
status = napi_get_boolean(e, r, &result);
if (status != napi_ok) return;

status = napi_set_return_value(e, info, result);
Expand Down
2 changes: 1 addition & 1 deletion test/addons-napi/test_exception/test_exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void wasPending(napi_env env, napi_callback_info info) {
napi_status status;

napi_value result;
status = napi_create_boolean(env, exceptionWasPending, &result);
status = napi_get_boolean(env, exceptionWasPending, &result);
if (status != napi_ok) return;

status = napi_set_return_value(env, info, result);
Expand Down
2 changes: 1 addition & 1 deletion test/addons-napi/test_function/test_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void Test(napi_env env, napi_callback_info info) {
if (status != napi_ok) return;

napi_valuetype valuetype;
status = napi_get_type_of_value(env, args[0], &valuetype);
status = napi_typeof(env, args[0], &valuetype);
if (status != napi_ok) return;

if (valuetype != napi_function) {
Expand Down
2 changes: 1 addition & 1 deletion test/addons-napi/test_instanceof/test_instanceof.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void doInstanceOf(napi_env env, napi_callback_info info) {
if (status != napi_ok) return;

napi_value result;
status = napi_create_boolean(env, instanceof, &result);
status = napi_get_boolean(env, instanceof, &result);
if (status != napi_ok) return;

status = napi_set_return_value(env, info, result);
Expand Down
2 changes: 1 addition & 1 deletion test/addons-napi/test_number/test_number.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void Test(napi_env env, napi_callback_info info) {
if (status != napi_ok) return;

napi_valuetype valuetype;
status = napi_get_type_of_value(env, args[0], &valuetype);
status = napi_typeof(env, args[0], &valuetype);
if (status != napi_ok) return;

if (valuetype != napi_number) {
Expand Down
Loading