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