diff --git a/src/env-inl.h b/src/env-inl.h index d0dd2047bd..d008586e5c 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -207,12 +207,6 @@ inline Environment::Environment(IsolateData* isolate_data, set_binding_cache_object(v8::Object::New(isolate())); set_module_load_list_array(v8::Array::New(isolate())); - v8::Local fn = v8::FunctionTemplate::New(isolate()); - fn->SetClassName(FIXED_ONE_BYTE_STRING(isolate(), "InternalFieldObject")); - v8::Local obj = fn->InstanceTemplate(); - obj->SetInternalFieldCount(1); - set_generic_internal_field_template(obj); - RB_INIT(&cares_task_list_); AssignToContext(context); @@ -473,12 +467,6 @@ inline void Environment::SetTemplateMethod(v8::Local that, t->SetClassName(name_string); // NODE_SET_METHOD() compatibility. } -inline v8::Local Environment::NewInternalFieldObject() { - v8::MaybeLocal m_obj = - generic_internal_field_template()->NewInstance(context()); - return m_obj.ToLocalChecked(); -} - #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) #define VS(PropertyName, StringValue) V(v8::String, PropertyName) #define V(TypeName, PropertyName) \ diff --git a/src/env.h b/src/env.h index 85327a74f5..8a07f38dfb 100644 --- a/src/env.h +++ b/src/env.h @@ -262,13 +262,14 @@ namespace node { V(context, v8::Context) \ V(domain_array, v8::Array) \ V(domains_stack_array, v8::Array) \ - V(generic_internal_field_template, v8::ObjectTemplate) \ V(jsstream_constructor_template, v8::FunctionTemplate) \ V(module_load_list_array, v8::Array) \ + V(pbkdf2_constructor_template, v8::ObjectTemplate) \ V(pipe_constructor_template, v8::FunctionTemplate) \ V(process_object, v8::Object) \ V(promise_reject_function, v8::Function) \ V(push_values_to_array_function, v8::Function) \ + V(randombytes_constructor_template, v8::ObjectTemplate) \ V(script_context_constructor_template, v8::FunctionTemplate) \ V(script_data_constructor_function, v8::Function) \ V(secure_context_constructor_template, v8::FunctionTemplate) \ @@ -534,8 +535,6 @@ class Environment { const char* name, v8::FunctionCallback callback); - inline v8::Local NewInternalFieldObject(); - void AtExit(void (*cb)(void* arg), void* arg); void RunAtExitCallbacks(); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 0408ff0b05..da1c337fe6 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -107,6 +107,7 @@ using v8::Maybe; using v8::MaybeLocal; using v8::Null; using v8::Object; +using v8::ObjectTemplate; using v8::Persistent; using v8::PropertyAttribute; using v8::PropertyCallbackInfo; @@ -5532,7 +5533,8 @@ void PBKDF2(const FunctionCallbackInfo& args) { digest = EVP_sha1(); } - obj = env->NewInternalFieldObject(); + obj = env->pbkdf2_constructor_template()-> + NewInstance(env->context()).ToLocalChecked(); req = new PBKDF2Request(env, obj, digest, @@ -5736,7 +5738,8 @@ void RandomBytes(const FunctionCallbackInfo& args) { if (size < 0 || size > Buffer::kMaxLength) return env->ThrowRangeError("size is not a valid Smi"); - Local obj = env->NewInternalFieldObject(); + Local obj = env->randombytes_constructor_template()-> + NewInstance(env->context()).ToLocalChecked(); char* data = node::Malloc(size); RandomBytesRequest* req = new RandomBytesRequest(env, @@ -5774,7 +5777,8 @@ void RandomBytesBuffer(const FunctionCallbackInfo& args) { int64_t offset = args[1]->IntegerValue(); int64_t size = args[2]->IntegerValue(); - Local obj = env->NewInternalFieldObject(); + Local obj = env->randombytes_constructor_template()-> + NewInstance(env->context()).ToLocalChecked(); obj->Set(env->context(), env->buffer_string(), args[0]).FromJust(); char* data = Buffer::Data(args[0]); data += offset; @@ -6251,6 +6255,18 @@ void InitCrypto(Local target, PublicKeyCipher::Cipher); + + Local pb = FunctionTemplate::New(env->isolate()); + pb->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "PBKDF2")); + Local pbt = pb->InstanceTemplate(); + pbt->SetInternalFieldCount(1); + env->set_pbkdf2_constructor_template(pbt); + + Local rb = FunctionTemplate::New(env->isolate()); + rb->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "RandomBytes")); + Local rbt = rb->InstanceTemplate(); + rbt->SetInternalFieldCount(1); + env->set_randombytes_constructor_template(rbt); } } // namespace crypto