Created
January 6, 2017 19:11
-
-
Save gabrielschulhof/3a8d174b860db0c18a732c0b25c12cbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void doInstanceOf(napi_env env, napi_func_cb_info info) { | |
napi_value arguments[2]; | |
napi_valuetype originalType, currentType, constructorPrototypeType; | |
bool returnValue = false; | |
napi_propertyname underunderProto; | |
napi_get_cb_args(env, info, arguments, 2); | |
if (napi_get_type_of_value(env, arguments[1]) != napi_function) { | |
napi_throw_type_error(env, (char *)"constructor must be a function"); | |
return; | |
} | |
arguments[1] = napi_get_property(env, arguments[1], | |
napi_property_name(env, "prototype")); | |
constructorPrototypeType = napi_get_type_of_value(env, arguments[1]); | |
if (constructorPrototypeType != napi_object) { | |
napi_throw_type_error(env, | |
(char *)"constructor prototype must be an object"); | |
return; | |
} | |
if (!napi_strict_equals(env, arguments[0], arguments[1])) { | |
underunderProto = napi_property_name(env, "__proto__"); | |
for (originalType = currentType = napi_get_type_of_value(env, arguments[0]); | |
!(currentType == napi_null || currentType == napi_undefined); | |
arguments[0] = | |
napi_get_property(env, arguments[0], underunderProto), | |
currentType = napi_get_type_of_value(env, arguments[0])) { | |
if (napi_strict_equals(env, arguments[0], arguments[1])) { | |
returnValue = | |
!(originalType == napi_number || | |
originalType == napi_boolean || | |
originalType == napi_string); | |
break; | |
} | |
} | |
} | |
napi_set_return_value(env, info, napi_create_boolean(env, returnValue)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment