Skip to content

Commit 92fdb24

Browse files
jasnelldanielleadams
authored andcommitted
src: add KeyObjectHandle::HasInstance
In preparation for use by the QUIC implementation. PR-URL: #45912 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent a639e2a commit 92fdb24

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

src/crypto/crypto_keys.cc

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -889,33 +889,36 @@ size_t KeyObjectData::GetSymmetricKeySize() const {
889889
return symmetric_key_.size();
890890
}
891891

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+
892897
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);
896920
}
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();
919922
}
920923

921924
void KeyObjectHandle::RegisterExternalReferences(

src/crypto/crypto_keys.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class KeyObjectData : public MemoryRetainer {
163163

164164
class KeyObjectHandle : public BaseObject {
165165
public:
166+
static bool HasInstance(Environment* env, v8::Local<v8::Value> value);
166167
static v8::Local<v8::Function> Initialize(Environment* env);
167168
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
168169

src/env_properties.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
V(contextify_global_template, v8::ObjectTemplate) \
335335
V(contextify_wrapper_template, v8::ObjectTemplate) \
336336
V(compiled_fn_entry_template, v8::ObjectTemplate) \
337+
V(crypto_key_object_handle_constructor, v8::FunctionTemplate) \
337338
V(env_proxy_template, v8::ObjectTemplate) \
338339
V(env_proxy_ctor_template, v8::FunctionTemplate) \
339340
V(dir_instance_template, v8::ObjectTemplate) \
@@ -376,7 +377,6 @@
376377
V(async_hooks_promise_resolve_function, v8::Function) \
377378
V(buffer_prototype_object, v8::Object) \
378379
V(crypto_key_object_constructor, v8::Function) \
379-
V(crypto_key_object_handle_constructor, v8::Function) \
380380
V(crypto_key_object_private_constructor, v8::Function) \
381381
V(crypto_key_object_public_constructor, v8::Function) \
382382
V(crypto_key_object_secret_constructor, v8::Function) \

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy