_export.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var global = require('./_global');
  2. var core = require('./_core');
  3. var hide = require('./_hide');
  4. var redefine = require('./_redefine');
  5. var ctx = require('./_ctx');
  6. var PROTOTYPE = 'prototype';
  7. var $export = function (type, name, source) {
  8. var IS_FORCED = type & $export.F;
  9. var IS_GLOBAL = type & $export.G;
  10. var IS_STATIC = type & $export.S;
  11. var IS_PROTO = type & $export.P;
  12. var IS_BIND = type & $export.B;
  13. var target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE];
  14. var exports = IS_GLOBAL ? core : core[name] || (core[name] = {});
  15. var expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {});
  16. var key, own, out, exp;
  17. if (IS_GLOBAL) source = name;
  18. for (key in source) {
  19. // contains in native
  20. own = !IS_FORCED && target && target[key] !== undefined;
  21. // export native or passed
  22. out = (own ? target : source)[key];
  23. // bind timers to global for call from export context
  24. exp = IS_BIND && own ? ctx(out, global) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
  25. // extend global
  26. if (target) redefine(target, key, out, type & $export.U);
  27. // export
  28. if (exports[key] != out) hide(exports, key, exp);
  29. if (IS_PROTO && expProto[key] != out) expProto[key] = out;
  30. }
  31. };
  32. global.core = core;
  33. // type bitmap
  34. $export.F = 1; // forced
  35. $export.G = 2; // global
  36. $export.S = 4; // static
  37. $export.P = 8; // proto
  38. $export.B = 16; // bind
  39. $export.W = 32; // wrap
  40. $export.U = 64; // safe
  41. $export.R = 128; // real proto method for `library`
  42. module.exports = $export;