Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Created January 6, 2017 19:07
Show Gist options
  • Save gabrielschulhof/ffd0a7e323ddb6c17bee9d1e16bc627f to your computer and use it in GitHub Desktop.
Save gabrielschulhof/ffd0a7e323ddb6c17bee9d1e16bc627f to your computer and use it in GitHub Desktop.
bool napi_instanceof(napi_env e, napi_value o, napi_value c) {
v8::Isolate *isolate = v8impl::V8IsolateFromJsEnv(e);
v8::Local<v8::Value> obj = v8impl::V8LocalValueFromJsValue(o);
v8::Local<v8::Value> consProto = v8impl::V8LocalValueFromJsValue(c)
->ToObject()->Get(v8::String::NewFromUtf8(isolate, "prototype"));
v8::Local<v8::String> protoString =
v8::String::NewFromUtf8(isolate, "__proto__");
while (!obj->IsNull()) {
if (obj->StrictEquals(consProto)) {
return true;
}
obj = obj->ToObject()->Get(protoString);
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment