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

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

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