Search in sources :

Example 21 with Property

use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.

the class ProxyObject method set.

/**
     * 9.5.9 [[Set]] ( P, V, Receiver)
     */
@Override
public boolean set(ExecutionContext cx, String propertyKey, Object value, Object receiver) {
    /* step 1 (implicit) */
    /* steps 2-4 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 5 */
    ScriptObject target = getProxyTarget();
    /* steps 6-7 */
    Callable trap = GetMethod(cx, handler, "set");
    /* step 8 */
    if (trap == null) {
        return target.set(cx, propertyKey, value, receiver);
    }
    /* steps 9-10 */
    boolean trapResult = ToBoolean(trap.call(cx, handler, target, propertyKey, value, receiver));
    /* step 11 */
    if (!trapResult) {
        return false;
    }
    /* steps 12-13 */
    Property targetDesc = target.getOwnProperty(cx, propertyKey);
    /* steps 14-15 */
    return validateSet(cx, value, targetDesc);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 22 with Property

use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.

the class ProxyObject method getOwnProperty.

/**
     * 9.5.5 [[GetOwnProperty]] (P)
     */
@Override
public Property getOwnProperty(ExecutionContext cx, String propertyKey) {
    /* step 1 (implicit) */
    /* steps 2-4 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 5 */
    ScriptObject target = getProxyTarget();
    /* steps 6-7 */
    Callable trap = GetMethod(cx, handler, "getOwnPropertyDescriptor");
    /* step 8 */
    if (trap == null) {
        return target.getOwnProperty(cx, propertyKey);
    }
    /* steps 9-10 */
    Object trapResultObj = trap.call(cx, handler, target, propertyKey);
    /* step 11 */
    if (!(Type.isObject(trapResultObj) || Type.isUndefined(trapResultObj))) {
        throw newTypeError(cx, Messages.Key.ProxyNotObjectOrUndefined);
    }
    /* steps 12-13 */
    Property targetDesc = target.getOwnProperty(cx, propertyKey);
    /* steps 14-23 */
    return validateGetOwnProperty(cx, target, trapResultObj, targetDesc);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 23 with Property

use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.

the class ProxyObject method hasProperty.

/**
     * 9.5.7 [[HasProperty]] (P)
     */
@Override
public boolean hasProperty(ExecutionContext cx, String propertyKey) {
    /* step 1 (implicit) */
    /* steps 2-4 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 5 */
    ScriptObject target = getProxyTarget();
    /* steps 6-7 */
    Callable trap = GetMethod(cx, handler, "has");
    /* step 8 */
    if (trap == null) {
        return target.hasProperty(cx, propertyKey);
    }
    /* steps 9-10 */
    boolean trapResult = ToBoolean(trap.call(cx, handler, target, propertyKey));
    /* step 11 */
    if (!trapResult) {
        /* steps 11.a-11.b */
        Property targetDesc = target.getOwnProperty(cx, propertyKey);
        /* step 11.c */
        validateHasProperty(cx, target, targetDesc);
    }
    /* step 12 */
    return trapResult;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 24 with Property

use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.

the class WrapperProxy method get.

@Override
public Object get(ExecutionContext cx, Symbol propertyKey, Object receiver) {
    /* modified 9.1.8 [[Get]] (P, Receiver) */
    Property desc = proxyTarget.getOwnProperty(cx, propertyKey);
    if (desc == null) {
        // modified
        ScriptObject parent = getPrototype();
        if (parent == null) {
            return UNDEFINED;
        }
        return parent.get(cx, propertyKey, receiver);
    }
    if (desc.isDataDescriptor()) {
        return desc.getValue();
    }
    assert desc.isAccessorDescriptor();
    Callable getter = desc.getGetter();
    if (getter == null) {
        return UNDEFINED;
    }
    return getter.call(cx, receiver);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 25 with Property

use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.

the class WrapperProxy method set.

@Override
public boolean set(ExecutionContext cx, String propertyKey, Object value, Object receiver) {
    /* modified 9.1.9 [[Set] (P, V, Receiver) */
    Property ownDesc = proxyTarget.getOwnProperty(cx, propertyKey);
    if (ownDesc == null) {
        // modified
        ScriptObject parent = getPrototype();
        if (parent != null) {
            return parent.set(cx, propertyKey, value, receiver);
        } else {
            ownDesc = new Property(UNDEFINED, true, true, true);
        }
    }
    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) {
            PropertyDescriptor valueDesc = new PropertyDescriptor(value);
            return _receiver.defineOwnProperty(cx, propertyKey, valueDesc);
        } else {
            return CreateDataProperty(cx, _receiver, propertyKey, value);
        }
    }
    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

Property (com.github.anba.es6draft.runtime.types.Property)51 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)33 Callable (com.github.anba.es6draft.runtime.types.Callable)26 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)10 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)8 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)4 ArrayList (java.util.ArrayList)3 CompilationException (com.github.anba.es6draft.compiler.CompilationException)2 ParserException (com.github.anba.es6draft.parser.ParserException)2 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)2 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)2 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)2 Source (com.github.anba.es6draft.runtime.internal.Source)2 FunctionConstructor.functionSource (com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource)2 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)2 ImmutablePrototypeObject (com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject)2 HasOwnProperty (com.github.anba.es6draft.runtime.AbstractOperations.HasOwnProperty)1 ToFlatString (com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString)1 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)1 AtomicsObject (com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject)1