Search in sources :

Example 1 with IPerformanceDataProvider

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;
}
Also used : ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) NativeFunction(org.mozilla.javascript.NativeFunction) Function(org.mozilla.javascript.Function) IPerformanceDataProvider(com.servoy.j2db.server.shared.IPerformanceDataProvider) PerformanceData(com.servoy.j2db.server.shared.PerformanceData) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) Scriptable(org.mozilla.javascript.Scriptable)

Aggregations

FoundSet (com.servoy.j2db.dataprocessing.FoundSet)1 ScriptCalculation (com.servoy.j2db.persistence.ScriptCalculation)1 IPerformanceDataProvider (com.servoy.j2db.server.shared.IPerformanceDataProvider)1 PerformanceData (com.servoy.j2db.server.shared.PerformanceData)1 Function (org.mozilla.javascript.Function)1 NativeFunction (org.mozilla.javascript.NativeFunction)1 Scriptable (org.mozilla.javascript.Scriptable)1