source: imaps-frontend/node_modules/es-abstract/2022/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: 2.0 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 some = require('../helpers/some');
9var OwnPropertyKeys = require('../helpers/OwnPropertyKeys');
10
11var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
12
13var CreateDataPropertyOrThrow = require('./CreateDataPropertyOrThrow');
14var Get = require('./Get');
15var IsArray = require('./IsArray');
16var IsIntegralNumber = require('./IsIntegralNumber');
17var IsPropertyKey = require('./IsPropertyKey');
18var SameValue = require('./SameValue');
19var ToNumber = require('./ToNumber');
20var ToObject = require('./ToObject');
21var Type = require('./Type');
22
23// https://262.ecma-international.org/12.0/#sec-copydataproperties
24
25module.exports = function CopyDataProperties(target, source, excludedItems) {
26 if (Type(target) !== 'Object') {
27 throw new $TypeError('Assertion failed: "target" must be an Object');
28 }
29
30 if (!IsArray(excludedItems) || !every(excludedItems, IsPropertyKey)) {
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 keys = OwnPropertyKeys(from);
41 forEach(keys, function (nextKey) {
42 var excluded = some(excludedItems, function (e) {
43 return SameValue(e, nextKey) === true;
44 });
45 /*
46 var excluded = false;
47
48 forEach(excludedItems, function (e) {
49 if (SameValue(e, nextKey) === true) {
50 excluded = true;
51 }
52 });
53 */
54
55 var enumerable = $isEnumerable(from, nextKey) || (
56 // this is to handle string keys being non-enumerable in older engines
57 typeof source === 'string'
58 && nextKey >= 0
59 && IsIntegralNumber(ToNumber(nextKey))
60 );
61 if (excluded === false && enumerable) {
62 var propValue = Get(from, nextKey);
63 CreateDataPropertyOrThrow(target, nextKey, propValue);
64 }
65 });
66
67 return target;
68};
Note: See TracBrowser for help on using the repository browser.