1515package netscape .javascript ;
1616
1717import java .applet .Applet ;
18+ import java .applet .AppletContext ;
1819
1920/**
20- * Stub for the JSException. This is part of the Applet
21- * LiveConnect simulation.
22- *
23- * TODO: we have to evaluate if it is possible to use plugin.jar from jdk
21+ *
22+ * BH: Adapted for SwingJS:
23+ *
24+ * getWindow(applet) returns a JSObject with this.obj = applet.getAppletContext().html5Applet._window
25+ *
26+ * Object returns are one of [null, Boolean, Double, String, JSObject (from "object" type)]
27+ *
28+ *
29+ * Stub for the JSException. This is part of the Applet LiveConnect simulation.
2430 *
2531 * @version $Revision: 9837 $
2632 * @author Ronald Brill
2733 */
2834public class JSObject {
2935
36+ @ SuppressWarnings ("unused" )
37+ private Object obj ; // html5Applet._window, for instance;
38+
39+ public JSObject () {
40+ }
41+
3042 /**
31- * Empty stub.
32- *
3343 * @param jsFuncName
3444 * the paramString
3545 * @param params
@@ -38,15 +48,19 @@ public class JSObject {
3848 * @throws JSException
3949 * in case or error
4050 */
41- public Object call (final String jsFuncName , final Object [] params ) throws JSException {
42-
51+ public Object call (String jsFuncName , Object [] params ) throws JSException {
4352 Object ret = null ;
4453 try {
54+ if (params == null )
55+ params = new Object [0 ];
56+ for (int i = params .length ; --i >= 0 ;) {
57+ params [i ] = unfixObject (params [i ]);
58+ }
59+
4560 /**
4661 * @j2sNative
4762 *
48- *
49- * ret = self[jsFuncName].apply(null, params);
63+ * ret = this.obj[jsFuncName].apply(this.obj, params);
5064 *
5165 */
5266 } catch (Throwable t ) {
@@ -55,9 +69,35 @@ public Object call(final String jsFuncName, final Object[] params) throws JSExce
5569 return fixObject (ret );
5670 }
5771
72+ private Object unfixObject (Object o ) {
73+ Object ret = o ;
74+ if (o == null ) {
75+ return null ;
76+ } else if (o instanceof Number ) {
77+ /**
78+ * @j2sNative
79+ *
80+ * return o.doubleValue();
81+ */
82+ } else if (o instanceof Boolean ) {
83+ /**
84+ * @j2sNative
85+ *
86+ * return o.BooleanValue();
87+ */
88+ } else if (o instanceof JSObject ) {
89+ return ((JSObject ) o ).obj ;
90+ }
91+ return ret ;
92+
93+ }
94+
5895 @ SuppressWarnings ("null" )
5996 private Object fixObject (Object ret ) {
60- String type = null ;
97+ if (ret == null )
98+ return null ;
99+
100+ String type = null ;
61101 /**
62102 * @j2sNative
63103 *
@@ -70,12 +110,13 @@ private Object fixObject(Object ret) {
70110 case "boolean" :
71111 return Boolean .valueOf ("" + ret );
72112 default :
73- return ret ;
113+ JSObject jsobject = new JSObject ();
114+ jsobject .obj = ret ;
115+ return jsobject ;
74116 }
75117 }
76118
77119 /**
78- * Empty stub.
79120 *
80121 * @param paramString the paramString
81122 * @return result Object
@@ -88,7 +129,7 @@ public Object eval(String params) throws JSException {
88129 * @j2sNative
89130 *
90131 *
91- * ret = eval(params);
132+ * ret = this.obj. eval(params);
92133 *
93134 */
94135 } catch (Throwable t ) {
@@ -110,7 +151,7 @@ public Object getMember(String name) throws JSException {
110151 * @j2sNative
111152 *
112153 *
113- * ret = self [name];
154+ * ret = this.obj [name];
114155 *
115156 */
116157 } catch (Throwable t ) {
@@ -124,13 +165,13 @@ public Object getMember(String name) throws JSException {
124165 * @param value the paramObject
125166 * @throws JSException in case or error
126167 */
127- public void setMember (final String name , final Object value ) throws JSException {
168+ public void setMember (String name , Object value ) throws JSException {
128169 try {
129170 /**
130171 * @j2sNative
131172 *
132173 *
133- * self [name] = value;
174+ * this.obj [name] = value;
134175 *
135176 */
136177 } catch (Throwable t ) {
@@ -143,13 +184,13 @@ public void setMember(final String name, final Object value) throws JSException
143184 * @param paramString the paramString
144185 * @throws JSException in case or error
145186 */
146- public void removeMember (final String name ) throws JSException {
187+ public void removeMember (String name ) throws JSException {
147188 try {
148189 /**
149190 * @j2sNative
150191 *
151192 *
152- * delete self [name];
193+ * delete this.obj [name];
153194 *
154195 */
155196 } catch (Throwable t ) {
@@ -158,43 +199,57 @@ public void removeMember(final String name) throws JSException {
158199 }
159200
160201 /**
161- * Empty stub.
162202 *
163- * @param paramInt the paramInt
203+ * @param index
164204 * @return result Object
165205 * @throws JSException in case or error
166206 */
167- public Object getSlot (final int paramInt ) throws JSException {
168- throw new RuntimeException ("Not yet implemented (netscape.javascript.JSObject.getSlot(int))." );
207+ public Object getSlot (int index ) throws JSException {
208+ Object ret = null ;
209+ try {
210+ /**
211+ * @j2sNative
212+ *
213+ * return this.obj[index];
214+ *
215+ */
216+ return fixObject (ret );
217+ } catch (Throwable t ) {
218+ throw new JSException ("" + t + " getSlot" );
219+ }
169220 }
170221
171222 /**
172- * Empty stub.
173223 *
174- * @param paramInt the paramInt
175- * @param paramObject the paramObject
224+ * @param index the paramInt
225+ * @param val the paramObject
176226 * @throws JSException in case or error
177227 */
178- public void setSlot (final int paramInt , final Object paramObject ) throws JSException {
179- throw new RuntimeException ("Not yet implemented (netscape.javascript.JSObject.setSlot(int, Object))." );
228+ public void setSlot (int index , Object val ) throws JSException {
229+ try {
230+ /**
231+ * @j2sNative
232+ *
233+ * this.obj[index] = val;
234+ *
235+ */
236+ } catch (Throwable t ) {
237+ throw new JSException ("" + t + " setSlot" );
238+ }
180239 }
181240
182241 /**
183242 * Empty stub.
184243 *
185- * @param paramApplet the paramApplet
244+ * @param applet the paramApplet
186245 * @return result Object
187246 * @throws JSException in case or error
188247 */
189- public static JSObject getWindow (Applet paramApplet ) throws JSException {
190- /**
191- * @j2sNative
192- *
193- * return self;
194- *
195- */
196- {
197- return null ;
198- }
248+ public static JSObject getWindow (Applet applet ) throws JSException {
249+ JSObject jsobject = new JSObject ();
250+ @ SuppressWarnings ("unused" )
251+ AppletContext context = applet .getAppletContext ();
252+ jsobject .obj = /** @j2sNative context.html5Applet._window || */ null ;
253+ return jsobject ;
199254 }
200255}
0 commit comments