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