Version 1
[yaffs-website] / node_modules / core-js / modules / library / _export.js
1 var global    = require('./_global')
2   , core      = require('./_core')
3   , ctx       = require('./_ctx')
4   , hide      = require('./_hide')
5   , PROTOTYPE = 'prototype';
6
7 var $export = function(type, name, source){
8   var IS_FORCED = type & $export.F
9     , IS_GLOBAL = type & $export.G
10     , IS_STATIC = type & $export.S
11     , IS_PROTO  = type & $export.P
12     , IS_BIND   = type & $export.B
13     , IS_WRAP   = type & $export.W
14     , exports   = IS_GLOBAL ? core : core[name] || (core[name] = {})
15     , expProto  = exports[PROTOTYPE]
16     , target    = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE]
17     , key, own, out;
18   if(IS_GLOBAL)source = name;
19   for(key in source){
20     // contains in native
21     own = !IS_FORCED && target && target[key] !== undefined;
22     if(own && key in exports)continue;
23     // export native or passed
24     out = own ? target[key] : source[key];
25     // prevent global pollution for namespaces
26     exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key]
27     // bind timers to global for call from export context
28     : IS_BIND && own ? ctx(out, global)
29     // wrap global constructors for prevent change them in library
30     : IS_WRAP && target[key] == out ? (function(C){
31       var F = function(a, b, c){
32         if(this instanceof C){
33           switch(arguments.length){
34             case 0: return new C;
35             case 1: return new C(a);
36             case 2: return new C(a, b);
37           } return new C(a, b, c);
38         } return C.apply(this, arguments);
39       };
40       F[PROTOTYPE] = C[PROTOTYPE];
41       return F;
42     // make static versions for prototype methods
43     })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
44     // export proto methods to core.%CONSTRUCTOR%.methods.%NAME%
45     if(IS_PROTO){
46       (exports.virtual || (exports.virtual = {}))[key] = out;
47       // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME%
48       if(type & $export.R && expProto && !expProto[key])hide(expProto, key, out);
49     }
50   }
51 };
52 // type bitmap
53 $export.F = 1;   // forced
54 $export.G = 2;   // global
55 $export.S = 4;   // static
56 $export.P = 8;   // proto
57 $export.B = 16;  // bind
58 $export.W = 32;  // wrap
59 $export.U = 64;  // safe
60 $export.R = 128; // real proto method for `library` 
61 module.exports = $export;