Bug 289791 - Debugger should support arrays objects
diff --git a/bundles/org.eclipse.e4.languages.javascript.debug.jsdi.rhino/src/org/eclipse/e4/languages/javascript/jsdi/rhino/ArrayReferenceImpl.java b/bundles/org.eclipse.e4.languages.javascript.debug.jsdi.rhino/src/org/eclipse/e4/languages/javascript/jsdi/rhino/ArrayReferenceImpl.java
index bf4b1f1..bfe9baa 100644
--- a/bundles/org.eclipse.e4.languages.javascript.debug.jsdi.rhino/src/org/eclipse/e4/languages/javascript/jsdi/rhino/ArrayReferenceImpl.java
+++ b/bundles/org.eclipse.e4.languages.javascript.debug.jsdi.rhino/src/org/eclipse/e4/languages/javascript/jsdi/rhino/ArrayReferenceImpl.java
@@ -10,9 +10,15 @@
*******************************************************************************/
package org.eclipse.e4.languages.javascript.jsdi.rhino;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
+import org.eclipse.e4.languages.javascript.debug.connect.JSONConstants;
import org.eclipse.e4.languages.javascript.jsdi.ArrayReference;
+import org.eclipse.e4.languages.javascript.jsdi.Property;
+import org.eclipse.e4.languages.javascript.jsdi.Value;
/**
* Rhino implementation of {@link ArrayReference}
@@ -22,6 +28,16 @@
public class ArrayReferenceImpl extends ObjectReferenceImpl implements ArrayReference {
/**
+ * Empty array
+ */
+ static final Value[] NO_VALUES = new Value[0];
+
+ /**
+ * Raw list of {@link Value}s
+ */
+ private ArrayList values = null;
+
+ /**
* Constructor
*
* @param vm
@@ -30,5 +46,62 @@
*/
public ArrayReferenceImpl(VirtualMachineImpl vm, Map body, StackFrameImpl stackFrameImpl) {
super(vm, body, stackFrameImpl);
+ // get values from body
+ this.values = new ArrayList(properties().size());
+ List props = properties();
+ for (Iterator iter = props.iterator(); iter.hasNext();) {
+ this.values.add(getValue((Property) iter.next()));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.e4.languages.javascript.jsdi.ArrayReference#getValue(int)
+ */
+ public Value getValue(int index) throws IndexOutOfBoundsException {
+ if (index < 0 || index > length()) {
+ throw new IndexOutOfBoundsException();
+ }
+ return (Value) this.values.get(index);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.e4.languages.javascript.jsdi.ArrayReference#getValues()
+ */
+ public List getValues() {
+ return this.values;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.e4.languages.javascript.jsdi.ArrayReference#length()
+ */
+ public int length() {
+ getValues();
+ return this.values.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.e4.languages.javascript.jsdi.rhino.ObjectReferenceImpl#toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Array [").append(this.values.size()).append("]");
+ return buffer.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.e4.languages.javascript.jsdi.rhino.ObjectReferenceImpl#getValueTypeName()
+ */
+ public String getValueTypeName() {
+ return JSONConstants.ARRAY;
}
}
diff --git a/bundles/org.eclipse.e4.languages.javascript.debug.jsdi.rhino/src/org/eclipse/e4/languages/javascript/jsdi/rhino/NumberValueImpl.java b/bundles/org.eclipse.e4.languages.javascript.debug.jsdi.rhino/src/org/eclipse/e4/languages/javascript/jsdi/rhino/NumberValueImpl.java
index f947bdd..8e853ff 100644
--- a/bundles/org.eclipse.e4.languages.javascript.debug.jsdi.rhino/src/org/eclipse/e4/languages/javascript/jsdi/rhino/NumberValueImpl.java
+++ b/bundles/org.eclipse.e4.languages.javascript.debug.jsdi.rhino/src/org/eclipse/e4/languages/javascript/jsdi/rhino/NumberValueImpl.java
@@ -53,8 +53,6 @@
* @see org.eclipse.e4.languages.javascript.jsdi.Value#getValueTypeName()
*/
public String getValueTypeName() {
-
- // always BigDecimal
return JSONConstants.NUMBER;
}
diff --git a/bundles/org.eclipse.e4.languages.javascript.debug.jsdi/src/org/eclipse/e4/languages/javascript/jsdi/ArrayReference.java b/bundles/org.eclipse.e4.languages.javascript.debug.jsdi/src/org/eclipse/e4/languages/javascript/jsdi/ArrayReference.java
index d706c48..b541f6f 100644
--- a/bundles/org.eclipse.e4.languages.javascript.debug.jsdi/src/org/eclipse/e4/languages/javascript/jsdi/ArrayReference.java
+++ b/bundles/org.eclipse.e4.languages.javascript.debug.jsdi/src/org/eclipse/e4/languages/javascript/jsdi/ArrayReference.java
@@ -10,11 +10,37 @@
*******************************************************************************/
package org.eclipse.e4.languages.javascript.jsdi;
+import java.util.List;
+
/**
- * Abstract representation of an object with-respect-to Javascript debugging
+ * Abstract representation of an array with-respect-to Javascript debugging.
*
* @since 1.0
*/
public interface ArrayReference extends ObjectReference {
+ /**
+ * Returns the current number of {@link Value}s in this array
+ *
+ * @return the number of {@link Value}s in the array
+ */
+ public int length();
+
+ /**
+ * Returns the {@link Value} at the given index in this array
+ *
+ * @param index
+ * the index of the {@link Value} to retrieve
+ * @return the {@link Value} at the given index
+ * @throws IndexOutOfBoundsException
+ * if the index is outside the bounds of this array. For example if <code>index < 0</code> or <code>index > {@link #length()}</code>
+ */
+ public Value getValue(int index) throws IndexOutOfBoundsException;
+
+ /**
+ * Returns the complete list of {@link Value}s in the array
+ *
+ * @return the complete list of {@link Value}s in this array or an empty array if this array has no values, never <code>null</code>
+ */
+ public List getValues();
}
diff --git a/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/internal/javascript/debug/launching/JavascriptSourceLookupParticipant.java b/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/internal/javascript/debug/launching/JavascriptSourceLookupParticipant.java
index 685702b..79b1276 100644
--- a/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/internal/javascript/debug/launching/JavascriptSourceLookupParticipant.java
+++ b/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/internal/javascript/debug/launching/JavascriptSourceLookupParticipant.java
@@ -68,12 +68,13 @@
Map props = script.sourceProperties();
IProject project = getProject(props);
if (project != null) {
- String pathname = (String) props.get(JSONConstants.BASE);
+ String pathname = (String) props.get("path");
String name = (String) props.get(JSONConstants.NAME);
if (pathname != null && name != null) {
- IPath path = new Path(pathname);
- path = path.removeFirstSegments(1).removeLastSegments(1).append(name);
- path = path.setDevice(null);
+ IPath path = new Path(pathname).append(name);
+ if (path.getDevice() != null) {
+ path = path.setDevice(null);
+ }
IFile file = project.getFile(path);
if (file != null) {
return new IFile[] { file };
diff --git a/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/javascript/debug/model/JSDIProperty.java b/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/javascript/debug/model/JSDIProperty.java
index 3dd36ec..7045d70 100644
--- a/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/javascript/debug/model/JSDIProperty.java
+++ b/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/javascript/debug/model/JSDIProperty.java
@@ -13,7 +13,6 @@
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IVariable;
-import org.eclipse.e4.languages.javascript.debug.connect.JSONConstants;
import org.eclipse.e4.languages.javascript.jsdi.PropertiesReference;
import org.eclipse.e4.languages.javascript.jsdi.Property;
import org.eclipse.e4.languages.javascript.jsdi.Value;
@@ -29,6 +28,7 @@
private Property property;
private PropertiesReference propertiesReference;
+ private JSDIValue value = null;
/**
* Constructor
@@ -56,7 +56,7 @@
* @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
*/
public String getReferenceTypeName() throws DebugException {
- return JSONConstants.UNKNOWN;
+ return getValue().getReferenceTypeName();
}
/*
@@ -65,8 +65,11 @@
* @see org.eclipse.debug.core.model.IVariable#getValue()
*/
public IValue getValue() throws DebugException {
- Value value = propertiesReference.getValue(property);
- return new JSDIValue(this, value);
+ if (value == null) {
+ Value val = propertiesReference.getValue(property);
+ value = new JSDIValue(this, val);
+ }
+ return value;
}
/*
diff --git a/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/javascript/debug/model/JSDIValue.java b/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/javascript/debug/model/JSDIValue.java
index a8446bf..371b668 100644
--- a/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/javascript/debug/model/JSDIValue.java
+++ b/bundles/org.eclipse.e4.languages.javascript.debug.model/src/org/eclipse/e4/languages/javascript/debug/model/JSDIValue.java
@@ -17,6 +17,9 @@
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IVariable;
+import org.eclipse.e4.languages.javascript.debug.connect.JSONConstants;
+import org.eclipse.e4.languages.javascript.jsdi.ArrayReference;
+import org.eclipse.e4.languages.javascript.jsdi.FunctionReference;
import org.eclipse.e4.languages.javascript.jsdi.PropertiesReference;
import org.eclipse.e4.languages.javascript.jsdi.Property;
import org.eclipse.e4.languages.javascript.jsdi.Value;
@@ -65,6 +68,20 @@
return this.value;
}
+ /**
+ * @return the detail string that is typically shown in the details pane
+ */
+ public String getDetailString() {
+ if (this.value instanceof ArrayReference) {
+ ArrayReference array = (ArrayReference) this.value;
+ return array.getValues().toString();
+ }
+ if (this.value instanceof FunctionReference) {
+
+ }
+ return this.value.toString();
+ }
+
/*
* (non-Javadoc)
*
@@ -89,6 +106,11 @@
* @see org.eclipse.debug.core.model.IValue#getValueString()
*/
public String getValueString() throws DebugException {
+ StringBuffer buffer = new StringBuffer();
+ if (this.value instanceof PropertiesReference) {
+ buffer.append(this.value.toString()).append(JSONConstants.SPACE).append("(id=unknown)");
+ return buffer.toString();
+ }
return this.value.toString();
}
diff --git a/bundles/org.eclipse.e4.languages.javascript.debug.rhino/src/org/eclipse/e4/languages/javascript/debug/rhino/DebugFrameImpl.java b/bundles/org.eclipse.e4.languages.javascript.debug.rhino/src/org/eclipse/e4/languages/javascript/debug/rhino/DebugFrameImpl.java
index 70b81e9..d28c83b 100644
--- a/bundles/org.eclipse.e4.languages.javascript.debug.rhino/src/org/eclipse/e4/languages/javascript/debug/rhino/DebugFrameImpl.java
+++ b/bundles/org.eclipse.e4.languages.javascript.debug.rhino/src/org/eclipse/e4/languages/javascript/debug/rhino/DebugFrameImpl.java
@@ -18,6 +18,7 @@
import org.eclipse.e4.languages.javascript.debug.rhino.ScriptImpl.ScriptRecord;
import org.mozilla.javascript.BaseFunction;
import org.mozilla.javascript.Context;
+import org.mozilla.javascript.NativeArray;
import org.mozilla.javascript.NativeJavaObject;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.ScriptRuntime;
@@ -320,25 +321,24 @@
* @see JSONConstants#OBJECT
*/
private void serializeFunctionOrObject(Scriptable scriptable, Map result) {
- boolean isFunction = scriptable instanceof BaseFunction;
- result.put(JSONConstants.TYPE, isFunction ? JSONConstants.FUNCTION : JSONConstants.OBJECT);
+ if (scriptable instanceof BaseFunction) {
+ result.put(JSONConstants.TYPE, JSONConstants.FUNCTION);
+ result.put(JSONConstants.NAME, ((BaseFunction) scriptable).getFunctionName());
+ } else if (scriptable instanceof NativeArray) {
+ result.put(JSONConstants.TYPE, JSONConstants.ARRAY);
+ } else {
+ result.put(JSONConstants.TYPE, JSONConstants.OBJECT);
+ }
result.put(JSONConstants.CLASS_NAME, scriptable.getClassName());
Object constructorFunction = null;
- if (ScriptableObject.hasProperty(scriptable, JSONConstants.CONSTRUCTOR))
+ if (ScriptableObject.hasProperty(scriptable, JSONConstants.CONSTRUCTOR)) {
constructorFunction = ScriptableObject.getProperty(scriptable, JSONConstants.CONSTRUCTOR);
+ }
result.put(JSONConstants.CONSTRUCTOR_FUNCTION, createRef(constructorFunction));
-
Scriptable protoObject = findProtoObject(scriptable);
result.put(JSONConstants.PROTO_OBJECT, createRef(protoObject));
-
result.put(JSONConstants.PROTOTYPE_OBJECT, createRef(scriptable.getPrototype()));
-
- if (isFunction) {
- String functionName = ((BaseFunction) scriptable).getFunctionName();
- result.put(JSONConstants.NAME, functionName);
- }
-
if (scriptable instanceof NativeJavaObject)
result.put(JSONConstants.PROPERTIES, createJavaObjectProperties((NativeJavaObject) scriptable));
else
diff --git a/bundles/org.eclipse.e4.languages.javascript.debug.ui/src/org/eclipse/e4/languages/internal/javascript/debug/ui/JSDIModelPresentation.java b/bundles/org.eclipse.e4.languages.javascript.debug.ui/src/org/eclipse/e4/languages/internal/javascript/debug/ui/JSDIModelPresentation.java
index db2ecda..6365157 100644
--- a/bundles/org.eclipse.e4.languages.javascript.debug.ui/src/org/eclipse/e4/languages/internal/javascript/debug/ui/JSDIModelPresentation.java
+++ b/bundles/org.eclipse.e4.languages.javascript.debug.ui/src/org/eclipse/e4/languages/internal/javascript/debug/ui/JSDIModelPresentation.java
@@ -27,6 +27,7 @@
import org.eclipse.e4.languages.javascript.debug.model.JSDILineBreakpoint;
import org.eclipse.e4.languages.javascript.debug.model.JSDIFunctionBreakpoint;
import org.eclipse.e4.languages.javascript.debug.model.JSDIProperty;
+import org.eclipse.e4.languages.javascript.debug.model.JSDIValue;
import org.eclipse.e4.languages.javascript.debug.model.JSDIVariable;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.osgi.util.NLS;
@@ -56,12 +57,8 @@
* @see org.eclipse.debug.ui.IDebugModelPresentation#computeDetail(org.eclipse.debug.core.model.IValue, org.eclipse.debug.ui.IValueDetailListener)
*/
public void computeDetail(IValue value, IValueDetailListener listener) {
- try {
- listener.detailComputed(value, value.getValueString());
- }
- catch(DebugException de) {
- //TODO log this?
- }
+ JSDIValue jsdivalue = (JSDIValue) value;
+ listener.detailComputed(value, jsdivalue.getDetailString());
}
/* (non-Javadoc)
diff --git a/bundles/org.eclipse.e4.languages.javascript/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.languages.javascript/META-INF/MANIFEST.MF
index 8527746..3e354b5 100644
--- a/bundles/org.eclipse.e4.languages.javascript/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.languages.javascript/META-INF/MANIFEST.MF
@@ -6,7 +6,8 @@
Bundle-Activator: org.eclipse.e4.internal.languages.javascript.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: OSGi/Minimum-1.2
-Import-Package: org.eclipse.e4.languages.javascript.debug.rhino,
+Import-Package: org.eclipse.core.runtime;version="3.4.0",
+ org.eclipse.e4.languages.javascript.debug.rhino,
org.eclipse.osgi.service.resolver;version="1.3.0",
org.mozilla.javascript,
org.osgi.framework;version="1.3.0",
diff --git a/bundles/org.eclipse.e4.languages.javascript/src/org/eclipse/e4/internal/languages/javascript/JSBundleData.java b/bundles/org.eclipse.e4.languages.javascript/src/org/eclipse/e4/internal/languages/javascript/JSBundleData.java
index e56973f..7659a00 100644
--- a/bundles/org.eclipse.e4.languages.javascript/src/org/eclipse/e4/internal/languages/javascript/JSBundleData.java
+++ b/bundles/org.eclipse.e4.languages.javascript/src/org/eclipse/e4/internal/languages/javascript/JSBundleData.java
@@ -11,17 +11,24 @@
package org.eclipse.e4.internal.languages.javascript;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.URIUtil;
+
public class JSBundleData {
private final int bundleId;
private final String location;
private final Map headers;
private final ClassLoader contextClassLoader;
private URL base;
+ private String relativepath = null;
public JSBundleData(int bundleId, String location, Map headers, ClassLoader contextClassLoader) {
this.bundleId = bundleId;
@@ -49,6 +56,28 @@
return headers;
}
+ /**
+ * Returns the relative path for this bundle data slicing off the
+ * host information and the trailing <code>bundle.json</code> bits
+ * @return the relative path for this bundle data
+ */
+ public String getRelativePath() {
+ if(relativepath == null) {
+ if(location == null) {
+ return location;
+ }
+ try {
+ URI uri = URIUtil.fromString(location);
+ IPath path = new Path(uri.getPath()).removeLastSegments(1);
+ relativepath = path.toString();
+ }
+ catch(URISyntaxException urise) {
+ return location;
+ }
+ }
+ return relativepath;
+ }
+
public URL getEntry(String path) {
try {
initBase();
diff --git a/bundles/org.eclipse.e4.languages.javascript/src/org/eclipse/e4/internal/languages/javascript/JSBundleImpl.java b/bundles/org.eclipse.e4.languages.javascript/src/org/eclipse/e4/internal/languages/javascript/JSBundleImpl.java
index a9d40a9..89c7cc2 100644
--- a/bundles/org.eclipse.e4.languages.javascript/src/org/eclipse/e4/internal/languages/javascript/JSBundleImpl.java
+++ b/bundles/org.eclipse.e4.languages.javascript/src/org/eclipse/e4/internal/languages/javascript/JSBundleImpl.java
@@ -300,6 +300,7 @@
Map scriptProperties = new HashMap();
scriptProperties.put("name", token);
scriptProperties.put("base", bundleData.getLocation());
+ scriptProperties.put("path", bundleData.getRelativePath());
scriptProperties.put(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
scriptProperties.put(Constants.BUNDLE_VERSION, version.toString());
if (bundleData.getContextClassLoader() instanceof RhinoClassLoader) {
diff --git a/examples/sample.js.debug/META-INF/MANIFEST.MF b/examples/sample.js.debug/META-INF/MANIFEST.MF
index 67d0683..404575a 100644
--- a/examples/sample.js.debug/META-INF/MANIFEST.MF
+++ b/examples/sample.js.debug/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Debug Sample
-Bundle-SymbolicName: sample.js.debug
+Bundle-SymbolicName: sample.js.debug;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: sample.js.debug.Activator
Bundle-RequiredExecutionEnvironment: J2SE-1.4
@@ -10,3 +10,4 @@
org.mozilla.javascript,
org.osgi.framework;version="1.3.0",
org.osgi.util.tracker;version="1.4.2"
+Bundle-ActivationPolicy: lazy
diff --git a/examples/sample.js.debugdisplay/META-INF/MANIFEST.MF b/examples/sample.js.debugdisplay/META-INF/MANIFEST.MF
index 3882a7f..847a710 100644
--- a/examples/sample.js.debugdisplay/META-INF/MANIFEST.MF
+++ b/examples/sample.js.debugdisplay/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Debug Sample
-Bundle-SymbolicName: sample.js.debugdisplay
+Bundle-SymbolicName: sample.js.debugdisplay;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: sample.js.debugdisplay.Activator
Bundle-RequiredExecutionEnvironment: J2SE-1.4
@@ -10,3 +10,4 @@
org.mozilla.javascript,
org.osgi.framework;version="1.3.0",
org.osgi.util.tracker;version="1.4.2"
+Bundle-ActivationPolicy: lazy
diff --git a/examples/sample.js.debugdisplay/scripts/script.js b/examples/sample.js.debugdisplay/scripts/script.js
index c26375c..508f290 100644
--- a/examples/sample.js.debugdisplay/scripts/script.js
+++ b/examples/sample.js.debugdisplay/scripts/script.js
@@ -8,5 +8,5 @@
var anObject = {x: 5, y: 25};
var aPrintableObject = {x: 5, y: 25};
var aMap = {};
-var anArray = [];
+var anArray = [4, 5, 79];
debugger;
diff --git a/examples/sample.js.fib/META-INF/MANIFEST.MF b/examples/sample.js.fib/META-INF/MANIFEST.MF
index 499b5cc..ba02b7f 100644
--- a/examples/sample.js.fib/META-INF/MANIFEST.MF
+++ b/examples/sample.js.fib/META-INF/MANIFEST.MF
@@ -5,4 +5,5 @@
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: J2SE-1.4
JavaScript-Bundle: scripts/bundle.json
+Bundle-ActivationPolicy: lazy
diff --git a/examples/sample.js.servlet/META-INF/MANIFEST.MF b/examples/sample.js.servlet/META-INF/MANIFEST.MF
index 81fead2..4ed1df8 100644
--- a/examples/sample.js.servlet/META-INF/MANIFEST.MF
+++ b/examples/sample.js.servlet/META-INF/MANIFEST.MF
@@ -9,4 +9,5 @@
Import-Package: javax.servlet;version="2.5.0",
javax.servlet.http;version="2.5.0"
JavaScript-Bundle: scripts/bundle.json
+Bundle-ActivationPolicy: lazy