Search in sources :

Example 1 with CheckCallable

use of com.github.anba.es6draft.runtime.internal.ScriptRuntime.CheckCallable in project es6draft by anba.

the class Interpreter method EvaluateCall.

/**
     * 12.3.4.2 Runtime Semantics: EvaluateCall( ref, arguments, tailPosition )<br>
     * 12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )
     * 
     * @param ref
     *            the call base reference
     * @param arguments
     *            the function call arguments
     * @param directEval
     *            the direct eval flag
     * @param cx
     *            the execution context
     * @return the return value after applying the call operation
     */
private Object EvaluateCall(Object ref, List<Expression> arguments, boolean directEval, ExecutionContext cx) {
    /* steps 1-2 (EvaluateCall) */
    Object func = GetValue(ref, cx);
    /* steps 3-4 (EvaluateCall) */
    Object thisValue = UNDEFINED;
    if (ref instanceof Reference) {
        Reference<?, ?> rref = (Reference<?, ?>) ref;
        if (rref.isPropertyReference()) {
            thisValue = rref.getThisValue();
        } else if (!(rref instanceof Reference.BindingReference)) {
            assert rref instanceof Reference.IdentifierReference;
            Reference.IdentifierReference<?> idref = (Reference.IdentifierReference<?>) rref;
            ScriptObject newThisValue = idref.getBase().withBaseObject();
            if (newThisValue != null) {
                thisValue = newThisValue;
            }
        }
    }
    /* steps 1-2 (EvaluateDirectCall) */
    Object[] argList = ArgumentListEvaluation(arguments, cx);
    /* steps 3-4 (EvaluateDirectCall) */
    Callable f = CheckCallable(func, cx);
    /* [12.3.4.1 Runtime Semantics: Evaluation - step 3] */
    if (directEval && IsBuiltinEval(ref, f, cx)) {
        int evalFlags = EvalFlags.Direct.getValue();
        if (strict) {
            evalFlags |= EvalFlags.Strict.getValue();
        }
        evalFlags |= EvalFlags.toFlags(parserOptions);
        return Eval.directEval(argList, cx, evalFlags);
    }
    if (directEval && ScriptRuntime.directEvalFallbackHook(cx) != null) {
        argList = ScriptRuntime.directEvalFallbackArguments(f, cx, thisValue, argList);
        thisValue = ScriptRuntime.directEvalFallbackThisArgument(cx);
        f = ScriptRuntime.directEvalFallbackHook(cx);
    }
    /* steps 6, 9 (EvaluateDirectCall) */
    return f.call(cx, thisValue, argList);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Reference(com.github.anba.es6draft.runtime.types.Reference) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) CheckCallable(com.github.anba.es6draft.runtime.internal.ScriptRuntime.CheckCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

CheckCallable (com.github.anba.es6draft.runtime.internal.ScriptRuntime.CheckCallable)1 Callable (com.github.anba.es6draft.runtime.types.Callable)1 Reference (com.github.anba.es6draft.runtime.types.Reference)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)1 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)1