src: reuse cached strings in CompileSerializeMain

CompileSerializeMain() created new "require", "__filename", and
"__dirname" strings via FIXED_ONE_BYTE_STRING() on every call, even
though these strings are already cached on IsolateData/Environment
as require_string(), __filename_string(), and __dirname_string()
(defined via PER_ISOLATE_STRING_PROPERTIES in src/env_properties.h)
and are reused this way elsewhere (e.g. the sibling
RunEmbedderPreload() already obtains Environment* the same way).

Signed-off-by: agape1225 <49804691+agape1225@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/65453
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
agape1225 authored and Antoine du Hamel committed 2026-09-15 10:49:19 +02:00
1 parent b5f0558c84
commit e260fd146c
1 file changed
+7 -7
+7 -7
View File
@@ -1571,17 +1571,17 @@ void CompileSerializeMain(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsString());
Local<String> filename = args[0].As<String>();
Local<String> source = args[1].As<String>();
Environment* env = Environment::GetCurrent(args);
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
// TODO(joyeecheung): do we need all of these? Maybe we would want a less
// internal version of them.
LocalVector<String> parameters(
isolate,
{
FIXED_ONE_BYTE_STRING(isolate, "require"),
FIXED_ONE_BYTE_STRING(isolate, "__filename"),
FIXED_ONE_BYTE_STRING(isolate, "__dirname"),
});
LocalVector<String> parameters(isolate,
{
env->require_string(),
env->__filename_string(),
env->__dirname_string(),
});
ScriptOrigin script_origin(filename, 0, 0, true);
ScriptCompiler::Source script_source(source, script_origin);