1 /* -*- Mode: java; tab-width: 8 -*-
2 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
5 /* ***** BEGIN LICENSE BLOCK *****
6 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
8 * The contents of this file are subject to the Mozilla Public License Version
9 * 1.1 (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS" basis,
14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15 * for the specific language governing rights and limitations under the
18 * The Original Code is Mozilla Communicator client code, released
21 * The Initial Developer of the Original Code is
22 * Netscape Communications Corporation.
23 * Portions created by the Initial Developer are Copyright (C) 1998
24 * the Initial Developer. All Rights Reserved.
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 gTestfile = 'ToJSObject-001.js';
45 * JavaScript to Java type conversion.
47 * This test passes JavaScript number values to several Java methods
48 * that expect arguments of various types, and verifies that the value is
49 * converted to the correct value and type.
51 * This tests instance methods, and not static methods.
53 * Running these tests successfully requires you to have
54 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
56 * Specification: Method Overloading Proposal for Liveconnect 3.0
58 * @author: christine@netscape.com
61 var SECTION = "JavaScript Object to java.lang.String";
63 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
67 var jsoc = new Packages.com.netscape.javascript.qa.liveconnect.JSObjectConversion();
72 // 3.3.6.4 Other JavaScript Objects
73 // Passing a JavaScript object to a java method that that expects a JSObject
74 // should wrap the JS object in a new instance of netscape.javascript.JSObject.
75 // HOwever, since we are running the test from JavaScript, getting the value
76 // back should return the unwrapped object.
78 var string = new String("JavaScript String Value");
80 a[i++] = new TestObject(
81 "jsoc.setJSObject(string)",
84 "jsoc.getJSObject().constructor",
88 var myobject = new MyObject( string );
90 a[i++] = new TestObject(
91 "jsoc.setJSObject( myobject )",
94 "jsoc.getJSObject().constructor",
98 var bool = new Boolean(true);
100 a[i++] = new TestObject(
101 "jsoc.setJSObject( bool )",
103 "jsoc.getJSObject()",
104 "jsoc.getJSObject().constructor",
108 bool = new Boolean(false);
110 a[i++] = new TestObject(
111 "jsoc.setJSObject( bool )",
113 "jsoc.getJSObject()",
114 "jsoc.getJSObject().constructor",
118 var object = new Object();
120 a[i++] = new TestObject(
121 "jsoc.setJSObject( object)",
123 "jsoc.getJSObject()",
124 "jsoc.getJSObject().constructor",
128 var number = new Number(0);
130 a[i++] = new TestObject(
131 "jsoc.setJSObject( number )",
133 "jsoc.getJSObject()",
134 "jsoc.getJSObject().constructor",
138 nan = new Number(NaN);
140 a[i++] = new TestObject(
141 "jsoc.setJSObject( nan )",
143 "jsoc.getJSObject()",
144 "jsoc.getJSObject().constructor",
148 infinity = new Number(Infinity);
150 a[i++] = new TestObject(
151 "jsoc.setJSObject( infinity )",
153 "jsoc.getJSObject()",
154 "jsoc.getJSObject().constructor",
158 var neg_infinity = new Number(-Infinity);
160 a[i++] = new TestObject(
161 "jsoc.setJSObject( neg_infinity)",
163 "jsoc.getJSObject()",
164 "jsoc.getJSObject().constructor",
168 var array = new Array(1,2,3)
170 a[i++] = new TestObject(
171 "jsoc.setJSObject(array)",
173 "jsoc.getJSObject()",
174 "jsoc.getJSObject().constructor",
179 a[i++] = new TestObject(
180 "jsoc.setJSObject( MyObject )",
182 "jsoc.getJSObject()",
183 "jsoc.getJSObject().constructor",
189 a[i++] = new TestObject(
190 "jsoc.setJSObject( THIS )",
192 "jsoc.getJSObject()",
193 "jsoc.getJSObject().constructor",
197 a[i++] = new TestObject(
198 "jsoc.setJSObject( Math )",
200 "jsoc.getJSObject()",
201 "jsoc.getJSObject().constructor",
205 a[i++] = new TestObject(
206 "jsoc.setJSObject( Function )",
208 "jsoc.getJSObject()",
209 "jsoc.getJSObject().constructor",
213 for ( i = 0; i < a.length; i++ ) {
215 a[i].description +"; "+ a[i].javaFieldName,
217 a[i].javaFieldValue );
220 a[i].description +"; " + a[i].javaMethodName,
222 a[i].javaMethodValue );
227 a[i].javaTypeValue );
232 function MyObject( stringValue ) {
233 this.stringValue = String(stringValue);
234 this.toString = new Function( "return this.stringValue" );
238 function TestObject( description, javaField, javaMethod, javaType,
244 this.description = description;
245 this.javaFieldName = javaField;
246 this.javaFieldValue = eval( javaField );
247 this.javaMethodName = javaMethod;
248 this.javaMethodValue = eval( javaMethod );
249 this.javaTypeName = javaType,
250 this.javaTypeValue = eval( javaType );
252 this.jsValue = jsValue;
253 this.jsType = jsType;