Debian Codegraph @

rhino/testsrc/tests/lc3/JavaClass/ToObject-001.js

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8 -*-
2 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
3 * All Rights Reserved.
4 */
5 /* This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8
9 gTestfile = 'ToObject-001.js';
10
11 /**
12 * JavaScript to Java type conversion.
13 *
14 * This test passes JavaScript number values to several Java methods
15 * that expect arguments of various types, and verifies that the value is
16 * converted to the correct value and type.
17 *
18 * This tests instance methods, and not static methods.
19 *
20 * Running these tests successfully requires you to have
21 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
22 *
23 * Specification: Method Overloading Proposal for Liveconnect 3.0
24 *
25 * @author: [email protected]
26 *
27 */
28 var SECTION = "JavaClass to java.lang.Class";
29 var VERSION = "1_4";
30 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
31 SECTION;
32 startTest();
33
34 var dt = new DT();
35
36 var a = new Array();
37 var i = 0;
38
39 // Pass a JavaClass to a method that expects an Object should wrap
40 // the object in a new instance of JSObject.
41
42 a[i++] = new TestObject (
43 "var newClass = java.lang.Class.forName(\"java.lang.Integer\"); "+
44 "dt.setObject( newClass )",
45 "dt.PUB_OBJECT",
46 "dt.getObject()",
47 "dt.getObject()",
48 java.lang.Class.forName("java.lang.Integer"),
49 "object" );
50
51 for ( i = 0; i < a.length; i++ ) {
52 new TestCase(
53 a[i].description +"; "+ a[i].javaFieldName,
54 a[i].jsValue,
55 a[i].javaFieldValue );
56
57 new TestCase(
58 a[i].description +"; " + a[i].javaMethodName,
59 a[i].jsValue,
60 a[i].javaMethodValue );
61
62 new TestCase(
63 a[i].javaTypeName,
64 a[i].jsType,
65 a[i].javaTypeValue );
66
67 }
68
69 test();
70
71 function TestObject( description, javaField, javaMethod, javaType,
72 jsValue, jsType )
73 {
74 eval (description );
75
76 this.description = description;
77 this.javaFieldName = javaField;
78 this.javaFieldValue = eval( javaField );
79 this.javaMethodName = javaMethod;
80 this.javaMethodValue = eval( javaMethod );
81 this.javaTypeName = javaType,
82 this.javaTypeValue = typeof this.javaFieldValue;
83
84 this.jsValue = jsValue;
85 this.jsType = jsType;
86 }