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 committed Jun 15, 2022
1 parent 9eb1b5c commit 0f90879
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 @@ -504,6 +504,7 @@ const lazyDOMException = hideStackFrames((message, name) => {

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 0f90879

Please sign in to comment.