[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var hasPropertyDescriptors = require('has-property-descriptors');
|
---|
| 4 |
|
---|
| 5 | var $defineProperty = require('es-define-property');
|
---|
| 6 |
|
---|
| 7 | var hasArrayLengthDefineBug = hasPropertyDescriptors.hasArrayLengthDefineBug();
|
---|
| 8 |
|
---|
| 9 | // eslint-disable-next-line global-require
|
---|
| 10 | var isArray = hasArrayLengthDefineBug && require('../helpers/IsArray');
|
---|
| 11 |
|
---|
| 12 | var callBound = require('call-bind/callBound');
|
---|
| 13 |
|
---|
| 14 | var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
---|
| 15 |
|
---|
| 16 | // eslint-disable-next-line max-params
|
---|
| 17 | module.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 | };
|
---|