Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.java.core/SwingJS-site.zip
Binary file not shown.
133 changes: 94 additions & 39 deletions sources/net.sf.j2s.java.core/src/netscape/javascript/JSObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,31 @@
package netscape.javascript;

import java.applet.Applet;
import java.applet.AppletContext;

/**
* Stub for the JSException. This is part of the Applet
* LiveConnect simulation.
*
* TODO: we have to evaluate if it is possible to use plugin.jar from jdk
*
* BH: Adapted for SwingJS:
*
* getWindow(applet) returns a JSObject with this.obj = applet.getAppletContext().html5Applet._window
*
* Object returns are one of [null, Boolean, Double, String, JSObject (from "object" type)]
*
*
* Stub for the JSException. This is part of the Applet LiveConnect simulation.
*
* @version $Revision: 9837 $
* @author Ronald Brill
*/
public class JSObject {

@SuppressWarnings("unused")
private Object obj; // html5Applet._window, for instance;

public JSObject() {
}

/**
* Empty stub.
*
* @param jsFuncName
* the paramString
* @param params
Expand All @@ -38,15 +48,19 @@ public class JSObject {
* @throws JSException
* in case or error
*/
public Object call(final String jsFuncName, final Object[] params) throws JSException {

public Object call(String jsFuncName, Object[] params) throws JSException {
Object ret = null;
try {
if (params == null)
params = new Object[0];
for (int i = params.length; --i >= 0;) {
params[i] = unfixObject(params[i]);
}

/**
* @j2sNative
*
*
* ret = self[jsFuncName].apply(null, params);
* ret = this.obj[jsFuncName].apply(this.obj, params);
*
*/
} catch (Throwable t) {
Expand All @@ -55,9 +69,35 @@ public Object call(final String jsFuncName, final Object[] params) throws JSExce
return fixObject(ret);
}

private Object unfixObject(Object o) {
Object ret = o;
if (o == null) {
return null;
} else if (o instanceof Number) {
/**
* @j2sNative
*
* return o.doubleValue();
*/
} else if (o instanceof Boolean) {
/**
* @j2sNative
*
* return o.BooleanValue();
*/
} else if (o instanceof JSObject) {
return ((JSObject) o).obj;
}
return ret;

}

@SuppressWarnings("null")
private Object fixObject(Object ret) {
String type = null;
if (ret == null)
return null;

String type = null;
/**
* @j2sNative
*
Expand All @@ -70,12 +110,13 @@ private Object fixObject(Object ret) {
case "boolean":
return Boolean.valueOf("" + ret);
default:
return ret;
JSObject jsobject = new JSObject();
jsobject.obj = ret;
return jsobject;
}
}

/**
* Empty stub.
*
* @param paramString the paramString
* @return result Object
Expand All @@ -88,7 +129,7 @@ public Object eval(String params) throws JSException {
* @j2sNative
*
*
* ret = eval(params);
* ret = this.obj.eval(params);
*
*/
} catch (Throwable t) {
Expand All @@ -110,7 +151,7 @@ public Object getMember(String name) throws JSException {
* @j2sNative
*
*
* ret = self[name];
* ret = this.obj[name];
*
*/
} catch (Throwable t) {
Expand All @@ -124,13 +165,13 @@ public Object getMember(String name) throws JSException {
* @param value the paramObject
* @throws JSException in case or error
*/
public void setMember(final String name, final Object value) throws JSException {
public void setMember(String name, Object value) throws JSException {
try {
/**
* @j2sNative
*
*
* self[name] = value;
* this.obj[name] = value;
*
*/
} catch (Throwable t) {
Expand All @@ -143,13 +184,13 @@ public void setMember(final String name, final Object value) throws JSException
* @param paramString the paramString
* @throws JSException in case or error
*/
public void removeMember(final String name) throws JSException {
public void removeMember(String name) throws JSException {
try {
/**
* @j2sNative
*
*
* delete self[name];
* delete this.obj[name];
*
*/
} catch (Throwable t) {
Expand All @@ -158,43 +199,57 @@ public void removeMember(final String name) throws JSException {
}

/**
* Empty stub.
*
* @param paramInt the paramInt
* @param index
* @return result Object
* @throws JSException in case or error
*/
public Object getSlot(final int paramInt) throws JSException {
throw new RuntimeException("Not yet implemented (netscape.javascript.JSObject.getSlot(int)).");
public Object getSlot(int index) throws JSException {
Object ret = null;
try {
/**
* @j2sNative
*
* return this.obj[index];
*
*/
return fixObject(ret);
} catch (Throwable t) {
throw new JSException("" + t + " getSlot");
}
}

/**
* Empty stub.
*
* @param paramInt the paramInt
* @param paramObject the paramObject
* @param index the paramInt
* @param val the paramObject
* @throws JSException in case or error
*/
public void setSlot(final int paramInt, final Object paramObject) throws JSException {
throw new RuntimeException("Not yet implemented (netscape.javascript.JSObject.setSlot(int, Object)).");
public void setSlot(int index, Object val) throws JSException {
try {
/**
* @j2sNative
*
* this.obj[index] = val;
*
*/
} catch (Throwable t) {
throw new JSException("" + t + " setSlot");
}
}

/**
* Empty stub.
*
* @param paramApplet the paramApplet
* @param applet the paramApplet
* @return result Object
* @throws JSException in case or error
*/
public static JSObject getWindow(Applet paramApplet) throws JSException {
/**
* @j2sNative
*
* return self;
*
*/
{
return null;
}
public static JSObject getWindow(Applet applet) throws JSException {
JSObject jsobject = new JSObject();
@SuppressWarnings("unused")
AppletContext context = applet.getAppletContext();
jsobject.obj = /** @j2sNative context.html5Applet._window || */ null;
return jsobject;
}
}