es.object.freeze.js 630 B

12345678910111213141516
  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. var nativeFreeze = Object.freeze;
  7. var FAILS_ON_PRIMITIVES = fails(function () { nativeFreeze(1); });
  8. // `Object.freeze` method
  9. // https://tc39.github.io/ecma262/#sec-object.freeze
  10. $({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES, sham: !FREEZING }, {
  11. freeze: function freeze(it) {
  12. return nativeFreeze && isObject(it) ? nativeFreeze(onFreeze(it)) : it;
  13. }
  14. });