Search in sources :

Example 1 with Debugger

use of org.mozilla.javascript.debug.Debugger in project Auto.js by hyb1996.

the class Dim method do_eval.

/**
 * Evaluates script in the given stack frame.
 */
private static String do_eval(Context cx, StackFrame frame, String expr) {
    String resultString;
    Debugger saved_debugger = cx.getDebugger();
    Object saved_data = cx.getDebuggerContextData();
    int saved_level = cx.getOptimizationLevel();
    cx.setDebugger(null, null);
    cx.setOptimizationLevel(-1);
    cx.setGeneratingDebug(false);
    try {
        Callable script = (Callable) cx.compileString(expr, "", 0, null);
        Object result = script.call(cx, frame.scope, frame.thisObj, ScriptRuntime.emptyArgs);
        if (result == Undefined.instance) {
            resultString = "";
        } else {
            resultString = ScriptRuntime.toString(result);
        }
    } catch (Exception exc) {
        resultString = exc.getMessage();
    } finally {
        cx.setGeneratingDebug(true);
        cx.setOptimizationLevel(saved_level);
        cx.setDebugger(saved_debugger, saved_data);
    }
    if (resultString == null) {
        resultString = "null";
    }
    return resultString;
}
Also used : Debugger(org.mozilla.javascript.debug.Debugger)

Example 2 with Debugger

use of org.mozilla.javascript.debug.Debugger in project servoy-client by Servoy.

the class WebServiceScriptable method getScript.

private static Script getScript(Context context, URL serverScript, IApplication app) throws URISyntaxException, IOException {
    Pair<Script, Long> pair = scripts.get(serverScript.toURI());
    long lastModified = -1;
    URLConnection connection = serverScript.openConnection();
    connection.setUseCaches(false);
    if (connection instanceof JarURLConnection) {
        try (JarFile jarFile = ((JarURLConnection) connection).getJarFile()) {
            lastModified = new File(jarFile.getName()).lastModified();
        }
    } else
        lastModified = connection.getLastModified();
    if (pair == null || pair.getRight().longValue() < lastModified) {
        String name = "";
        URI uri = serverScript.toURI();
        if ("file".equals(uri.getScheme())) {
            File file = new File(uri);
            if (file.exists()) {
                name = file.getAbsolutePath();
            }
        }
        Debugger debugger = null;
        int lvl = context.getOptimizationLevel();
        Script script;
        try {
            if (app instanceof IDebugClient) {
                if ("".endsWith(name)) {
                    context.setGeneratingDebug(false);
                    debugger = context.getDebugger();
                    if (debugger != null) {
                        context.setOptimizationLevel(9);
                        context.setDebugger(null, null);
                    }
                } else if (context.getDebugger() == null) {
                    // this is a refresh/recreate forms, could be because of a server side script edit/change
                    // then the debugger is not attached because it is not the event thread. make sure that
                    // code optimization level is disabled.
                    context.setGeneratingDebug(true);
                    context.setOptimizationLevel(-1);
                }
            } else {
                // in none debug client, don't compile to a java file (classloading problems)
                // but also don't generate debug info
                context.setGeneratingDebug(false);
                context.setOptimizationLevel(-1);
            }
            context.setGeneratingSource(false);
            script = context.compileString(Utils.getURLContent(serverScript), name, 1, null);
        } finally {
            if (debugger != null) {
                context.setDebugger(debugger, null);
                context.setOptimizationLevel(lvl);
            }
        }
        pair = new Pair<Script, Long>(script, Long.valueOf(lastModified));
        scripts.put(uri, pair);
    }
    return pair.getLeft();
}
Also used : Debugger(org.mozilla.javascript.debug.Debugger) Script(org.mozilla.javascript.Script) IDebugClient(com.servoy.j2db.IDebugClient) JarURLConnection(java.net.JarURLConnection) JarFile(java.util.jar.JarFile) URI(java.net.URI) URLConnection(java.net.URLConnection) JarURLConnection(java.net.JarURLConnection) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 3 with Debugger

use of org.mozilla.javascript.debug.Debugger in project servoy-client by Servoy.

the class ScriptVariableScope method put.

/*
	 * @see Scriptable#put(String, Scriptable, Object)
	 */
@Override
public void put(String name, Scriptable arg1, Object value) {
    if (value instanceof Function) {
        super.put(name, arg1, value);
    } else {
        try {
            Context currentContext = Context.getCurrentContext();
            if (currentContext != null) {
                Debugger debugger = currentContext.getDebugger();
                if (debugger != null) {
                    if (debugger instanceof IDebuggerWithWatchPoints) {
                        IDebuggerWithWatchPoints wp = (IDebuggerWithWatchPoints) debugger;
                        wp.modification(name, this);
                    }
                }
            }
            put(name, value);
        } catch (RuntimeException re) {
            throw new WrappedException(re);
        }
    }
}
Also used : Context(org.mozilla.javascript.Context) Debugger(org.mozilla.javascript.debug.Debugger) Function(org.mozilla.javascript.Function) WrappedException(org.mozilla.javascript.WrappedException) IDebuggerWithWatchPoints(org.mozilla.javascript.debug.IDebuggerWithWatchPoints)

Example 4 with Debugger

use of org.mozilla.javascript.debug.Debugger in project servoy-client by Servoy.

the class LazyCompilationScope method get.

@Override
public Object get(String name, Scriptable start) {
    Object o = getImpl(name, start);
    if (o != Scriptable.NOT_FOUND) {
        Context currentContext = Context.getCurrentContext();
        if (currentContext != null) {
            Debugger debugger = currentContext.getDebugger();
            if (debugger instanceof IDebuggerWithWatchPoints) {
                IDebuggerWithWatchPoints wp = (IDebuggerWithWatchPoints) debugger;
                wp.access(name, this);
            }
        }
    }
    return o;
}
Also used : Context(org.mozilla.javascript.Context) Debugger(org.mozilla.javascript.debug.Debugger) IDebuggerWithWatchPoints(org.mozilla.javascript.debug.IDebuggerWithWatchPoints)

Example 5 with Debugger

use of org.mozilla.javascript.debug.Debugger in project servoy-client by Servoy.

the class FormDialog method setVisible.

@Override
public void setVisible(boolean b) {
    for (IWindowVisibleChangeListener l : visibleChangeListeners.toArray(new IWindowVisibleChangeListener[visibleChangeListeners.size()])) l.beforeVisibleChange(this, b);
    if (!b) {
        // For future implementation of case 286968 change
        // if (persistBounds)
        // {
        // super.setVisible(false);
        // }
        // else
        // {
        String name = getName();
        // the parent will not save the bounds this way in Servoy.properties
        setName(null);
        super.setVisible(false);
        setName(name);
    // }
    } else {
        Context context = null;
        Debugger debugger = null;
        Object debuggerContextData = null;
        if (isModal() && Utils.isAppleMacOS()) {
            context = Context.enter();
            debugger = context.getDebugger();
            debuggerContextData = context.getDebuggerContextData();
            context.setDebugger(null, null);
        }
        try {
            super.setVisible(true);
        } finally {
            if (isModal() && Utils.isAppleMacOS()) {
                context.setDebugger(debugger, debuggerContextData);
                Context.exit();
            }
        }
    }
}
Also used : Context(org.mozilla.javascript.Context) Debugger(org.mozilla.javascript.debug.Debugger) IWindowVisibleChangeListener(com.servoy.j2db.ui.IWindowVisibleChangeListener)

Aggregations

Debugger (org.mozilla.javascript.debug.Debugger)6 Context (org.mozilla.javascript.Context)4 WrappedException (org.mozilla.javascript.WrappedException)2 IDebuggerWithWatchPoints (org.mozilla.javascript.debug.IDebuggerWithWatchPoints)2 IDebugClient (com.servoy.j2db.IDebugClient)1 IServiceProvider (com.servoy.j2db.IServiceProvider)1 IWindowVisibleChangeListener (com.servoy.j2db.ui.IWindowVisibleChangeListener)1 File (java.io.File)1 JarURLConnection (java.net.JarURLConnection)1 URI (java.net.URI)1 URLConnection (java.net.URLConnection)1 Date (java.util.Date)1 JarFile (java.util.jar.JarFile)1 Function (org.mozilla.javascript.Function)1 NativeArray (org.mozilla.javascript.NativeArray)1 NativeJavaClass (org.mozilla.javascript.NativeJavaClass)1 Script (org.mozilla.javascript.Script)1 Wrapper (org.mozilla.javascript.Wrapper)1 XMLObject (org.mozilla.javascript.xml.XMLObject)1