mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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>
This commit is contained in:
1 parent
8c0fe1e184
commit
b187d55b6d
2 files changed
+94
No files matched your search
@@ -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,
|
||||
};
|
||||
@@ -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;
|
||||
Reference in new issue
Block a user