1 | 'use strict';
|
2 | var DESCRIPTORS = require('../internals/descriptors');
|
3 | var IE8_DOM_DEFINE = require('../internals/ie8-dom-define');
|
4 | var V8_PROTOTYPE_DEFINE_BUG = require('../internals/v8-prototype-define-bug');
|
5 | var anObject = require('../internals/an-object');
|
6 | var toPropertyKey = require('../internals/to-property-key');
|
7 |
|
8 | var $TypeError = TypeError;
|
9 |
|
10 | var $defineProperty = Object.defineProperty;
|
11 |
|
12 | var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
13 | var ENUMERABLE = 'enumerable';
|
14 | var CONFIGURABLE = 'configurable';
|
15 | var WRITABLE = 'writable';
|
16 |
|
17 |
|
18 |
|
19 | exports.f = DESCRIPTORS ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) {
|
20 | anObject(O);
|
21 | P = toPropertyKey(P);
|
22 | anObject(Attributes);
|
23 | if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) {
|
24 | var current = $getOwnPropertyDescriptor(O, P);
|
25 | if (current && current[WRITABLE]) {
|
26 | O[P] = Attributes.value;
|
27 | Attributes = {
|
28 | configurable: CONFIGURABLE in Attributes ? Attributes[CONFIGURABLE] : current[CONFIGURABLE],
|
29 | enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE],
|
30 | writable: false
|
31 | };
|
32 | }
|
33 | } return $defineProperty(O, P, Attributes);
|
34 | } : $defineProperty : function defineProperty(O, P, Attributes) {
|
35 | anObject(O);
|
36 | P = toPropertyKey(P);
|
37 | anObject(Attributes);
|
38 | if (IE8_DOM_DEFINE) try {
|
39 | return $defineProperty(O, P, Attributes);
|
40 | } catch (error) { }
|
41 | if ('get' in Attributes || 'set' in Attributes) throw new $TypeError('Accessors not supported');
|
42 | if ('value' in Attributes) O[P] = Attributes.value;
|
43 | return O;
|
44 | };
|