source: imaps-frontend/node_modules/es-abstract/helpers/DefineOwnProperty.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.5 KB
RevLine 
[d565449]1'use strict';
2
3var hasPropertyDescriptors = require('has-property-descriptors');
4
5var $defineProperty = require('es-define-property');
6
7var hasArrayLengthDefineBug = hasPropertyDescriptors.hasArrayLengthDefineBug();
8
9// eslint-disable-next-line global-require
10var isArray = hasArrayLengthDefineBug && require('../helpers/IsArray');
11
12var callBound = require('call-bind/callBound');
13
14var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
15
16// eslint-disable-next-line max-params
17module.exports = function DefineOwnProperty(IsDataDescriptor, SameValue, FromPropertyDescriptor, O, P, desc) {
18 if (!$defineProperty) {
19 if (!IsDataDescriptor(desc)) {
20 // ES3 does not support getters/setters
21 return false;
22 }
23 if (!desc['[[Configurable]]'] || !desc['[[Writable]]']) {
24 return false;
25 }
26
27 // fallback for ES3
28 if (P in O && $isEnumerable(O, P) !== !!desc['[[Enumerable]]']) {
29 // a non-enumerable existing property
30 return false;
31 }
32
33 // property does not exist at all, or exists but is enumerable
34 var V = desc['[[Value]]'];
35 // eslint-disable-next-line no-param-reassign
36 O[P] = V; // will use [[Define]]
37 return SameValue(O[P], V);
38 }
39 if (
40 hasArrayLengthDefineBug
41 && P === 'length'
42 && '[[Value]]' in desc
43 && isArray(O)
44 && O.length !== desc['[[Value]]']
45 ) {
46 // eslint-disable-next-line no-param-reassign
47 O.length = desc['[[Value]]'];
48 return O.length === desc['[[Value]]'];
49 }
50
51 $defineProperty(O, P, FromPropertyDescriptor(desc));
52 return true;
53};
Note: See TracBrowser for help on using the repository browser.