41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
var global = require('./$.global')
|
|
, core = require('./$.core')
|
|
, hide = require('./$.hide')
|
|
, redefine = require('./$.redefine')
|
|
, ctx = require('./$.ctx')
|
|
, PROTOTYPE = 'prototype';
|
|
|
|
var $export = function(type, name, source){
|
|
var IS_FORCED = type & $export.F
|
|
, IS_GLOBAL = type & $export.G
|
|
, IS_STATIC = type & $export.S
|
|
, IS_PROTO = type & $export.P
|
|
, IS_BIND = type & $export.B
|
|
, target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE]
|
|
, exports = IS_GLOBAL ? core : core[name] || (core[name] = {})
|
|
, expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {})
|
|
, key, own, out, exp;
|
|
if(IS_GLOBAL)source = name;
|
|
for(key in source){
|
|
// contains in native
|
|
own = !IS_FORCED && target && key in target;
|
|
// export native or passed
|
|
out = (own ? target : source)[key];
|
|
// bind timers to global for call from export context
|
|
exp = IS_BIND && own ? ctx(out, global) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
|
|
// extend global
|
|
if(target && !own)redefine(target, key, out);
|
|
// export
|
|
if(exports[key] != out)hide(exports, key, exp);
|
|
if(IS_PROTO && expProto[key] != out)expProto[key] = out;
|
|
}
|
|
};
|
|
global.core = core;
|
|
// type bitmap
|
|
$export.F = 1; // forced
|
|
$export.G = 2; // global
|
|
$export.S = 4; // static
|
|
$export.P = 8; // proto
|
|
$export.B = 16; // bind
|
|
$export.W = 32; // wrap
|
|
module.exports = $export; |