Debian Codegraph @

rhino/testsrc/tests/lc3/JSObject/ToDouble-003-n.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 = 'ToDouble-003-n.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 = "JavaScript Object to java.lang.String";
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 // 3.3.6.4 Other JavaScript Objects
40 // Passing a JavaScript object to a java method that that expects a double
41 // should:
42 // 1. Apply the ToPrimitive operator (ECMA 9.3) to the JavaScript object
43 // with hint Number
44 // 2. Convert Result(1) to Java numeric type using the rules in 3.3.3.
45
46 DESCRIPTION = "dt.setDouble(null)";
47 EXPECTED = "error";
48
49 a[i++] = new TestObject(
50 "dt.setDouble(null)",
51 "dt.PUB_DOUBLE",
52 "dt.getDouble()",
53 "typeof dt.getDouble()",
54 "error",
55 "error");
56
57 for ( i = 0; i < a.length; i++ ) {
58 new TestCase(
59 a[i].description +"; "+ a[i].javaFieldName,
60 a[i].jsValue,
61 a[i].javaFieldValue );
62
63 new TestCase(
64 a[i].description +"; " + a[i].javaMethodName,
65 a[i].jsValue,
66 a[i].javaMethodValue );
67
68 new TestCase(
69 a[i].javaTypeName,
70 a[i].jsType,
71 a[i].javaTypeValue );
72 }
73
74 test();
75
76 function MyObject( stringValue ) {
77 this.stringValue = String(stringValue);
78 this.toString = new Function( "return this.stringValue" );
79 }
80
81 function MyOtherObject( value ) {
82 this.toString = null;
83 this.value = value;
84 this.valueOf = new Function( "return this.value" );
85 }
86
87 function AnotherObject( value ) {
88 this.toString = new Function( "return new Number(666)" );
89 this.value = value;
90 this.valueOf = new Function( "return this.value" );
91 }
92
93 function TestObject( description, javaField, javaMethod, javaType,
94 jsValue, jsType )
95 {
96 eval (description );
97
98 this.description = description;
99 this.javaFieldName = javaField;
100 this.javaFieldValue = eval( javaField );
101 this.javaMethodName = javaMethod;
102 this.javaMethodValue = eval( javaMethod );
103 this.javaTypeName = javaType,
104 this.javaTypeValue = eval( javaType );
105
106 this.jsValue = jsValue;
107 this.jsType = jsType;
108 }