Debian Codegraph @

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