source: imaps-frontend/node_modules/es-abstract/2020/CopyDataProperties.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[d565449]1'use strict';
2
3var $TypeError = require('es-errors/type');
4
[79a0317]5var callBound = require('call-bound');
[d565449]6var forEach = require('../helpers/forEach');
7var every = require('../helpers/every');
[79a0317]8var OwnPropertyKeys = require('own-keys');
[d565449]9
10var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
11
12var CreateDataPropertyOrThrow = require('./CreateDataPropertyOrThrow');
13var Get = require('./Get');
14var IsArray = require('./IsArray');
15var IsInteger = require('./IsInteger');
[79a0317]16var isPropertyKey = require('../helpers/isPropertyKey');
[d565449]17var SameValue = require('./SameValue');
18var ToNumber = require('./ToNumber');
19var ToObject = require('./ToObject');
[79a0317]20
21var isObject = require('../helpers/isObject');
[d565449]22
23// https://262.ecma-international.org/11.0/#sec-copydataproperties
24
25module.exports = function CopyDataProperties(target, source, excludedItems) {
[79a0317]26 if (!isObject(target)) {
[d565449]27 throw new $TypeError('Assertion failed: "target" must be an Object');
28 }
29
[79a0317]30 if (!IsArray(excludedItems) || !every(excludedItems, isPropertyKey)) {
[d565449]31 throw new $TypeError('Assertion failed: "excludedItems" must be a List of Property Keys');
32 }
33
34 if (typeof source === 'undefined' || source === null) {
35 return target;
36 }
37
38 var from = ToObject(source);
39
40 var sourceKeys = OwnPropertyKeys(from);
41 forEach(sourceKeys, function (nextKey) {
42 var excluded = false;
43
44 forEach(excludedItems, function (e) {
45 if (SameValue(e, nextKey) === true) {
46 excluded = true;
47 }
48 });
49
50 var enumerable = $isEnumerable(from, nextKey) || (
51 // this is to handle string keys being non-enumerable in older engines
52 typeof source === 'string'
53 && nextKey >= 0
54 && IsInteger(ToNumber(nextKey))
55 );
56 if (excluded === false && enumerable) {
57 var propValue = Get(from, nextKey);
58 CreateDataPropertyOrThrow(target, nextKey, propValue);
59 }
60 });
61
62 return target;
63};
Note: See TracBrowser for help on using the repository browser.