define-built-in.js 965 B

123456789101112131415161718192021222324252627
  1. var isCallable = require('../internals/is-callable');
  2. var definePropertyModule = require('../internals/object-define-property');
  3. var makeBuiltIn = require('../internals/make-built-in');
  4. var defineGlobalProperty = require('../internals/define-global-property');
  5. module.exports = function (O, key, value, options) {
  6. if (!options) options = {};
  7. var simple = options.enumerable;
  8. var name = options.name !== undefined ? options.name : key;
  9. if (isCallable(value)) makeBuiltIn(value, name, options);
  10. if (options.global) {
  11. if (simple) O[key] = value;
  12. else defineGlobalProperty(key, value);
  13. } else {
  14. try {
  15. if (!options.unsafe) delete O[key];
  16. else if (O[key]) simple = true;
  17. } catch (error) { /* empty */ }
  18. if (simple) O[key] = value;
  19. else definePropertyModule.f(O, key, {
  20. value: value,
  21. enumerable: false,
  22. configurable: !options.nonConfigurable,
  23. writable: !options.nonWritable
  24. });
  25. } return O;
  26. };