1
|
'use strict';
|
2
|
|
3
|
var GetIntrinsic = require('../GetIntrinsic');
|
4
|
|
5
|
var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
|
6
|
|
7
|
if ($defineProperty) {
|
8
|
try {
|
9
|
$defineProperty({}, 'a', { value: 1 });
|
10
|
} catch (e) {
|
11
|
// IE 8 has a broken defineProperty
|
12
|
$defineProperty = null;
|
13
|
}
|
14
|
}
|
15
|
|
16
|
var callBound = require('../helpers/callBound');
|
17
|
|
18
|
var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
19
|
|
20
|
// eslint-disable-next-line max-params
|
21
|
module.exports = function DefineOwnProperty(IsDataDescriptor, SameValue, FromPropertyDescriptor, O, P, desc) {
|
22
|
if (!$defineProperty) {
|
23
|
if (!IsDataDescriptor(desc)) {
|
24
|
// ES3 does not support getters/setters
|
25
|
return false;
|
26
|
}
|
27
|
if (!desc['[[Configurable]]'] || !desc['[[Writable]]']) {
|
28
|
return false;
|
29
|
}
|
30
|
|
31
|
// fallback for ES3
|
32
|
if (P in O && $isEnumerable(O, P) !== !!desc['[[Enumerable]]']) {
|
33
|
// a non-enumerable existing property
|
34
|
return false;
|
35
|
}
|
36
|
|
37
|
// property does not exist at all, or exists but is enumerable
|
38
|
var V = desc['[[Value]]'];
|
39
|
// eslint-disable-next-line no-param-reassign
|
40
|
O[P] = V; // will use [[Define]]
|
41
|
return SameValue(O[P], V);
|
42
|
}
|
43
|
$defineProperty(O, P, FromPropertyDescriptor(desc));
|
44
|
return true;
|
45
|
};
|