Skip to content

Commit b586e89

Browse files
LiviaMedeirosaduh95
authored andcommitted
chore: add kEmptyObject to internal/util
PR-URL: nodejs/node#43159 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 5d40d04 commit b586e89

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/internal/per_context/primordials.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ exports.ObjectCreate = obj => Object.create(obj)
2121
exports.ObjectDefineProperties = (obj, props) => Object.defineProperties(obj, props)
2222
exports.ObjectDefineProperty = (obj, key, descr) => Object.defineProperty(obj, key, descr)
2323
exports.ObjectEntries = obj => Object.entries(obj)
24+
exports.ObjectFreeze = obj => Object.freeze(obj)
2425
exports.ObjectGetOwnPropertyDescriptor = (obj, key) => Object.getOwnPropertyDescriptor(obj, key)
2526
exports.ObjectIsExtensible = obj => Object.isExtensible(obj)
2627
exports.ObjectPrototypeHasOwnProperty = (obj, property) => Object.prototype.hasOwnProperty.call(obj, property)

lib/internal/util.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
// https://github.com/nodejs/node/blob/1aab13cad9c800f4121c1d35b554b78c1b17bdbd/lib/internal/util.js
1+
// https://github.com/nodejs/node/blob/a9b1fd3987fae5ad5340859a6088b86179b576c5/lib/internal/util.js
22
'use strict'
33

4+
const {
5+
ObjectCreate,
6+
ObjectFreeze
7+
} = require('#internal/per_context/primordials')
48
const {
59
types: { isNativeError }
610
} = require('util')
@@ -23,7 +27,10 @@ function isError (e) {
2327
return isNativeError(e) || e instanceof Error
2428
}
2529

30+
const kEmptyObject = ObjectFreeze(ObjectCreate(null))
31+
2632
module.exports = {
2733
createDeferredPromise,
28-
isError
34+
isError,
35+
kEmptyObject
2936
}

0 commit comments

Comments
 (0)