Search in sources :

Example 61 with Property

use of com.github.anba.es6draft.runtime.types.Property 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();
    /* step 6 */
    Callable trap = GetMethod(cx, handler, "defineProperty");
    /* step 7 */
    if (trap == null) {
        return target.defineOwnProperty(cx, propertyKey, desc);
    }
    /* step 8 */
    Object descObj = FromPropertyDescriptor(cx, desc);
    /* step 9 */
    boolean trapResult = ToBoolean(trap.call(cx, handler, target, propertyKey, descObj));
    /* step 10 */
    if (!trapResult) {
        return false;
    }
    /* step 11 */
    Property targetDesc = target.getOwnProperty(cx, propertyKey);
    /* steps 12-17 */
    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 62 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, Symbol propertyKey, Object value, Object receiver) {
    /* step 1 (implicit) */
    /* steps 2-4 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 5 */
    ScriptObject target = getProxyTarget();
    /* step 6 */
    Callable trap = GetMethod(cx, handler, "set");
    /* step 7 */
    if (trap == null) {
        return target.set(cx, propertyKey, value, receiver);
    }
    /* step 8 */
    boolean trapResult = ToBoolean(trap.call(cx, handler, target, propertyKey, value, receiver));
    /* step 9 */
    if (!trapResult) {
        return false;
    }
    /* step 10 */
    Property targetDesc = target.getOwnProperty(cx, propertyKey);
    /* steps 11-12 */
    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 63 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, Symbol propertyKey) {
    /* step 1 (implicit) */
    /* steps 2-4 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 5 */
    ScriptObject target = getProxyTarget();
    /* step 6 */
    Callable trap = GetMethod(cx, handler, "has");
    /* step 7 */
    if (trap == null) {
        return target.hasProperty(cx, propertyKey);
    }
    /* step 8 */
    boolean booleanTrapResult = ToBoolean(trap.call(cx, handler, target, propertyKey));
    /* step 9 */
    if (!booleanTrapResult) {
        /* step 9.a */
        Property targetDesc = target.getOwnProperty(cx, propertyKey);
        /* step 9.b */
        validateHasProperty(cx, target, targetDesc);
    }
    /* step 10 */
    return booleanTrapResult;
}
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 64 with Property

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

the class ProxyObject method get.

/**
 * 9.5.8 [[Get]] (P, Receiver)
 */
@Override
public Object get(ExecutionContext cx, Symbol propertyKey, Object receiver) {
    /* step 1 (implicit) */
    /* steps 2-4 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 5 */
    ScriptObject target = getProxyTarget();
    /* step 6 */
    Callable trap = GetMethod(cx, handler, "get");
    /* step 7 */
    if (trap == null) {
        return target.get(cx, propertyKey, receiver);
    }
    /* step 8 */
    Object trapResult = trap.call(cx, handler, target, propertyKey, receiver);
    /* step 9 */
    Property targetDesc = target.getOwnProperty(cx, propertyKey);
    /* steps 10-11 */
    return validateGet(cx, trapResult, 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 65 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, long propertyKey) {
    /* step 1 (implicit) */
    /* steps 2-4 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 5 */
    ScriptObject target = getProxyTarget();
    /* step 6 */
    Callable trap = GetMethod(cx, handler, "getOwnPropertyDescriptor");
    /* step 7 */
    if (trap == null) {
        return target.getOwnProperty(cx, propertyKey);
    }
    /* step 8 */
    Object trapResultObj = trap.call(cx, handler, target, ToString(propertyKey));
    /* step 9 */
    if (!(Type.isObject(trapResultObj) || Type.isUndefined(trapResultObj))) {
        throw newTypeError(cx, Messages.Key.ProxyNotObjectOrUndefined);
    }
    /* step 10 */
    Property targetDesc = target.getOwnProperty(cx, propertyKey);
    /* steps 11-18 */
    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)

Aggregations

Property (com.github.anba.es6draft.runtime.types.Property)93 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)54 Callable (com.github.anba.es6draft.runtime.types.Callable)44 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)19 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)18 OrdinaryGenerator (com.github.anba.es6draft.runtime.types.builtins.OrdinaryGenerator)6 OrdinaryAsyncGenerator (com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncGenerator)5 PrivateName (com.github.anba.es6draft.runtime.types.PrivateName)4 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)4 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)4 CreateDataProperty (com.github.anba.es6draft.runtime.AbstractOperations.CreateDataProperty)3 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)3 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)3 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)3 OrdinaryFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryFunction)3 ArrayList (java.util.ArrayList)3 CompilationException (com.github.anba.es6draft.compiler.CompilationException)2 ParserException (com.github.anba.es6draft.parser.ParserException)2 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)2 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)2