From 212c9c086c526a0fdf8ac0bb0db36626f0534a0a Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 25 Sep 2015 12:19:53 +0200 Subject: [PATCH] src: internalize binding function property names Internalized strings are created in the old space and that is where they eventually would end up anyway when created as normal strings. PR-URL: https://github.com/nodejs/node/pull/3060 Reviewed-By: James M Snell Reviewed-By: Trevor Norris --- src/env-inl.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 34d0531a1e4b61..a3f4a797adaeae 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -478,7 +478,10 @@ inline void Environment::SetMethod(v8::Local that, v8::FunctionCallback callback) { v8::Local function = NewFunctionTemplate(callback)->GetFunction(); - v8::Local name_string = v8::String::NewFromUtf8(isolate(), name); + // kInternalized strings are created in the old space. + const v8::NewStringType type = v8::NewStringType::kInternalized; + v8::Local name_string = + v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); that->Set(name_string, function); function->SetName(name_string); // NODE_SET_METHOD() compatibility. } @@ -489,7 +492,10 @@ inline void Environment::SetProtoMethod(v8::Local that, v8::Local signature = v8::Signature::New(isolate(), that); v8::Local function = NewFunctionTemplate(callback, signature)->GetFunction(); - v8::Local name_string = v8::String::NewFromUtf8(isolate(), name); + // kInternalized strings are created in the old space. + const v8::NewStringType type = v8::NewStringType::kInternalized; + v8::Local name_string = + v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); that->PrototypeTemplate()->Set(name_string, function); function->SetName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility. } @@ -499,7 +505,10 @@ inline void Environment::SetTemplateMethod(v8::Local that, v8::FunctionCallback callback) { v8::Local function = NewFunctionTemplate(callback)->GetFunction(); - v8::Local name_string = v8::String::NewFromUtf8(isolate(), name); + // kInternalized strings are created in the old space. + const v8::NewStringType type = v8::NewStringType::kInternalized; + v8::Local name_string = + v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); that->Set(name_string, function); function->SetName(name_string); // NODE_SET_METHOD() compatibility. }