Search in sources :

Example 11 with Callable

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

the class Eval method directEval.

/**
     * 18.2.1 eval (x)
     * <p>
     * [Called from generated code]
     * 
     * @param arguments
     *            the arguments
     * @param cx
     *            the execution context
     * @param flags
     *            the eval flags
     * @return the evaluation result
     */
public static Object directEval(Object[] arguments, ExecutionContext cx, int flags) {
    assert EvalFlags.Direct.isSet(flags);
    Object source;
    Callable translate = cx.getRealm().getDirectEvalTranslate();
    if (translate != null) {
        source = translate.call(cx, cx.getRealm().getRealmObject(), arguments);
    } else {
        source = arguments.length > 0 ? arguments[0] : UNDEFINED;
    }
    return PerformEval(cx, cx, source, flags);
}
Also used : Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 12 with Callable

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

the class Eval method indirectEval.

/**
     * 18.2.1 eval (x)
     * 
     * @param cx
     *            the execution context
     * @param caller
     *            the caller context
     * @param arguments
     *            the arguments
     * @return the evaluation result
     */
public static Object indirectEval(ExecutionContext cx, ExecutionContext caller, Object... arguments) {
    Object source;
    Callable indirectEval = cx.getRealm().getIndirectEval();
    if (indirectEval != null) {
        source = indirectEval.call(cx, cx.getRealm().getRealmObject(), arguments);
    } else {
        source = arguments.length > 0 ? arguments[0] : UNDEFINED;
    }
    return globalEval(cx, caller, source);
}
Also used : Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 13 with Callable

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

the class MapConstructor method construct.

/**
     * 23.1.1.1 Map ([ iterable ])
     */
@Override
public MapObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object iterable = argument(args, 0);
    /* step 1 (not applicable) */
    /* steps 2-4 */
    MapObject map = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.MapPrototype, MapObject::new);
    /* steps 5-6, 8 */
    if (Type.isUndefinedOrNull(iterable)) {
        return map;
    }
    /* step 7 */
    Object _adder = Get(calleeContext, map, "set");
    if (!IsCallable(_adder)) {
        throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "set");
    }
    Callable adder = (Callable) _adder;
    boolean isBuiltin = MapPrototype.isBuiltinSet(_adder);
    if (isBuiltin && iterable instanceof MapObject) {
        MapObject other = (MapObject) iterable;
        if (ScriptIterators.isBuiltinIterator(calleeContext, other)) {
            map.getMapData().setAll(other.getMapData());
            return map;
        }
    }
    ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
    /* step 9 */
    try {
        while (iter.hasNext()) {
            Object nextItem = iter.next();
            if (!Type.isObject(nextItem)) {
                throw newTypeError(calleeContext, Messages.Key.MapPairNotObject);
            }
            ScriptObject item = Type.objectValue(nextItem);
            Object k = Get(calleeContext, item, 0);
            Object v = Get(calleeContext, item, 1);
            if (isBuiltin) {
                map.getMapData().set(k, v);
            } else {
                adder.call(calleeContext, map, k, v);
            }
        }
        return map;
    } catch (ScriptException e) {
        iter.close(e);
        throw e;
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 14 with Callable

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

the class WeakMapConstructor method construct.

/**
     * 23.3.1.1 WeakMap ([ iterable ])
     */
@Override
public WeakMapObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object iterable = argument(args, 0);
    /* step 1 (not applicable) */
    /* steps 2-4 */
    WeakMapObject map = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.WeakMapPrototype, WeakMapObject::new);
    /* steps 5-6, 8 */
    if (Type.isUndefinedOrNull(iterable)) {
        return map;
    }
    /* step 7 */
    Object _adder = Get(calleeContext, map, "set");
    if (!IsCallable(_adder)) {
        throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "set");
    }
    Callable adder = (Callable) _adder;
    ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
    /* step 9 */
    try {
        while (iter.hasNext()) {
            Object nextItem = iter.next();
            if (!Type.isObject(nextItem)) {
                throw newTypeError(calleeContext, Messages.Key.WeakMapPairNotObject);
            }
            ScriptObject item = Type.objectValue(nextItem);
            Object k = Get(calleeContext, item, 0);
            Object v = Get(calleeContext, item, 1);
            adder.call(calleeContext, map, k, v);
        }
        return map;
    } catch (ScriptException e) {
        iter.close(e);
        throw e;
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 15 with Callable

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

the class WeakSetConstructor method construct.

/**
     * 23.4.1.1 WeakSet ([ iterable ])
     */
@Override
public WeakSetObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object iterable = argument(args, 0);
    /* step 1 (not applicable) */
    /* steps 2-4 */
    WeakSetObject set = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.WeakSetPrototype, WeakSetObject::new);
    /* steps 5-6, 8 */
    if (Type.isUndefinedOrNull(iterable)) {
        return set;
    }
    /* step 7 */
    Object _adder = Get(calleeContext, set, "add");
    if (!IsCallable(_adder)) {
        throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "add");
    }
    Callable adder = (Callable) _adder;
    ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
    /* step 9 */
    try {
        while (iter.hasNext()) {
            Object nextValue = iter.next();
            adder.call(calleeContext, set, nextValue);
        }
        return set;
    } catch (ScriptException e) {
        iter.close(e);
        throw e;
    }
}
Also used : ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) 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