MES手机端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

56 lines
2.7 KiB

  1. 'use strict';
  2. var globalThis = require('../internals/global-this');
  3. var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
  4. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  5. var defineBuiltIn = require('../internals/define-built-in');
  6. var defineGlobalProperty = require('../internals/define-global-property');
  7. var copyConstructorProperties = require('../internals/copy-constructor-properties');
  8. var isForced = require('../internals/is-forced');
  9. /*
  10. options.target - name of the target object
  11. options.global - target is the global object
  12. options.stat - export as static methods of target
  13. options.proto - export as prototype methods of target
  14. options.real - real prototype method for the `pure` version
  15. options.forced - export even if the native feature is available
  16. options.bind - bind methods to the target, required for the `pure` version
  17. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  18. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  19. options.sham - add a flag to not completely full polyfills
  20. options.enumerable - export as enumerable property
  21. options.dontCallGetSet - prevent calling a getter on target
  22. options.name - the .name of the function if it does not match the key
  23. */
  24. module.exports = function (options, source) {
  25. var TARGET = options.target;
  26. var GLOBAL = options.global;
  27. var STATIC = options.stat;
  28. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  29. if (GLOBAL) {
  30. target = globalThis;
  31. } else if (STATIC) {
  32. target = globalThis[TARGET] || defineGlobalProperty(TARGET, {});
  33. } else {
  34. target = globalThis[TARGET] && globalThis[TARGET].prototype;
  35. }
  36. if (target) for (key in source) {
  37. sourceProperty = source[key];
  38. if (options.dontCallGetSet) {
  39. descriptor = getOwnPropertyDescriptor(target, key);
  40. targetProperty = descriptor && descriptor.value;
  41. } else targetProperty = target[key];
  42. FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  43. // contained in target
  44. if (!FORCED && targetProperty !== undefined) {
  45. if (typeof sourceProperty == typeof targetProperty) continue;
  46. copyConstructorProperties(sourceProperty, targetProperty);
  47. }
  48. // add a flag to not completely full polyfills
  49. if (options.sham || (targetProperty && targetProperty.sham)) {
  50. createNonEnumerableProperty(sourceProperty, 'sham', true);
  51. }
  52. defineBuiltIn(target, key, sourceProperty, options);
  53. }
  54. };