2020-08-26 01:57:08 +02:00
|
|
|
'use strict';
|
|
|
|
|
2021-02-26 04:58:33 +01:00
|
|
|
var GetIntrinsic = require('get-intrinsic');
|
2020-08-26 01:57:08 +02:00
|
|
|
|
|
|
|
var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
|
|
|
|
|
|
|
|
if ($defineProperty) {
|
|
|
|
try {
|
|
|
|
$defineProperty({}, 'a', { value: 1 });
|
|
|
|
} catch (e) {
|
|
|
|
// IE 8 has a broken defineProperty
|
|
|
|
$defineProperty = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 04:58:33 +01:00
|
|
|
var callBound = require('call-bind/callBound');
|
2020-08-26 01:57:08 +02:00
|
|
|
|
|
|
|
var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
|
|
|
|
|
|
|
// eslint-disable-next-line max-params
|
|
|
|
module.exports = function DefineOwnProperty(IsDataDescriptor, SameValue, FromPropertyDescriptor, O, P, desc) {
|
|
|
|
if (!$defineProperty) {
|
|
|
|
if (!IsDataDescriptor(desc)) {
|
|
|
|
// ES3 does not support getters/setters
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!desc['[[Configurable]]'] || !desc['[[Writable]]']) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// fallback for ES3
|
|
|
|
if (P in O && $isEnumerable(O, P) !== !!desc['[[Enumerable]]']) {
|
|
|
|
// a non-enumerable existing property
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// property does not exist at all, or exists but is enumerable
|
|
|
|
var V = desc['[[Value]]'];
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
O[P] = V; // will use [[Define]]
|
|
|
|
return SameValue(O[P], V);
|
|
|
|
}
|
|
|
|
$defineProperty(O, P, FromPropertyDescriptor(desc));
|
|
|
|
return true;
|
|
|
|
};
|