From cd32b77567c43929808902ca429d46effb1431da Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Thu, 27 Apr 2017 22:15:36 +0300 Subject: [PATCH] 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: https://github.com/nodejs/abi-stable-node/issues/238 PR-URL: https://github.com/nodejs/node/pull/12705 Reviewed-By: Michael Dawson Reviewed-By: Colin Ihrig Reviewed-By: Jason Ginchereau Reviewed-By: Anna Henningsen --- src/node_api.cc | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/node_api.cc b/src/node_api.cc index f35b01dae8f6cd..3067050afbbccf 100644 --- a/src/node_api.cc +++ b/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 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 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 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 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 external_value = val.As(); *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 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 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 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 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 {