保誠-保戶業務員媒合平台
Tomas
2022-05-19 957a1f10a06fdbb76f1a0ba94fe44126c613fee3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
 
var GetIntrinsic = require('get-intrinsic');
 
var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
 
if ($defineProperty) {
    try {
        $defineProperty({}, 'a', { value: 1 });
    } catch (e) {
        // IE 8 has a broken defineProperty
        $defineProperty = null;
    }
}
 
// node v0.6 has a bug where array lengths can be Set but not Defined
var hasArrayLengthDefineBug = Object.defineProperty && Object.defineProperty([], 'length', { value: 1 }).length === 0;
 
// eslint-disable-next-line global-require
var isArray = hasArrayLengthDefineBug && require('../2020/IsArray'); // this does not depend on any other AOs.
 
var callBound = require('call-bind/callBound');
 
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);
    }
    if (
        hasArrayLengthDefineBug
        && P === 'length'
        && '[[Value]]' in desc
        && isArray(O)
        && O.length !== desc['[[Value]]']
    ) {
        // eslint-disable-next-line no-param-reassign
        O.length = desc['[[Value]]'];
        return O.length === desc['[[Value]]'];
    }
 
    $defineProperty(O, P, FromPropertyDescriptor(desc));
    return true;
};