From 4038cf0513e7c7f206616bff7da878dfe32c0478 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 8 Oct 2023 19:50:53 +0100 Subject: [PATCH] vm: freeze `dependencySpecifiers` array PR-URL: https://github.com/nodejs/node/pull/49720 Reviewed-By: Moshe Atlow Reviewed-By: Marco Ippolito Reviewed-By: Chengzhong Wu --- lib/internal/vm/module.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/internal/vm/module.js b/lib/internal/vm/module.js index c77ee9b107e0ad..d9a073fd4d7906 100644 --- a/lib/internal/vm/module.js +++ b/lib/internal/vm/module.js @@ -7,6 +7,7 @@ const { ArrayPrototypeIndexOf, ArrayPrototypeSome, ObjectDefineProperty, + ObjectFreeze, ObjectGetPrototypeOf, ObjectSetPrototypeOf, ReflectApply, @@ -340,9 +341,7 @@ class SourceTextModule extends Module { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } - if (this[kDependencySpecifiers] === undefined) { - this[kDependencySpecifiers] = this[kWrap].getStaticDependencySpecifiers(); - } + this[kDependencySpecifiers] ??= ObjectFreeze(this[kWrap].getStaticDependencySpecifiers()); return this[kDependencySpecifiers]; }