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 <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Beth Griggs <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
LiviaMedeiros authored and targos committed Jul 12, 2022
1 parent fdf19f8 commit 8f9a31e
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 8f9a31e

Please sign in to comment.