|
| 1 | +// Flags: --expose-internals |
| 2 | +'use strict'; |
| 3 | +require('../common'); |
| 4 | + |
| 5 | +// Test helper objects from internal/util |
| 6 | + |
| 7 | +const assert = require('assert'); |
| 8 | +const { |
| 9 | + kEnumerableProperty, |
| 10 | + kEmptyObject, |
| 11 | +} = require('internal/util'); |
| 12 | + |
| 13 | +Object.prototype.blep = 'blop'; |
| 14 | + |
| 15 | +{ |
| 16 | + assert.strictEqual( |
| 17 | + kEnumerableProperty.blep, |
| 18 | + undefined |
| 19 | + ); |
| 20 | + assert.strictEqual( |
| 21 | + kEnumerableProperty.enumerable, |
| 22 | + true |
| 23 | + ); |
| 24 | + assert.strictEqual( |
| 25 | + Object.getPrototypeOf(kEnumerableProperty), |
| 26 | + null |
| 27 | + ); |
| 28 | + assert.deepStrictEqual( |
| 29 | + Object.getOwnPropertyNames(kEnumerableProperty), |
| 30 | + [ 'enumerable' ] |
| 31 | + ); |
| 32 | +} |
| 33 | + |
| 34 | +{ |
| 35 | + assert.strictEqual( |
| 36 | + kEmptyObject.blep, |
| 37 | + undefined |
| 38 | + ); |
| 39 | + assert.strictEqual( |
| 40 | + kEmptyObject.prototype, |
| 41 | + undefined |
| 42 | + ); |
| 43 | + assert.strictEqual( |
| 44 | + Object.getPrototypeOf(kEmptyObject), |
| 45 | + null |
| 46 | + ); |
| 47 | + assert.strictEqual( |
| 48 | + kEmptyObject instanceof Object, |
| 49 | + false |
| 50 | + ); |
| 51 | + assert.deepStrictEqual( |
| 52 | + Object.getOwnPropertyDescriptors(kEmptyObject), |
| 53 | + {} |
| 54 | + ); |
| 55 | + assert.deepStrictEqual( |
| 56 | + Object.getOwnPropertyNames(kEmptyObject), |
| 57 | + [] |
| 58 | + ); |
| 59 | + assert.deepStrictEqual( |
| 60 | + Object.getOwnPropertySymbols(kEmptyObject), |
| 61 | + [] |
| 62 | + ); |
| 63 | + assert.strictEqual( |
| 64 | + Object.isExtensible(kEmptyObject), |
| 65 | + false |
| 66 | + ); |
| 67 | + assert.strictEqual( |
| 68 | + Object.isSealed(kEmptyObject), |
| 69 | + true |
| 70 | + ); |
| 71 | + assert.strictEqual( |
| 72 | + Object.isFrozen(kEmptyObject), |
| 73 | + true |
| 74 | + ); |
| 75 | + |
| 76 | + assert.throws( |
| 77 | + () => kEmptyObject.foo = 'bar', |
| 78 | + TypeError |
| 79 | + ); |
| 80 | + assert.throws( |
| 81 | + () => Object.assign(kEmptyObject, { foo: 'bar' }), |
| 82 | + TypeError |
| 83 | + ); |
| 84 | + assert.throws( |
| 85 | + () => Object.defineProperty(kEmptyObject, 'foo', {}), |
| 86 | + TypeError |
| 87 | + ); |
| 88 | +} |
| 89 | + |
| 90 | +delete Object.prototype.blep; |
0 commit comments