Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Last active December 14, 2016 14:36
Show Gist options
  • Save gabrielschulhof/0a1e2387a72bf7a38c8f41cadfd2941f to your computer and use it in GitHub Desktop.
Save gabrielschulhof/0a1e2387a72bf7a38c8f41cadfd2941f to your computer and use it in GitHub Desktop.
const char *napi_type_name_from_value(napi_valuetype theType) {
return theType == napi_undefined ? "napi_undefined" :
theType == napi_null ? "napi_null" :
theType == napi_boolean ? "napi_boolean" :
theType == napi_number ? "napi_number" :
theType == napi_string ? "napi_string" :
theType == napi_symbol ? "napi_symbol" :
theType == napi_object ? "napi_object" :
theType == napi_function ? "napi_function" : "unknown";
}
void getProtoChainTypes(napi_env env, napi_func_cb_info info) {
napi_value arguments[1];
napi_value returnValue = napi_create_array(env);
napi_valuetype theType;
uint32_t index;
napi_propertyname underunderProto = napi_property_name(env, "__proto__");
napi_get_cb_args(env, info, arguments, 1);
for (index = 0, theType = napi_get_type_of_value(env, arguments[0]);
!(theType == napi_null || theType == napi_undefined);
index++,
arguments[0] = napi_get_property(env, arguments[0], underunderProto),
theType = napi_get_type_of_value(env, arguments[0])) {
napi_set_element(env, returnValue, index, napi_create_string(env,
napi_type_name_from_value(theType)));
}
napi_set_element(env, returnValue, index, napi_create_string(env,
napi_type_name_from_value(theType)));
napi_set_return_value(env, info, returnValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment