Skip to content

Commit

Permalink
n-api: remove unnecessary try-catch bracket from certain APIs
Browse files Browse the repository at this point in the history
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
Gabriel Schulhof authored and addaleax committed May 3, 2017
1 parent 871fb5a commit cd32b77
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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);

Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cd32b77

Please sign in to comment.