debian-mirror-gitlab/core-js/modules/es.reflect.set.js

46 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-09-25 13:30:05 +05:30
var $ = require('../internals/export');
var anObject = require('../internals/an-object');
var isObject = require('../internals/is-object');
var has = require('../internals/has');
2019-12-04 20:38:33 +05:30
var fails = require('../internals/fails');
2019-09-25 13:30:05 +05:30
var definePropertyModule = require('../internals/object-define-property');
var getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');
var getPrototypeOf = require('../internals/object-get-prototype-of');
var createPropertyDescriptor = require('../internals/create-property-descriptor');
// `Reflect.set` method
// https://tc39.github.io/ecma262/#sec-reflect.set
function set(target, propertyKey, V /* , receiver */) {
var receiver = arguments.length < 4 ? target : arguments[3];
var ownDescriptor = getOwnPropertyDescriptorModule.f(anObject(target), propertyKey);
var existingDescriptor, prototype;
if (!ownDescriptor) {
if (isObject(prototype = getPrototypeOf(target))) {
return set(prototype, propertyKey, V, receiver);
}
ownDescriptor = createPropertyDescriptor(0);
}
if (has(ownDescriptor, 'value')) {
if (ownDescriptor.writable === false || !isObject(receiver)) return false;
if (existingDescriptor = getOwnPropertyDescriptorModule.f(receiver, propertyKey)) {
if (existingDescriptor.get || existingDescriptor.set || existingDescriptor.writable === false) return false;
existingDescriptor.value = V;
definePropertyModule.f(receiver, propertyKey, existingDescriptor);
} else definePropertyModule.f(receiver, propertyKey, createPropertyDescriptor(0, V));
return true;
}
return ownDescriptor.set === undefined ? false : (ownDescriptor.set.call(receiver, V), true);
}
2019-12-04 20:38:33 +05:30
// MS Edge 17-18 Reflect.set allows setting the property to object
// with non-writable property on the prototype
var MS_EDGE_BUG = fails(function () {
var object = definePropertyModule.f({}, 'a', { configurable: true });
// eslint-disable-next-line no-undef
return Reflect.set(getPrototypeOf(object), 'a', 1, object) !== false;
});
$({ target: 'Reflect', stat: true, forced: MS_EDGE_BUG }, {
2019-09-25 13:30:05 +05:30
set: set
});