-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: add
kEmptyObject
to internal/util
PR-URL: #43159 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
- Loading branch information
1 parent
8c0fe1e
commit b187d55
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |