Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiviaMedeiros <livia@cirno.name>2022-05-21 12:48:37 +0300
committerAntoine du Hamel <duhamelantoine1995@gmail.com>2022-06-11 13:18:02 +0300
commita9b1fd3987fae5ad5340859a6088b86179b576c5 (patch)
tree32c2b11ce6acb0969d74ef9da2d7c557cb5cabe3
parente227e5285d00654293454fd148e9916b5880cbcd (diff)
util: add `kEmptyObject` to internal/util
PR-URL: https://github.com/nodejs/node/pull/43159 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
-rw-r--r--lib/internal/util.js4
-rw-r--r--test/parallel/test-internal-util-objects.js90
2 files changed, 94 insertions, 0 deletions
diff --git a/lib/internal/util.js b/lib/internal/util.js
index 61e58a5d69d..030af62be87 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -13,6 +13,7 @@ const {
ObjectGetOwnPropertyDescriptor,
ObjectGetOwnPropertyDescriptors,
ObjectGetPrototypeOf,
+ ObjectFreeze,
ObjectSetPrototypeOf,
Promise,
ReflectApply,
@@ -504,6 +505,8 @@ const lazyDOMException = hideStackFrames((message, name) => {
const kEnumerableProperty = ObjectCreate(null);
kEnumerableProperty.enumerable = true;
+const kEmptyObject = ObjectFreeze(ObjectCreate(null));
+
module.exports = {
assertCrypto,
cachedResult,
@@ -544,5 +547,6 @@ module.exports = {
kIsEncodingSymbol: Symbol('kIsEncodingSymbol'),
kVmBreakFirstLineSymbol: Symbol('kVmBreakFirstLineSymbol'),
+ kEmptyObject,
kEnumerableProperty,
};
diff --git a/test/parallel/test-internal-util-objects.js b/test/parallel/test-internal-util-objects.js
new file mode 100644
index 00000000000..092deb9e094
--- /dev/null
+++ b/test/parallel/test-internal-util-objects.js
@@ -0,0 +1,90 @@
+// Flags: --expose-internals
+'use strict';
+require('../common');
+
+// Test helper objects from internal/util
+
+const assert = require('assert');
+const {
+ kEnumerableProperty,
+ kEmptyObject,
+} = require('internal/util');
+
+Object.prototype.blep = 'blop';
+
+{
+ assert.strictEqual(
+ kEnumerableProperty.blep,
+ undefined
+ );
+ assert.strictEqual(
+ kEnumerableProperty.enumerable,
+ true
+ );
+ assert.strictEqual(
+ Object.getPrototypeOf(kEnumerableProperty),
+ null
+ );
+ assert.deepStrictEqual(
+ Object.getOwnPropertyNames(kEnumerableProperty),
+ [ 'enumerable' ]
+ );
+}
+
+{
+ assert.strictEqual(
+ kEmptyObject.blep,
+ undefined
+ );
+ assert.strictEqual(
+ kEmptyObject.prototype,
+ undefined
+ );
+ assert.strictEqual(
+ Object.getPrototypeOf(kEmptyObject),
+ null
+ );
+ assert.strictEqual(
+ kEmptyObject instanceof Object,
+ false
+ );
+ assert.deepStrictEqual(
+ Object.getOwnPropertyDescriptors(kEmptyObject),
+ {}
+ );
+ assert.deepStrictEqual(
+ Object.getOwnPropertyNames(kEmptyObject),
+ []
+ );
+ assert.deepStrictEqual(
+ Object.getOwnPropertySymbols(kEmptyObject),
+ []
+ );
+ assert.strictEqual(
+ Object.isExtensible(kEmptyObject),
+ false
+ );
+ assert.strictEqual(
+ Object.isSealed(kEmptyObject),
+ true
+ );
+ assert.strictEqual(
+ Object.isFrozen(kEmptyObject),
+ true
+ );
+
+ assert.throws(
+ () => kEmptyObject.foo = 'bar',
+ TypeError
+ );
+ assert.throws(
+ () => Object.assign(kEmptyObject, { foo: 'bar' }),
+ TypeError
+ );
+ assert.throws(
+ () => Object.defineProperty(kEmptyObject, 'foo', {}),
+ TypeError
+ );
+}
+
+delete Object.prototype.blep;