Debian Codegraph @

rhino/testsrc/tests/lc3/JSNumber/ToInt-005-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 = 'ToInt-005-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 = "number conversion 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 // passing a JS number to a method that expects a int:
40 // round JS number to integral value using round-to-negative-infinity mode
41 // numbers with a magnitude too large to be represented in the target integral
42 // type result in a runtime error.
43 // Nan converts to 0.
44
45 // Special cases: 0, -0, Infinity, -Infinity, and NaN
46
47 DESCRIPTION = "dt.setInteger( NaN )";
48 EXPECTED = "error";
49
50 a[i++] = new TestObject(
51 "dt.setInteger( NaN )",
52 "dt.PUB_INT",
53 "dt.getInteger()",
54 "typeof dt.getInteger()",
55 "error",
56 "error" );
57
58 for ( i = 0; i < a.length; i++ ) {
59 new TestCase(
60 a[i].description +"; "+ a[i].javaFieldName,
61 a[i].jsValue,
62 a[i].javaFieldValue );
63
64 new TestCase(
65 a[i].description +"; " + a[i].javaMethodName,
66 a[i].jsValue,
67 a[i].javaMethodValue );
68
69 new TestCase(
70 a[i].javaTypeName,
71 a[i].jsType,
72 a[i].javaTypeValue );
73 }
74
75 test();
76
77 function TestObject( description, javaField, javaMethod, javaType,
78 jsValue, jsType )
79 {
80 eval (description );
81
82 this.description = description;
83 this.javaFieldName = javaField;
84 this.javaFieldValue = eval( javaField );
85 this.javaMethodName = javaMethod;
86 this.javaMethodValue = eval( javaMethod );
87 this.javaTypeName = javaType,
88 this.javaTypeValue = eval( javaType );
89
90 this.jsValue = jsValue;
91 this.jsType = jsType;
92 }