es.object.freeze.js 673 B

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