source: imaps-frontend/node_modules/es-abstract/2023/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 every = require('../helpers/every');
8var some = require('../helpers/some');
9var OwnPropertyKeys = require('own-keys');
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('../helpers/isPropertyKey');
18var SameValue = require('./SameValue');
19var ToNumber = require('./ToNumber');
20var ToObject = require('./ToObject');
21
22var isObject = require('../helpers/isObject');
23
24// https://262.ecma-international.org/12.0/#sec-copydataproperties
25
26module.exports = function CopyDataProperties(target, source, excludedItems) {
27 if (!isObject(target)) {
28 throw new $TypeError('Assertion failed: "target" must be an Object');
29 }
30
31 if (!IsArray(excludedItems) || !every(excludedItems, isPropertyKey)) {
32 throw new $TypeError('Assertion failed: "excludedItems" must be a List of Property Keys');
33 }
34
35 if (typeof source === 'undefined' || source === null) {
36 return target;
37 }
38
39 var from = ToObject(source);
40
41 var keys = OwnPropertyKeys(from);
42 forEach(keys, function (nextKey) {
43 var excluded = some(excludedItems, function (e) {
44 return SameValue(e, nextKey) === true;
45 });
46 /*
47 var excluded = false;
48
49 forEach(excludedItems, function (e) {
50 if (SameValue(e, nextKey) === true) {
51 excluded = true;
52 }
53 });
54 */
55
56 var enumerable = $isEnumerable(from, nextKey) || (
57 // this is to handle string keys being non-enumerable in older engines
58 typeof source === 'string'
59 && nextKey >= 0
60 && IsIntegralNumber(ToNumber(nextKey))
61 );
62 if (excluded === false && enumerable) {
63 var propValue = Get(from, nextKey);
64 CreateDataPropertyOrThrow(target, nextKey, propValue);
65 }
66 });
67
68 return target;
69};
Note: See TracBrowser for help on using the repository browser.