Skip to content

Commit

Permalink
util: freeze kEnumerableProperty
Browse files Browse the repository at this point in the history
PR-URL: #43390
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
LiviaMedeiros authored and targos committed Jul 31, 2022
1 parent 705a8af commit 053347c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ function structuredClone(value) {

const kEnumerableProperty = ObjectCreate(null);
kEnumerableProperty.enumerable = true;
ObjectFreeze(kEnumerableProperty);

const kEmptyObject = ObjectFreeze(ObjectCreate(null));

Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-internal-util-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

{
Expand Down

0 comments on commit 053347c

Please sign in to comment.