source: imaps-frontend/node_modules/es-abstract/2019/CopyDataProperties.js@ d565449

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

Update repo after prototype presentation

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