8023721: Simplify eval in DebuggerSupport.
authorjlaskey
Mon, 26 Aug 2013 15:33:40 -0300
changeset 19635 b1a895c53316
parent 19634 67426988370f
child 19636 ce19ba858512
8023721: Simplify eval in DebuggerSupport. Reviewed-by: sundar, lagergren, hannesw Contributed-by: james.laskey@oracle.com
nashorn/src/jdk/nashorn/internal/runtime/DebuggerSupport.java
--- a/nashorn/src/jdk/nashorn/internal/runtime/DebuggerSupport.java	Mon Aug 26 15:59:41 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/DebuggerSupport.java	Mon Aug 26 15:33:40 2013 -0300
@@ -79,6 +79,27 @@
     }
 
     /**
+     * Call eval on the current global.
+     * @param scope           Scope to use.
+     * @param self            Receiver to use.
+     * @param string          String to evaluate.
+     * @param returnException true if exceptions are to be returned.
+     * @return Result of eval as string, or, an exception or null depending on returnException.
+     */
+    static Object eval(final ScriptObject scope, final Object self, final String string, final boolean returnException) {
+        final ScriptObject global = Context.getGlobalTrusted();
+        final ScriptObject initialScope = scope != null ? scope : global;
+        final Object callThis = self != null ? self : global;
+        final Context context = global.getContext();
+
+        try {
+            return context.eval(initialScope, string, callThis, ScriptRuntime.UNDEFINED, false);
+        } catch (Throwable ex) {
+            return returnException ? ex : null;
+        }
+    }
+
+    /**
      * This method returns a bulk description of an object's properties.
      * @param object Script object to be displayed by the debugger.
      * @param all    true if to include non-enumerable values.
@@ -135,7 +156,7 @@
 
         for (int i = 0; i < keys.length; i++) {
             final String key = keys[i];
-            descs[i] = valueInfo(key, object.get(key), true, duplicates);
+            descs[i] = valueInfo(key, object.get(key), all, duplicates);
         }
 
         duplicates.remove(object);
@@ -172,7 +193,7 @@
                         }
 
                         if (valueAsObject instanceof ScriptObject && !(valueAsObject instanceof ScriptFunction)) {
-                            final String objectString = objectAsString((ScriptObject)valueAsObject, true, duplicates);
+                            final String objectString = objectAsString((ScriptObject)valueAsObject, all, duplicates);
                             sb.append(objectString != null ? objectString : "{...}");
                         } else {
                             sb.append(valueAsString(valueAsObject));