Debian Codegraph @

rhino/testsrc/tests/lc3/JavaObject/JavaObjectToShort-002-n.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = 'JavaObjectToShort-002-n.js';
7
8 /* -*- Mode: java; tab-width: 8 -*-
9 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
10 * All Rights Reserved.
11 */
12 /**
13 * JavaScript to Java type conversion.
14 *
15 * This test passes JavaScript number values to several Java methods
16 * that expect arguments of various types, and verifies that the value is
17 * converted to the correct value and type.
18 *
19 * This tests instance methods, and not static methods.
20 *
21 * Running these tests successfully requires you to have
22 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
23 *
24 * Specification: Method Overloading Proposal for Liveconnect 3.0
25 *
26 * @author: [email protected]
27 *
28 */
29 var SECTION = "JavaObject to short";
30 var VERSION = "1_4";
31 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
32 SECTION;
33 startTest();
34
35 var dt = new DT();
36
37 var a = new Array();
38 var i = 0;
39
40 // 1. If the object does not have a doubleValue() method, a runtime error
41 // occurs.
42 // 2. Call the object's doubleValue() method
43 // 3. If result(2) is NaN, a runtime error occurs
44 // 3. Convert Result(2) to Java numeric type. Round JS number to integral
45 // value using round-to-negative-infinity mode.
46 // Numbers with a magnitude too large to be represented in the target
47 // integral type should result in a runtime error.
48
49 DESCRIPTION = "dt.PUB_DOUBLE_REPRESENTATION = NaN;"+
50 "dt.setShort( dt )";
51 EXPECTED = "error";
52
53 a[i++] = new TestObject (
54 "dt.PUB_DOUBLE_REPRESENTATION = NaN;"+
55 "dt.setShort( dt )",
56 "dt.PUB_SHORT",
57 "dt.getShort()",
58 "typeof dt.getShort()",
59 "error",
60 "number" );
61
62 for ( i = 0; i < a.length; i++ ) {
63 new TestCase(
64 a[i].description +"; "+ a[i].javaFieldName,
65 a[i].jsValue,
66 a[i].javaFieldValue );
67
68 new TestCase(
69 a[i].description +"; " + a[i].javaMethodName,
70 a[i].jsValue,
71 a[i].javaMethodValue );
72
73 new TestCase(
74 a[i].javaTypeName,
75 a[i].jsType,
76 a[i].javaTypeValue );
77
78 }
79
80 test();
81
82 function TestObject( description, javaField, javaMethod, javaType,
83 jsValue, jsType )
84 {
85 eval (description );
86
87 this.description = description;
88 this.javaFieldName = javaField;
89 this.javaFieldValue = eval( javaField );
90 this.javaMethodName = javaMethod;
91 this.javaMethodValue = eval( javaMethod );
92 this.javaTypeName = javaType,
93 this.javaTypeValue = typeof this.javaFieldValue;
94
95 this.jsValue = jsValue;
96 this.jsType = jsType;
97 }