2016-10-10 03:43:44 +02:00
|
|
|
// 26.1.13 Reflect.set(target, propertyKey, V [, receiver])
|
2017-04-20 03:09:25 +02:00
|
|
|
var $ = require('./$')
|
|
|
|
, has = require('./$.has')
|
|
|
|
, $export = require('./$.export')
|
|
|
|
, createDesc = require('./$.property-desc')
|
|
|
|
, anObject = require('./$.an-object')
|
|
|
|
, isObject = require('./$.is-object');
|
2016-10-10 03:43:44 +02:00
|
|
|
|
|
|
|
function set(target, propertyKey, V/*, receiver*/){
|
|
|
|
var receiver = arguments.length < 4 ? target : arguments[3]
|
2017-04-20 03:09:25 +02:00
|
|
|
, ownDesc = $.getDesc(anObject(target), propertyKey)
|
2016-10-10 03:43:44 +02:00
|
|
|
, existingDescriptor, proto;
|
|
|
|
if(!ownDesc){
|
2017-04-20 03:09:25 +02:00
|
|
|
if(isObject(proto = $.getProto(target))){
|
2016-10-10 03:43:44 +02:00
|
|
|
return set(proto, propertyKey, V, receiver);
|
|
|
|
}
|
|
|
|
ownDesc = createDesc(0);
|
|
|
|
}
|
|
|
|
if(has(ownDesc, 'value')){
|
|
|
|
if(ownDesc.writable === false || !isObject(receiver))return false;
|
2017-04-20 03:09:25 +02:00
|
|
|
existingDescriptor = $.getDesc(receiver, propertyKey) || createDesc(0);
|
2016-10-10 03:43:44 +02:00
|
|
|
existingDescriptor.value = V;
|
2017-04-20 03:09:25 +02:00
|
|
|
$.setDesc(receiver, propertyKey, existingDescriptor);
|
2016-10-10 03:43:44 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return ownDesc.set === undefined ? false : (ownDesc.set.call(receiver, V), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$export($export.S, 'Reflect', {set: set});
|