Search in sources :

Example 46 with Callable

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

the class ProxyObject method isExtensible.

/**
     * 9.5.3 [[IsExtensible]] ( )
     */
@Override
public boolean isExtensible(ExecutionContext cx) {
    /* steps 1-3 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 4 */
    ScriptObject target = getProxyTarget();
    /* steps 5-6 */
    Callable trap = GetMethod(cx, handler, "isExtensible");
    /* step 7 */
    if (trap == null) {
        return target.isExtensible(cx);
    }
    /* steps 8-9 */
    boolean trapResult = ToBoolean(trap.call(cx, handler, target));
    /* steps 10-11 */
    boolean targetResult = target.isExtensible(cx);
    /* step 12 */
    if (trapResult != targetResult) {
        throw newTypeError(cx, Messages.Key.ProxyExtensible);
    }
    /* step 13 */
    return trapResult;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 47 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, Symbol 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 48 with Callable

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

the class ProxyObject method getPrototypeOf.

/**
     * 9.5.1 [[GetPrototypeOf]] ( )
     */
@Override
public ScriptObject getPrototypeOf(ExecutionContext cx) {
    /* steps 1-3 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 4 */
    ScriptObject target = getProxyTarget();
    /* steps 5-6 */
    Callable trap = GetMethod(cx, handler, "getPrototypeOf");
    /* step 7 */
    if (trap == null) {
        return target.getPrototypeOf(cx);
    }
    /* steps 8-9 */
    Object handlerProto = trap.call(cx, handler, target);
    /* step 10 */
    if (!Type.isObjectOrNull(handlerProto)) {
        throw newTypeError(cx, Messages.Key.NotObjectOrNull);
    }
    ScriptObject handlerProtoObj = Type.objectValueOrNull(handlerProto);
    /* steps 11-12 */
    boolean extensibleTarget = IsExtensible(cx, target);
    /* step 13 */
    if (extensibleTarget) {
        return handlerProtoObj;
    }
    /* steps 14-15 */
    ScriptObject targetProto = target.getPrototypeOf(cx);
    /* step 16 */
    if (handlerProtoObj != targetProto) {
        throw newTypeError(cx, Messages.Key.ProxySamePrototype);
    }
    /* step 17 */
    return handlerProtoObj;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 49 with Callable

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

the class ProxyObject method getOwnProperty.

/**
     * 9.5.5 [[GetOwnProperty]] (P)
     */
@Override
public Property getOwnProperty(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, "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 50 with Callable

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

the class ProxyObject method preventExtensions.

/**
     * 9.5.4 [[PreventExtensions]] ( )
     */
@Override
public boolean preventExtensions(ExecutionContext cx) {
    /* steps 1-3 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 4 */
    ScriptObject target = getProxyTarget();
    /* steps 5-6 */
    Callable trap = GetMethod(cx, handler, "preventExtensions");
    /* step 7 */
    if (trap == null) {
        return target.preventExtensions(cx);
    }
    /* steps 8-9 */
    boolean trapResult = ToBoolean(trap.call(cx, handler, target));
    /* step 10 */
    if (trapResult) {
        boolean targetIsExtensible = target.isExtensible(cx);
        if (targetIsExtensible) {
            throw newTypeError(cx, Messages.Key.ProxyExtensible);
        }
    }
    /* step 11 */
    return trapResult;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) 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