Search in sources :

Example 16 with Callable

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

the class ScriptEngineImpl method invoke.

private Object invoke(ScriptObject thisValue, String name, Object... args) throws javax.script.ScriptException, NoSuchMethodException {
    Realm realm = getEvalRealm(context);
    RuntimeContext runtimeContext = realm.getWorld().getContext();
    Console console = runtimeContext.getConsole();
    runtimeContext.setConsole(new ScriptingConsole(context));
    try {
        Object[] arguments = TypeConverter.fromJava(args);
        if (thisValue == null) {
            thisValue = realm.getGlobalThis();
        }
        ExecutionContext cx = realm.defaultContext();
        Object func = thisValue.get(cx, name, thisValue);
        if (!IsCallable(func)) {
            throw new NoSuchMethodException(name);
        }
        Object result = ((Callable) func).call(cx, thisValue, arguments);
        realm.getWorld().runEventLoop();
        return TypeConverter.toJava(result);
    } catch (ScriptException e) {
        throw new javax.script.ScriptException(e);
    } finally {
        runtimeContext.setConsole(console);
    }
}
Also used : ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ExecutionContext.newScriptingExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newScriptingExecutionContext) Console(com.github.anba.es6draft.runtime.internal.Console) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RuntimeContext(com.github.anba.es6draft.runtime.internal.RuntimeContext) Realm(com.github.anba.es6draft.runtime.Realm) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 17 with Callable

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

the class OrdinaryFunction method AddRestrictedFunctionProperties.

/**
     * 9.2.7 AddRestrictedFunctionProperties ( F, realm )
     * 
     * @param <FUNCTION>
     *            the function type
     * @param f
     *            the function object
     * @param realm
     *            the realm object
     */
public static <FUNCTION extends OrdinaryObject & Callable> void AddRestrictedFunctionProperties(FUNCTION f, Realm realm) {
    /* steps 1-2 */
    Callable thrower = realm.getThrowTypeError();
    /* steps 3-4 */
    f.infallibleDefineOwnProperty("caller", new Property(thrower, thrower, false, true));
    /* steps 5-6 */
    f.infallibleDefineOwnProperty("arguments", new Property(thrower, thrower, false, true));
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 18 with Callable

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

the class BoundFunctionObject method call.

/**
     * 9.4.1.1 [[Call]] (thisArgument, argumentsList)
     */
@Override
public final Object call(ExecutionContext callerContext, Object thisValue, Object... argumentsList) {
    /* step 1 */
    Callable target = getFlattenedTargetFunction();
    /* step 2 */
    Object boundThis = getBoundThis();
    /* step 3 */
    Object[] boundArgs = getBoundArguments();
    /* step 4 */
    Object[] args = concatArguments(callerContext, boundArgs, argumentsList);
    /* step 5 */
    return target.call(callerContext, boundThis, args);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 19 with Callable

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

the class BoundFunctionObject method tailCall.

/**
     * 9.4.1.1 [[Call]] (thisArgument, argumentsList)
     */
@Override
public final Object tailCall(ExecutionContext callerContext, Object thisValue, Object... argumentsList) throws Throwable {
    /* step 1 */
    Callable target = getFlattenedTargetFunction();
    /* step 2 */
    Object boundThis = getBoundThis();
    /* step 3 */
    Object[] boundArgs = getBoundArguments();
    /* step 4 */
    Object[] args = concatArguments(callerContext, boundArgs, argumentsList);
    /* step 5 */
    return target.tailCall(callerContext, boundThis, args);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 20 with Callable

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

the class OrdinaryObject method getValue.

/**
     * 9.1.8 [[Get]] (P, Receiver)
     *
     * @param cx
     *            the execution context
     * @param propertyKey
     *            the property key
     * @param receiver
     *            the receiver object
     * @return the property value
     */
protected Object getValue(ExecutionContext cx, String propertyKey, Object receiver) {
    /* step 1 (implicit) */
    /* steps 2-3 */
    Property desc = getProperty(cx, propertyKey);
    /* step 4 */
    if (desc == null) {
        ScriptObject parent = getPrototypeOf(cx);
        if (parent == null) {
            return UNDEFINED;
        }
        return parent.get(cx, propertyKey, receiver);
    }
    /* step 5 */
    if (desc.isDataDescriptor()) {
        return desc.getValue();
    }
    assert desc.isAccessorDescriptor();
    /* step 6 */
    Callable getter = desc.getGetter();
    /* step 7 */
    if (getter == null) {
        return UNDEFINED;
    }
    /* step 8 */
    return getter.call(cx, receiver, EMPTY_GETTER_ARGS);
}
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