Search in sources :

Example 56 with Callable

use of com.github.anba.es6draft.runtime.types.Callable 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)

Example 57 with Callable

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

the class ProxyObject method defineOwnProperty.

/**
     * 9.5.6 [[DefineOwnProperty]] (P, Desc)
     */
@Override
public boolean defineOwnProperty(ExecutionContext cx, String propertyKey, PropertyDescriptor desc) {
    /* step 1 (implicit) */
    /* steps 2-4 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 5 */
    ScriptObject target = getProxyTarget();
    /* steps 6-7 */
    Callable trap = GetMethod(cx, handler, "defineProperty");
    /* step 8 */
    if (trap == null) {
        return target.defineOwnProperty(cx, propertyKey, desc);
    }
    /* step 9 */
    Object descObj = FromPropertyDescriptor(cx, desc);
    /* steps 10-11 */
    boolean trapResult = ToBoolean(trap.call(cx, handler, target, propertyKey, descObj));
    /* step 12 */
    if (!trapResult) {
        return false;
    }
    /* steps 13-14 */
    Property targetDesc = target.getOwnProperty(cx, propertyKey);
    /* steps 15-21 */
    return validateDefineOwnProperty(cx, desc, target, 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 58 with Callable

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

the class ProxyObject method set.

/**
     * 9.5.9 [[Set]] ( P, V, Receiver)
     */
@Override
public boolean set(ExecutionContext cx, Symbol 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 59 with Callable

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

the class ProxyObject method delete.

/**
     * 9.5.10 [[Delete]] (P)
     */
@Override
public boolean delete(ExecutionContext cx, Symbol propertyKey) {
    /* step 1 (implicit) */
    /* steps 2-4 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 5 */
    ScriptObject target = getProxyTarget();
    /* steps 6-7 */
    Callable trap = GetMethod(cx, handler, "deleteProperty");
    /* step 8 */
    if (trap == null) {
        return target.delete(cx, propertyKey);
    }
    /* steps 9-10 */
    boolean trapResult = ToBoolean(trap.call(cx, handler, target, propertyKey));
    /* step 11 */
    if (!trapResult) {
        return false;
    }
    /* steps 12-13 */
    Property targetDesc = target.getOwnProperty(cx, propertyKey);
    /* steps 14-16 */
    return validateDelete(cx, 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)

Aggregations

Callable (com.github.anba.es6draft.runtime.types.Callable)59 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)49 Property (com.github.anba.es6draft.runtime.types.Property)26 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)10 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)7 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)7 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)6 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)3 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)3 ArrayList (java.util.ArrayList)3 Jump (com.github.anba.es6draft.compiler.assembler.Jump)2 Realm (com.github.anba.es6draft.runtime.Realm)2 PromiseObject (com.github.anba.es6draft.runtime.objects.promise.PromiseObject)2 com.github.anba.es6draft.ast (com.github.anba.es6draft.ast)1 Abrupt (com.github.anba.es6draft.ast.AbruptNode.Abrupt)1 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)1 ModuleScope (com.github.anba.es6draft.ast.scope.ModuleScope)1 Name (com.github.anba.es6draft.ast.scope.Name)1 Scope (com.github.anba.es6draft.ast.scope.Scope)1 ScriptScope (com.github.anba.es6draft.ast.scope.ScriptScope)1