use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class OrdinaryObject method getValue.
/**
* 9.1.8 [[Get]] (P, Receiver)
*
* @param cx
* the execution context
* @param propertyKey
* the property key
* @param receiver
* the receiver object
* @return the property value
*/
protected Object getValue(ExecutionContext cx, Symbol propertyKey, Object receiver) {
/* step 1 (implicit) */
/* steps 2-3 */
Property desc = getProperty(cx, propertyKey);
/* step 4 */
if (desc == null) {
ScriptObject parent = getPrototypeOf(cx);
if (parent == null) {
return UNDEFINED;
}
return parent.get(cx, propertyKey, receiver);
}
/* step 5 */
if (desc.isDataDescriptor()) {
return desc.getValue();
}
assert desc.isAccessorDescriptor();
/* step 6 */
Callable getter = desc.getGetter();
/* step 7 */
if (getter == null) {
return UNDEFINED;
}
/* step 8 */
return getter.call(cx, receiver, EMPTY_GETTER_ARGS);
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class OrdinaryObject method deleteRangeDense.
private long deleteRangeDense(long startIndex, long endIndex) {
IndexedMap<Property> indexed = indexedProperties;
for (long index = endIndex; startIndex < index; ) {
Property prop = indexed.get(--index);
if (prop != null && !prop.isConfigurable()) {
return index;
}
indexed.removeUnchecked(index);
}
return -1;
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class OrdinaryObject method ordinaryDefineOwnProperty.
/**
* 9.1.6.1 OrdinaryDefineOwnProperty (O, P, Desc)
*
* @param cx
* the execution context
* @param propertyKey
* the property key
* @param desc
* the property descriptor
* @return {@code true} on success
*/
protected final boolean ordinaryDefineOwnProperty(ExecutionContext cx, Symbol propertyKey, PropertyDescriptor desc) {
/* steps 1-2 */
Property current = getProperty(cx, propertyKey);
/* step 3 */
boolean extensible = isExtensible();
/* step 4 */
return validateAndApplyPropertyDescriptor(symbolProperties, propertyKey, extensible, desc, current);
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class OrdinaryObject method setValue.
/**
* 9.1.9 [[Set] (P, V, Receiver)
*
* @param cx
* the execution context
* @param propertyKey
* the property key
* @param value
* the new property value
* @param receiver
* the receiver object
* @return {@code true} on success
*/
protected boolean setValue(ExecutionContext cx, String propertyKey, Object value, Object receiver) {
/* step 1 (implicit) */
/* steps 2-3 */
Property ownDesc = getProperty(cx, propertyKey);
/* step 4 */
if (ownDesc == null) {
ScriptObject parent = getPrototypeOf(cx);
if (parent != null) {
return parent.set(cx, propertyKey, value, receiver);
} else {
ownDesc = new Property(UNDEFINED, true, true, true);
}
} else if (receiver == this && ownDesc.isWritable()) {
// Optimize the common case for own, writable properties
return setPropertyValue(cx, propertyKey, value, ownDesc);
}
/* step 5 */
if (ownDesc.isDataDescriptor()) {
if (!ownDesc.isWritable()) {
return false;
}
if (!Type.isObject(receiver)) {
return false;
}
ScriptObject _receiver = Type.objectValue(receiver);
Property existingDescriptor = _receiver.getOwnProperty(cx, propertyKey);
if (existingDescriptor != null) {
if (existingDescriptor.isAccessorDescriptor() || !existingDescriptor.isWritable()) {
return false;
}
PropertyDescriptor valueDesc = new PropertyDescriptor(value);
return _receiver.defineOwnProperty(cx, propertyKey, valueDesc);
} else {
return CreateDataProperty(cx, _receiver, propertyKey, value);
}
}
/* step 6 */
assert ownDesc.isAccessorDescriptor();
Callable setter = ownDesc.getSetter();
if (setter == null) {
return false;
}
setter.call(cx, receiver, value);
return true;
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class ProxyObject method validateOwnPropertyKeys.
private List<Object> validateOwnPropertyKeys(ExecutionContext cx, ScriptObject target, Object trapResultArray) {
/* steps 9-10 */
List<Object> trapResult = CreateListFromArrayLike(cx, trapResultArray, EnumSet.of(Type.String, Type.Symbol));
/* steps 11-12 */
boolean extensibleTarget = target.isExtensible(cx);
/* steps 13-15 */
List<?> targetKeys = target.ownPropertyKeys(cx);
/* step 16 */
ArrayList<Object> targetConfigurableKeys = new ArrayList<>();
/* step 17 */
ArrayList<Object> targetNonConfigurableKeys = new ArrayList<>();
/* step 18 */
for (Object key : targetKeys) {
Property desc = target.getOwnProperty(cx, key);
if (desc != null && !desc.isConfigurable()) {
targetNonConfigurableKeys.add(key);
} else {
targetConfigurableKeys.add(key);
}
}
/* step 19 */
if (extensibleTarget && targetNonConfigurableKeys.isEmpty()) {
return trapResult;
}
/* step 20 */
final Integer zero = Integer.valueOf(0);
HashMap<Object, Integer> uncheckedResultKeys = new HashMap<>();
for (Object key : trapResult) {
Integer c = uncheckedResultKeys.put(key, zero);
if (c != null) {
uncheckedResultKeys.put(key, c + 1);
}
}
/* step 21 */
for (Object key : targetNonConfigurableKeys) {
Integer c = uncheckedResultKeys.remove(key);
if (c == null) {
throw newTypeError(cx, Messages.Key.ProxyNotConfigurable);
}
if (c > 0) {
uncheckedResultKeys.put(key, c - 1);
}
}
/* step 22 */
if (extensibleTarget) {
return trapResult;
}
/* step 23 */
for (Object key : targetConfigurableKeys) {
Integer c = uncheckedResultKeys.remove(key);
if (c == null) {
throw newTypeError(cx, Messages.Key.ProxyNotExtensible);
}
if (c > 0) {
uncheckedResultKeys.put(key, c - 1);
}
}
/* step 24 */
if (!uncheckedResultKeys.isEmpty()) {
throw newTypeError(cx, Messages.Key.ProxyAbsentNotExtensible);
}
/* step 25 */
return trapResult;
}
Aggregations