From 56b8cc5cef78b1b8b8ad6424492a3e3237682205 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Thu, 26 May 2022 08:00:35 +0800 Subject: [PATCH] util: freeze `kEnumerableProperty` PR-URL: https://github.com/nodejs/node/pull/43390 Reviewed-By: Antoine du Hamel Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Beth Griggs Reviewed-By: Luigi Pinca --- lib/internal/util.js | 1 + test/parallel/test-internal-util-objects.js | 29 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/internal/util.js b/lib/internal/util.js index 030af62be8761e..36736da36d5313 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -504,6 +504,7 @@ const lazyDOMException = hideStackFrames((message, name) => { const kEnumerableProperty = ObjectCreate(null); kEnumerableProperty.enumerable = true; +ObjectFreeze(kEnumerableProperty); const kEmptyObject = ObjectFreeze(ObjectCreate(null)); diff --git a/test/parallel/test-internal-util-objects.js b/test/parallel/test-internal-util-objects.js index 092deb9e09464b..74068e4c577bd6 100644 --- a/test/parallel/test-internal-util-objects.js +++ b/test/parallel/test-internal-util-objects.js @@ -29,6 +29,35 @@ Object.prototype.blep = 'blop'; Object.getOwnPropertyNames(kEnumerableProperty), [ 'enumerable' ] ); + + assert.throws( + () => Object.setPrototypeOf(kEnumerableProperty, { value: undefined }), + TypeError + ); + assert.throws( + () => delete kEnumerableProperty.enumerable, + TypeError + ); + assert.throws( + () => kEnumerableProperty.enumerable = false, + TypeError + ); + assert.throws( + () => Object.assign(kEnumerableProperty, { enumerable: false }), + TypeError + ); + assert.throws( + () => kEnumerableProperty.value = undefined, + TypeError + ); + assert.throws( + () => Object.assign(kEnumerableProperty, { value: undefined }), + TypeError + ); + assert.throws( + () => Object.defineProperty(kEnumerableProperty, 'value', {}), + TypeError + ); } {