Search in sources :

Example 21 with PropertyDescriptor

use of com.github.anba.es6draft.runtime.types.PropertyDescriptor 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, long 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;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)21 Property (com.github.anba.es6draft.runtime.types.Property)10 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)10 Callable (com.github.anba.es6draft.runtime.types.Callable)6 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)5 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)5 AccessorPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor)4 BuiltinSymbol (com.github.anba.es6draft.runtime.types.BuiltinSymbol)3 MethodHandle (java.lang.invoke.MethodHandle)3 FromPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor)2 ToPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor)2 NativeFunction (com.github.anba.es6draft.runtime.types.builtins.NativeFunction)2 EnumMap (java.util.EnumMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Script (com.github.anba.es6draft.Script)1 HasOwnProperty (com.github.anba.es6draft.runtime.AbstractOperations.HasOwnProperty)1 AtomicsObject (com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject)1 IntlObject (com.github.anba.es6draft.runtime.objects.intl.IntlObject)1 MathObject (com.github.anba.es6draft.runtime.objects.number.MathObject)1 RealmObject (com.github.anba.es6draft.runtime.objects.reflect.RealmObject)1