use of com.servoy.j2db.server.shared.IPerformanceDataProvider in project servoy-client by Servoy.
the class ScriptEngine method compileScriptProvider.
/**
* @param sp
* @param scope
* @param cx
* @return
*/
@SuppressWarnings("nls")
protected Function compileScriptProvider(IScriptProvider sp, Scriptable scope, Context cx, String sourceName) {
String declaration = sp.getDeclaration();
// dont return the calc function itself but still the value.
if (sp instanceof ScriptCalculation) {
declaration = extractFunction(declaration, "function $1_");
} else {
declaration = extractFunction(declaration, "function $1");
}
// f below always seems to be NativeFunction instance as both Codegen.createFunctionObject and Interpreter.createFunctionObject return
// a NativeFunction instance; and that is what cx.compileFunction(...) ends up calling
Function f = cx.compileFunction(scope, declaration, sourceName, sp.getLineNumberOffset(), null);
if (!(sp instanceof ScriptCalculation)) {
if (sp.getScopeName() != null) {
// $NON-NLS-1$
f.put("_scopename_", f, sp.getScopeName());
}
// $NON-NLS-1$
f.put("_methodname_", f, sp.getDataProviderID());
f.put("_AllowToRunInFind_", f, Boolean.valueOf(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
sp.getDeclaration().indexOf("@AllowToRunInFind") != -1 || declaration.indexOf(".search") != -1 || declaration.indexOf("controller.loadAllRecords") != -1));
}
String methodName = sp.getName();
PerformanceData performanceData = application instanceof IPerformanceDataProvider ? ((IPerformanceDataProvider) application).getPerformanceData() : null;
if (performanceData != null) {
String scopeName = scope.getClassName();
if (scope instanceof LazyCompilationScope) {
scopeName = ((LazyCompilationScope) scope).getScopeName();
scopeName = lookForSuperCalls(sp, scopeName);
} else if (scope.getParentScope() instanceof LazyCompilationScope) {
scopeName = ((LazyCompilationScope) scope.getParentScope()).getScopeName();
scopeName = lookForSuperCalls(sp, scopeName);
} else if (scope instanceof FoundSet) {
Scriptable parentScope = ((FoundSet) scope).getPrototype();
if (parentScope instanceof LazyCompilationScope) {
scopeName = ((LazyCompilationScope) parentScope).getScopeName();
}
}
methodName = scopeName + "." + methodName;
return new FunctionWrapper(f, methodName, performanceData, application.getClientID());
}
return f;
}
Aggregations