Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b7ad12

Browse filesBrowse files
bnoordhuistargos
authored andcommitted
n-api: DRY napi_coerce_to_x() API methods
PR-URL: #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>
1 parent 530e63a commit 2b7ad12
Copy full SHA for 2b7ad12

File tree

Expand file treeCollapse file tree

1 file changed

+22
-46
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-46
lines changed
Open diff view settings
Collapse file

‎src/js_native_api_v8.cc‎

Copy file name to clipboardExpand all lines: src/js_native_api_v8.cc
+22-46Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,21 +2139,6 @@ napi_status napi_get_value_string_utf16(napi_env env,
21392139
return napi_clear_last_error(env);
21402140
}
21412141

2142-
napi_status napi_coerce_to_object(napi_env env,
2143-
napi_value value,
2144-
napi_value* result) {
2145-
NAPI_PREAMBLE(env);
2146-
CHECK_ARG(env, value);
2147-
CHECK_ARG(env, result);
2148-
2149-
v8::Local<v8::Context> context = env->context();
2150-
v8::Local<v8::Object> obj;
2151-
CHECK_TO_OBJECT(env, context, obj, value);
2152-
2153-
*result = v8impl::JsValueFromV8LocalValue(obj);
2154-
return GET_RETURN_STATUS(env);
2155-
}
2156-
21572142
napi_status napi_coerce_to_bool(napi_env env,
21582143
napi_value value,
21592144
napi_value* result) {
@@ -2168,37 +2153,28 @@ napi_status napi_coerce_to_bool(napi_env env,
21682153
return GET_RETURN_STATUS(env);
21692154
}
21702155

2171-
napi_status napi_coerce_to_number(napi_env env,
2172-
napi_value value,
2173-
napi_value* result) {
2174-
NAPI_PREAMBLE(env);
2175-
CHECK_ARG(env, value);
2176-
CHECK_ARG(env, result);
2177-
2178-
v8::Local<v8::Context> context = env->context();
2179-
v8::Local<v8::Number> num;
2180-
2181-
CHECK_TO_NUMBER(env, context, num, value);
2182-
2183-
*result = v8impl::JsValueFromV8LocalValue(num);
2184-
return GET_RETURN_STATUS(env);
2185-
}
2186-
2187-
napi_status napi_coerce_to_string(napi_env env,
2188-
napi_value value,
2189-
napi_value* result) {
2190-
NAPI_PREAMBLE(env);
2191-
CHECK_ARG(env, value);
2192-
CHECK_ARG(env, result);
2193-
2194-
v8::Local<v8::Context> context = env->context();
2195-
v8::Local<v8::String> str;
2196-
2197-
CHECK_TO_STRING(env, context, str, value);
2198-
2199-
*result = v8impl::JsValueFromV8LocalValue(str);
2200-
return GET_RETURN_STATUS(env);
2201-
}
2156+
#define GEN_COERCE_FUNCTION(UpperCaseName, MixedCaseName, LowerCaseName) \
2157+
napi_status napi_coerce_to_##LowerCaseName(napi_env env, \
2158+
napi_value value, \
2159+
napi_value* result) { \
2160+
NAPI_PREAMBLE(env); \
2161+
CHECK_ARG(env, value); \
2162+
CHECK_ARG(env, result); \
2163+
\
2164+
v8::Local<v8::Context> context = env->context(); \
2165+
v8::Local<v8::MixedCaseName> str; \
2166+
\
2167+
CHECK_TO_##UpperCaseName(env, context, str, value); \
2168+
\
2169+
*result = v8impl::JsValueFromV8LocalValue(str); \
2170+
return GET_RETURN_STATUS(env); \
2171+
}
2172+
2173+
GEN_COERCE_FUNCTION(NUMBER, Number, number)
2174+
GEN_COERCE_FUNCTION(OBJECT, Object, object)
2175+
GEN_COERCE_FUNCTION(STRING, String, string)
2176+
2177+
#undef GEN_COERCE_FUNCTION
22022178

22032179
napi_status napi_wrap(napi_env env,
22042180
napi_value js_object,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.