Debian Codegraph @

rhino/testsrc/tests/lc3/JSUndefined/undefined-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 = 'undefined-001.js';
10
11 /**
12 * JavaScript to Java type conversion.
13 *
14 * This test passes the JavaScript "undefined" value 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 = "undefined conversion";
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 // passing undefined to a java method that expects an object should convert
40 // undefined to the java.lang.String whose value is "undefined"
41
42 a[i++] = new TestObject(
43 "dt.setObject( undefined )",
44 "dt.PUB_OBJECT +''",
45 "dt.getObject() + ''",
46 "dt.getObject().getClass()",
47 "undefined",
48 java.lang.Class.forName( "java.lang.String" ) );
49
50 // passing undefined to a java method that expects a string should convert
51 // undefined to the java.lang.String whose value is "undefined"
52
53 a[i++] = new TestObject(
54 "dt.setStringObject( undefined )",
55 "dt.PUB_STRING +''",
56 "dt.getStringObject() + ''",
57 "dt.getStringObject().getClass()",
58 "undefined",
59 java.lang.Class.forName( "java.lang.String" ) );
60
61 for ( i = 0; i < a.length; i++ ) {
62 new TestCase(
63 a[i].description +"; "+ a[i].javaFieldName,
64 a[i].jsValue,
65 a[i].javaFieldValue );
66
67 new TestCase(
68 a[i].description +"; " + a[i].javaMethodName,
69 a[i].jsValue,
70 a[i].javaMethodValue );
71
72 new TestCase(
73 a[i].javaTypeName,
74 a[i].jsType,
75 a[i].javaTypeValue );
76 }
77
78 test();
79
80 function TestObject( description, javaField, javaMethod, javaType,
81 jsValue, jsType )
82 {
83 eval (description );
84
85 this.description = description;
86 this.javaFieldName = javaField;
87 this.javaFieldValue = eval( javaField );
88 this.javaMethodName = javaMethod;
89 this.javaMethodValue = eval( javaMethod );
90 this.javaTypeName = javaType,
91 this.javaTypeValue = eval( javaType );
92
93 this.jsValue = jsValue;
94 this.jsType = jsType;
95 }