summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2019-05-21 11:40:22 +0200
committerDaniel Bevenius <daniel.bevenius@gmail.com>2019-05-24 05:19:34 +0200
commitc56474f9fe8785c0e13b72df769806f07a0846df (patch)
tree3aebec2bb4d626d3ef4cbd73a252e5c21c4322c8 /src
parent99268b1e996d13a0aeda7aa112796484fe4e4238 (diff)
downloadandroid-node-v8-c56474f9fe8785c0e13b72df769806f07a0846df.tar.gz
android-node-v8-c56474f9fe8785c0e13b72df769806f07a0846df.tar.bz2
android-node-v8-c56474f9fe8785c0e13b72df769806f07a0846df.zip
n-api: DRY napi_coerce_to_x() API methods
PR-URL: https://github.com/nodejs/node/pull/27796 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/js_native_api_v8.cc68
1 files changed, 22 insertions, 46 deletions
diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc
index da460e6b52..413231dd36 100644
--- a/src/js_native_api_v8.cc
+++ b/src/js_native_api_v8.cc
@@ -2139,21 +2139,6 @@ napi_status napi_get_value_string_utf16(napi_env env,
return napi_clear_last_error(env);
}
-napi_status napi_coerce_to_object(napi_env env,
- napi_value value,
- napi_value* result) {
- NAPI_PREAMBLE(env);
- CHECK_ARG(env, value);
- CHECK_ARG(env, result);
-
- v8::Local<v8::Context> context = env->context();
- v8::Local<v8::Object> obj;
- CHECK_TO_OBJECT(env, context, obj, value);
-
- *result = v8impl::JsValueFromV8LocalValue(obj);
- return GET_RETURN_STATUS(env);
-}
-
napi_status napi_coerce_to_bool(napi_env env,
napi_value value,
napi_value* result) {
@@ -2168,37 +2153,28 @@ napi_status napi_coerce_to_bool(napi_env env,
return GET_RETURN_STATUS(env);
}
-napi_status napi_coerce_to_number(napi_env env,
- napi_value value,
- napi_value* result) {
- NAPI_PREAMBLE(env);
- CHECK_ARG(env, value);
- CHECK_ARG(env, result);
-
- v8::Local<v8::Context> context = env->context();
- v8::Local<v8::Number> num;
-
- CHECK_TO_NUMBER(env, context, num, value);
-
- *result = v8impl::JsValueFromV8LocalValue(num);
- return GET_RETURN_STATUS(env);
-}
-
-napi_status napi_coerce_to_string(napi_env env,
- napi_value value,
- napi_value* result) {
- NAPI_PREAMBLE(env);
- CHECK_ARG(env, value);
- CHECK_ARG(env, result);
-
- v8::Local<v8::Context> context = env->context();
- v8::Local<v8::String> str;
-
- CHECK_TO_STRING(env, context, str, value);
-
- *result = v8impl::JsValueFromV8LocalValue(str);
- return GET_RETURN_STATUS(env);
-}
+#define GEN_COERCE_FUNCTION(UpperCaseName, MixedCaseName, LowerCaseName) \
+ napi_status napi_coerce_to_##LowerCaseName(napi_env env, \
+ napi_value value, \
+ napi_value* result) { \
+ NAPI_PREAMBLE(env); \
+ CHECK_ARG(env, value); \
+ CHECK_ARG(env, result); \
+ \
+ v8::Local<v8::Context> context = env->context(); \
+ v8::Local<v8::MixedCaseName> str; \
+ \
+ CHECK_TO_##UpperCaseName(env, context, str, value); \
+ \
+ *result = v8impl::JsValueFromV8LocalValue(str); \
+ return GET_RETURN_STATUS(env); \
+ }
+
+GEN_COERCE_FUNCTION(NUMBER, Number, number)
+GEN_COERCE_FUNCTION(OBJECT, Object, object)
+GEN_COERCE_FUNCTION(STRING, String, string)
+
+#undef GEN_COERCE_FUNCTION
napi_status napi_wrap(napi_env env,
napi_value js_object,