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;
}
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);
}
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();
}
}
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);
}
}
}
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;
}
Aggregations