Search in sources :

Example 1 with Reference

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

the class Interpreter method visit.

@Override
public Object visit(AssignmentExpression node, ExecutionContext cx) {
    if (node.getOperator() == AssignmentExpression.Operator.ASSIGN) {
        Reference<?, ?> lref = (Reference<?, ?>) node.getLeft().accept(this, cx);
        Object rval = GetValue(node.getRight().accept(this, cx), cx);
        PutValue(lref, rval, cx);
        return rval;
    } else {
        Reference<?, ?> lref = (Reference<?, ?>) node.getLeft().accept(this, cx);
        Object lval = GetValue(lref, cx);
        Object rval = GetValue(node.getRight().accept(this, cx), cx);
        Object r;
        switch(node.getOperator()) {
            case ASSIGN_ADD:
                r = ScriptRuntime.add(lval, rval, cx);
                break;
            case ASSIGN_BITAND:
                r = bitand(lval, rval, cx);
                break;
            case ASSIGN_BITOR:
                r = bitor(lval, rval, cx);
                break;
            case ASSIGN_BITXOR:
                r = bitxor(lval, rval, cx);
                break;
            case ASSIGN_DIV:
                r = div(lval, rval, cx);
                break;
            case ASSIGN_EXP:
                r = exp(lval, rval, cx);
                break;
            case ASSIGN_MOD:
                r = mod(lval, rval, cx);
                break;
            case ASSIGN_MUL:
                r = mul(lval, rval, cx);
                break;
            case ASSIGN_SHL:
                r = leftShift(lval, rval, cx);
                break;
            case ASSIGN_SHR:
                r = rightShift(lval, rval, cx);
                break;
            case ASSIGN_SUB:
                r = sub(lval, rval, cx);
                break;
            case ASSIGN_USHR:
                r = unsignedRightShift(lval, rval, cx);
                break;
            case ASSIGN:
            default:
                throw new AssertionError();
        }
        PutValue(lref, r, cx);
        return r;
    }
}
Also used : 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)

Example 2 with Reference

use of com.github.anba.es6draft.runtime.types.Reference 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

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