All Downloads are FREE. Search and download functionalities are using the official Maven repository.

webit.script.core.ast.method.FunctionMethodDeclare Maven / Gradle / Ivy

There is a newer version: 1.5.2
Show newest version
// Copyright (c) 2013, Webit Team. All Rights Reserved.
package webit.script.core.ast.method;

import webit.script.Context;
import webit.script.Template;
import webit.script.core.ast.expressions.FunctionDeclareExpression;
import webit.script.core.runtime.VariantContext;
import webit.script.exceptions.ScriptRuntimeException;
import webit.script.util.ExceptionUtil;

/**
 *
 * @author Zqq
 */
public final class FunctionMethodDeclare implements MethodDeclare {

    private final FunctionDeclareExpression function;
    private final Template template;
    private final VariantContext[] parentVarContexts;

    public FunctionMethodDeclare(FunctionDeclareExpression function, Template template, VariantContext[] parentVarContexts) {
        this.function = function;
        this.template = template;
        this.parentVarContexts = parentVarContexts;
    }

    public Object invoke(final Context context, final Object[] args) {
        try {
            return function.invoke(new Context(context, template, parentVarContexts), args);
        } catch (Throwable e) {
            throw template == context.template
                    ? ExceptionUtil.castToScriptRuntimeException(e, function)
                    : new ScriptRuntimeException(ExceptionUtil.castToScriptRuntimeException(e, function).setTemplate(template));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy