Search in sources :

Example 1 with Variables

use of lucee.runtime.type.scope.Variables in project Lucee by lucee.

the class ComponentImpl method beforeCall.

/**
 * will be called before executing method or constructor
 * @param pc
 * @return the old scope map
 */
public Variables beforeCall(PageContext pc) {
    Variables parent = pc.variablesScope();
    pc.setVariablesScope(scope);
    return parent;
}
Also used : Variables(lucee.runtime.type.scope.Variables)

Example 2 with Variables

use of lucee.runtime.type.scope.Variables in project Lucee by lucee.

the class Evaluate method call.

public static Object call(PageContext pc, Object[] objs, boolean preciseMath) throws PageException {
    // define a ohter enviroment for the function
    if (objs.length > 1 && objs[objs.length - 1] instanceof Scope) {
        // Variables Scope
        Variables var = null;
        Local lcl = null, cLcl = null;
        Argument arg = null, cArg = null;
        if (objs[objs.length - 1] instanceof Variables) {
            var = (Variables) objs[objs.length - 1];
        } else if (objs[objs.length - 1] instanceof CallerImpl) {
            CallerImpl ci = ((CallerImpl) objs[objs.length - 1]);
            var = ci.getVariablesScope();
            lcl = ci.getLocalScope();
            arg = ci.getArgumentsScope();
        }
        if (var != null) {
            Variables cVar = pc.variablesScope();
            pc.setVariablesScope(var);
            if (lcl != null && !(lcl instanceof LocalNotSupportedScope)) {
                cLcl = pc.localScope();
                cArg = pc.argumentsScope();
                pc.setFunctionScopes(lcl, arg);
            }
            try {
                return _call(pc, objs, objs.length - 1, preciseMath);
            } finally {
                pc.setVariablesScope(cVar);
                if (cLcl != null)
                    pc.setFunctionScopes(cLcl, cArg);
            }
        } else // Undefined Scope
        if (objs[objs.length - 1] instanceof Undefined) {
            PageContextImpl pci = (PageContextImpl) pc;
            Undefined undefined = (Undefined) objs[objs.length - 1];
            boolean check = undefined.getCheckArguments();
            Variables orgVar = pc.variablesScope();
            Argument orgArgs = pc.argumentsScope();
            Local orgLocal = pc.localScope();
            pci.setVariablesScope(undefined.variablesScope());
            if (check)
                pci.setFunctionScopes(undefined.localScope(), undefined.argumentsScope());
            try {
                return _call(pc, objs, objs.length - 1, preciseMath);
            } finally {
                pc.setVariablesScope(orgVar);
                if (check)
                    pci.setFunctionScopes(orgLocal, orgArgs);
            }
        }
    }
    return _call(pc, objs, objs.length, preciseMath);
}
Also used : Variables(lucee.runtime.type.scope.Variables) Undefined(lucee.runtime.type.scope.Undefined) CallerImpl(lucee.runtime.type.scope.CallerImpl) Scope(lucee.runtime.type.scope.Scope) LocalNotSupportedScope(lucee.runtime.type.scope.LocalNotSupportedScope) Argument(lucee.runtime.type.scope.Argument) LocalNotSupportedScope(lucee.runtime.type.scope.LocalNotSupportedScope) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl)

Example 3 with Variables

use of lucee.runtime.type.scope.Variables in project Lucee by lucee.

the class CFFunction method loadUDF.

public static UDF loadUDF(PageContext pc, String filename, Collection.Key name, boolean isweb) throws PageException {
    ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
    String key = isweb ? name.getString() + config.getIdentification().getId() : name.getString();
    UDF udf = config.getFromFunctionCache(key);
    if (udf != null)
        return udf;
    Mapping mapping = isweb ? config.getFunctionMapping() : config.getServerFunctionMapping();
    Page p = mapping.getPageSource(filename).loadPage(pc, false);
    // execute page
    Variables old = pc.variablesScope();
    pc.setVariablesScope(VAR);
    boolean wasSilent = pc.setSilent();
    try {
        p.call(pc);
        Object o = pc.variablesScope().get(name, null);
        if (o instanceof UDF) {
            udf = (UDF) o;
            config.putToFunctionCache(key, udf);
            return udf;
        }
        throw new ExpressionException("there is no Function defined with name [" + name + "] in template [" + mapping.getStrPhysical() + File.separator + filename + "]");
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    } finally {
        pc.setVariablesScope(old);
        if (!wasSilent)
            pc.unsetSilent();
    }
}
Also used : Variables(lucee.runtime.type.scope.Variables) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) UDF(lucee.runtime.type.UDF) Mapping(lucee.runtime.Mapping) Page(lucee.runtime.Page) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 4 with Variables

use of lucee.runtime.type.scope.Variables in project Lucee by lucee.

the class CFTag method doInclude.

void doInclude() throws PageException {
    Variables var = pageContext.variablesScope();
    pageContext.setVariablesScope(ctVariablesScope);
    QueryStack cs = null;
    Undefined undefined = pageContext.undefinedScope();
    int oldMode = undefined.setMode(Undefined.MODE_NO_LOCAL_AND_ARGUMENTS);
    if (oldMode != Undefined.MODE_NO_LOCAL_AND_ARGUMENTS)
        callerScope.setScope(var, pageContext.localScope(), pageContext.argumentsScope(), true);
    else
        callerScope.setScope(var, null, null, false);
    if (pageContext.getConfig().allowImplicidQueryCall()) {
        cs = undefined.getQueryStack();
        undefined.setQueryStack(new QueryStackImpl());
    }
    try {
        pageContext.doInclude(new PageSource[] { source.getPageSource() }, false);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    } finally {
        undefined.setMode(oldMode);
        // varScopeData=variablesScope.getMap();
        pageContext.setVariablesScope(var);
        if (pageContext.getConfig().allowImplicidQueryCall()) {
            undefined.setQueryStack(cs);
        }
    }
}
Also used : Variables(lucee.runtime.type.scope.Variables) Undefined(lucee.runtime.type.scope.Undefined) QueryStack(lucee.runtime.util.QueryStack) QueryStackImpl(lucee.runtime.util.QueryStackImpl)

Example 5 with Variables

use of lucee.runtime.type.scope.Variables in project Lucee by lucee.

the class ComponentImpl method _call.

Object _call(PageContext pc, Collection.Key calledName, UDFPlus udf, Struct namedArgs, Object[] args) throws PageException {
    Object rtn = null;
    Variables parent = null;
    // debug yes
    if (pc.getConfig().debug()) {
        // new DebugEntry(src,udf.getFunctionName());
        DebugEntryTemplate debugEntry = pc.getDebugger().getEntry(pc, pageSource, udf.getFunctionName());
        long currTime = pc.getExecutionTime();
        long time = System.nanoTime();
        // sync yes
        if (top.properties._synchronized) {
            synchronized (this) {
                try {
                    parent = beforeCall(pc);
                    if (args != null)
                        rtn = udf.call(pc, calledName, args, true);
                    else
                        rtn = udf.callWithNamedValues(pc, calledName, namedArgs, true);
                } finally {
                    pc.setVariablesScope(parent);
                    long diff = ((System.nanoTime() - time) - (pc.getExecutionTime() - currTime));
                    pc.setExecutionTime(pc.getExecutionTime() + diff);
                    debugEntry.updateExeTime(diff);
                }
            }
        } else // sync no
        {
            try {
                parent = beforeCall(pc);
                if (args != null)
                    rtn = udf.call(pc, calledName, args, true);
                else
                    rtn = udf.callWithNamedValues(pc, calledName, namedArgs, true);
            } finally {
                pc.setVariablesScope(parent);
                long diff = ((System.nanoTime() - time) - (pc.getExecutionTime() - currTime));
                pc.setExecutionTime(pc.getExecutionTime() + diff);
                debugEntry.updateExeTime(diff);
            }
        }
    } else // debug no
    {
        // sync yes
        if (top.properties._synchronized) {
            synchronized (this) {
                try {
                    parent = beforeCall(pc);
                    if (args != null)
                        rtn = udf.call(pc, calledName, args, true);
                    else
                        rtn = udf.callWithNamedValues(pc, calledName, namedArgs, true);
                } finally {
                    pc.setVariablesScope(parent);
                }
            }
        } else // sync no 385|263
        {
            try {
                parent = beforeCall(pc);
                if (args != null)
                    rtn = udf.call(pc, calledName, args, true);
                else
                    rtn = udf.callWithNamedValues(pc, calledName, namedArgs, true);
            } finally {
                pc.setVariablesScope(parent);
            }
        }
    }
    return rtn;
}
Also used : Variables(lucee.runtime.type.scope.Variables) DebugEntryTemplate(lucee.runtime.debug.DebugEntryTemplate)

Aggregations

Variables (lucee.runtime.type.scope.Variables)8 Undefined (lucee.runtime.type.scope.Undefined)3 PageContextImpl (lucee.runtime.PageContextImpl)2 DebugEntryTemplate (lucee.runtime.debug.DebugEntryTemplate)2 Argument (lucee.runtime.type.scope.Argument)2 CallerImpl (lucee.runtime.type.scope.CallerImpl)2 Local (lucee.runtime.type.scope.Local)2 Mapping (lucee.runtime.Mapping)1 Page (lucee.runtime.Page)1 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 UDF (lucee.runtime.type.UDF)1 LocalNotSupportedScope (lucee.runtime.type.scope.LocalNotSupportedScope)1 Scope (lucee.runtime.type.scope.Scope)1 QueryStack (lucee.runtime.util.QueryStack)1 QueryStackImpl (lucee.runtime.util.QueryStackImpl)1