@@ -889,33 +889,36 @@ size_t KeyObjectData::GetSymmetricKeySize() const { |
889 | 889 | return symmetric_key_.size(); |
890 | 890 | } |
891 | 891 |
|
| 892 | +bool KeyObjectHandle::HasInstance(Environment* env, Local<Value> value) { |
| 893 | + Local<FunctionTemplate> t = env->crypto_key_object_handle_constructor(); |
| 894 | + return !t.IsEmpty() && t->HasInstance(value); |
| 895 | +} |
| 896 | + |
892 | 897 | v8::Local<v8::Function> KeyObjectHandle::Initialize(Environment* env) { |
893 | | - Local<Function> templ = env->crypto_key_object_handle_constructor(); |
894 | | - if (!templ.IsEmpty()) { |
895 | | - return templ; |
| 898 | + Local<FunctionTemplate> templ = env->crypto_key_object_handle_constructor(); |
| 899 | + if (templ.IsEmpty()) { |
| 900 | + Isolate* isolate = env->isolate(); |
| 901 | + templ = NewFunctionTemplate(isolate, New); |
| 902 | + templ->InstanceTemplate()->SetInternalFieldCount( |
| 903 | + KeyObjectHandle::kInternalFieldCount); |
| 904 | + templ->Inherit(BaseObject::GetConstructorTemplate(env)); |
| 905 | + |
| 906 | + SetProtoMethod(isolate, templ, "init", Init); |
| 907 | + SetProtoMethodNoSideEffect( |
| 908 | + isolate, templ, "getSymmetricKeySize", GetSymmetricKeySize); |
| 909 | + SetProtoMethodNoSideEffect( |
| 910 | + isolate, templ, "getAsymmetricKeyType", GetAsymmetricKeyType); |
| 911 | + SetProtoMethod(isolate, templ, "export", Export); |
| 912 | + SetProtoMethod(isolate, templ, "exportJwk", ExportJWK); |
| 913 | + SetProtoMethod(isolate, templ, "initECRaw", InitECRaw); |
| 914 | + SetProtoMethod(isolate, templ, "initEDRaw", InitEDRaw); |
| 915 | + SetProtoMethod(isolate, templ, "initJwk", InitJWK); |
| 916 | + SetProtoMethod(isolate, templ, "keyDetail", GetKeyDetail); |
| 917 | + SetProtoMethod(isolate, templ, "equals", Equals); |
| 918 | + |
| 919 | + env->set_crypto_key_object_handle_constructor(templ); |
896 | 920 | } |
897 | | - Isolate* isolate = env->isolate(); |
898 | | - Local<FunctionTemplate> t = NewFunctionTemplate(isolate, New); |
899 | | - t->InstanceTemplate()->SetInternalFieldCount( |
900 | | - KeyObjectHandle::kInternalFieldCount); |
901 | | - t->Inherit(BaseObject::GetConstructorTemplate(env)); |
902 | | - |
903 | | - SetProtoMethod(isolate, t, "init", Init); |
904 | | - SetProtoMethodNoSideEffect( |
905 | | - isolate, t, "getSymmetricKeySize", GetSymmetricKeySize); |
906 | | - SetProtoMethodNoSideEffect( |
907 | | - isolate, t, "getAsymmetricKeyType", GetAsymmetricKeyType); |
908 | | - SetProtoMethod(isolate, t, "export", Export); |
909 | | - SetProtoMethod(isolate, t, "exportJwk", ExportJWK); |
910 | | - SetProtoMethod(isolate, t, "initECRaw", InitECRaw); |
911 | | - SetProtoMethod(isolate, t, "initEDRaw", InitEDRaw); |
912 | | - SetProtoMethod(isolate, t, "initJwk", InitJWK); |
913 | | - SetProtoMethod(isolate, t, "keyDetail", GetKeyDetail); |
914 | | - SetProtoMethod(isolate, t, "equals", Equals); |
915 | | - |
916 | | - auto function = t->GetFunction(env->context()).ToLocalChecked(); |
917 | | - env->set_crypto_key_object_handle_constructor(function); |
918 | | - return function; |
| 921 | + return templ->GetFunction(env->context()).ToLocalChecked(); |
919 | 922 | } |
920 | 923 |
|
921 | 924 | void KeyObjectHandle::RegisterExternalReferences( |
|