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