1 | var $ = require('../internals/export');
|
---|
2 | var anObject = require('../internals/an-object');
|
---|
3 | var isObject = require('../internals/is-object');
|
---|
4 | var has = require('../internals/has');
|
---|
5 | var fails = require('../internals/fails');
|
---|
6 | var definePropertyModule = require('../internals/object-define-property');
|
---|
7 | var getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');
|
---|
8 | var getPrototypeOf = require('../internals/object-get-prototype-of');
|
---|
9 | var createPropertyDescriptor = require('../internals/create-property-descriptor');
|
---|
10 |
|
---|
11 | // `Reflect.set` method
|
---|
12 | // https://tc39.es/ecma262/#sec-reflect.set
|
---|
13 | function set(target, propertyKey, V /* , receiver */) {
|
---|
14 | var receiver = arguments.length < 4 ? target : arguments[3];
|
---|
15 | var ownDescriptor = getOwnPropertyDescriptorModule.f(anObject(target), propertyKey);
|
---|
16 | var existingDescriptor, prototype;
|
---|
17 | if (!ownDescriptor) {
|
---|
18 | if (isObject(prototype = getPrototypeOf(target))) {
|
---|
19 | return set(prototype, propertyKey, V, receiver);
|
---|
20 | }
|
---|
21 | ownDescriptor = createPropertyDescriptor(0);
|
---|
22 | }
|
---|
23 | if (has(ownDescriptor, 'value')) {
|
---|
24 | if (ownDescriptor.writable === false || !isObject(receiver)) return false;
|
---|
25 | if (existingDescriptor = getOwnPropertyDescriptorModule.f(receiver, propertyKey)) {
|
---|
26 | if (existingDescriptor.get || existingDescriptor.set || existingDescriptor.writable === false) return false;
|
---|
27 | existingDescriptor.value = V;
|
---|
28 | definePropertyModule.f(receiver, propertyKey, existingDescriptor);
|
---|
29 | } else definePropertyModule.f(receiver, propertyKey, createPropertyDescriptor(0, V));
|
---|
30 | return true;
|
---|
31 | }
|
---|
32 | return ownDescriptor.set === undefined ? false : (ownDescriptor.set.call(receiver, V), true);
|
---|
33 | }
|
---|
34 |
|
---|
35 | // MS Edge 17-18 Reflect.set allows setting the property to object
|
---|
36 | // with non-writable property on the prototype
|
---|
37 | var MS_EDGE_BUG = fails(function () {
|
---|
38 | var Constructor = function () { /* empty */ };
|
---|
39 | var object = definePropertyModule.f(new Constructor(), 'a', { configurable: true });
|
---|
40 | // eslint-disable-next-line es/no-reflect -- required for testing
|
---|
41 | return Reflect.set(Constructor.prototype, 'a', 1, object) !== false;
|
---|
42 | });
|
---|
43 |
|
---|
44 | $({ target: 'Reflect', stat: true, forced: MS_EDGE_BUG }, {
|
---|
45 | set: set
|
---|
46 | });
|
---|