Skip to content
Permalink
Browse files

n-api: remove unnecessary try-catch bracket from certain APIs

These APIs do not need a try-catch around their body, because no
exceptions are thrown in their implementation:
- `napi_is_array()`
- `napi_get_value_string_latin1()`
- `napi_get_value_string_utf8()`
- `napi_get_value_string_utf16()`
- `napi_get_value_external()`
- `napi_is_buffer()`
- `napi_is_arraybuffer()`
- `napi_get_arraybuffer_info()`
- `napi_is_typedarray()`
- `napi_get_typedarray_info()`

Fixes: nodejs/abi-stable-node#238
PR-URL: #12705
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information...
gabrielschulhof authored and addaleax committed Apr 27, 2017
1 parent 871fb5a commit cd32b77567c43929808902ca429d46effb1431da
Showing with 21 additions and 21 deletions.
  1. +21 −21 src/node_api.cc
@@ -1207,14 +1207,14 @@ napi_status napi_define_properties(napi_env env,
}

napi_status napi_is_array(napi_env env, napi_value value, bool* result) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
CHECK_ARG(env, value);
CHECK_ARG(env, result);

v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);

*result = val->IsArray();
return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

napi_status napi_get_array_length(napi_env env,
@@ -1775,7 +1775,7 @@ napi_status napi_get_value_string_latin1(napi_env env,
char* buf,
size_t bufsize,
size_t* result) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
CHECK_ARG(env, value);

v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
@@ -1795,7 +1795,7 @@ napi_status napi_get_value_string_latin1(napi_env env,
}
}

return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

// Copies a JavaScript string into a UTF-8 string buffer. The result is the
@@ -1811,7 +1811,7 @@ napi_status napi_get_value_string_utf8(napi_env env,
char* buf,
size_t bufsize,
size_t* result) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
CHECK_ARG(env, value);

v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
@@ -1831,7 +1831,7 @@ napi_status napi_get_value_string_utf8(napi_env env,
}
}

return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

// Copies a JavaScript string into a UTF-16 string buffer. The result is the
@@ -1847,7 +1847,7 @@ napi_status napi_get_value_string_utf16(napi_env env,
char16_t* buf,
size_t bufsize,
size_t* result) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
CHECK_ARG(env, value);

v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
@@ -1868,7 +1868,7 @@ napi_status napi_get_value_string_utf16(napi_env env,
}
}

return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

napi_status napi_coerce_to_object(napi_env env,
@@ -2022,13 +2022,13 @@ napi_status napi_create_external(napi_env env,

*result = v8impl::JsValueFromV8LocalValue(external_value);

return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

napi_status napi_get_value_external(napi_env env,
napi_value value,
void** result) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
CHECK_ARG(env, value);
CHECK_ARG(env, result);

@@ -2038,7 +2038,7 @@ napi_status napi_get_value_external(napi_env env,
v8::Local<v8::External> external_value = val.As<v8::External>();
*result = external_value->Value();

return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

// Set initial_refcount to 0 for a weak reference, >0 for a strong reference.
@@ -2479,12 +2479,12 @@ napi_status napi_create_buffer_copy(napi_env env,
}

napi_status napi_is_buffer(napi_env env, napi_value value, bool* result) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
CHECK_ARG(env, value);
CHECK_ARG(env, result);

*result = node::Buffer::HasInstance(v8impl::V8LocalValueFromJsValue(value));
return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

napi_status napi_get_buffer_info(napi_env env,
@@ -2508,14 +2508,14 @@ napi_status napi_get_buffer_info(napi_env env,
}

napi_status napi_is_arraybuffer(napi_env env, napi_value value, bool* result) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
CHECK_ARG(env, value);
CHECK_ARG(env, result);

v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
*result = val->IsArrayBuffer();

return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

napi_status napi_create_arraybuffer(napi_env env,
@@ -2572,7 +2572,7 @@ napi_status napi_get_arraybuffer_info(napi_env env,
napi_value arraybuffer,
void** data,
size_t* byte_length) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
CHECK_ARG(env, arraybuffer);

v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer);
@@ -2589,18 +2589,18 @@ napi_status napi_get_arraybuffer_info(napi_env env,
*byte_length = contents.ByteLength();
}

return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

napi_status napi_is_typedarray(napi_env env, napi_value value, bool* result) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
CHECK_ARG(env, value);
CHECK_ARG(env, result);

v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
*result = val->IsTypedArray();

return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

napi_status napi_create_typedarray(napi_env env,
@@ -2662,7 +2662,7 @@ napi_status napi_get_typedarray_info(napi_env env,
void** data,
napi_value* arraybuffer,
size_t* byte_offset) {
NAPI_PREAMBLE(env);
CHECK_ENV(env);
CHECK_ARG(env, typedarray);

v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(typedarray);
@@ -2710,7 +2710,7 @@ napi_status napi_get_typedarray_info(napi_env env,
*byte_offset = array->ByteOffset();
}

return GET_RETURN_STATUS(env);
return napi_clear_last_error(env);
}

namespace uvimpl {

0 comments on commit cd32b77

Please sign in to comment.
You can’t perform that action at this time.