node/test/parallel/test-internal-util-objects.js
LiviaMedeiros 0f9087971c
util: freeze kEnumerableProperty
PR-URL: https://github.com/nodejs/node/pull/43390
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2022-06-15 16:41:51 +08:00

120 lines
2.3 KiB
JavaScript

// 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.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
);
}
{
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;