es.object.freeze.js 659 B

1234567891011121314151617
  1. var $ = require('../internals/export');
  2. var FREEZING = require('../internals/freezing');
  3. var fails = require('../internals/fails');
  4. var isObject = require('../internals/is-object');
  5. var onFreeze = require('../internals/internal-metadata').onFreeze;
  6. // eslint-disable-next-line es/no-object-freeze -- safe
  7. var $freeze = Object.freeze;
  8. var FAILS_ON_PRIMITIVES = fails(function () { $freeze(1); });
  9. // `Object.freeze` method
  10. // https://tc39.es/ecma262/#sec-object.freeze
  11. $({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES, sham: !FREEZING }, {
  12. freeze: function freeze(it) {
  13. return $freeze && isObject(it) ? $freeze(onFreeze(it)) : it;
  14. }
  15. });