Debian Codegraph @

rhino/testsrc/tests/lc3/JavaObject/JavaObjectToByte-007-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 = 'JavaObjectToByte-007-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 byte";
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 var newValue = Math.random();
50
51 DESCRIPTION = "dt.PUB_DOUBLE_REPRESENTATION = Infinity;"+
52 "dt.setByte( dt )";
53 EXPECTED = "error";
54
55 a[i++] = new TestObject (
56 "dt.PUB_DOUBLE_REPRESENTATION = Infinity;"+
57 "dt.setByte( dt )",
58 "dt.PUB_BYTE",
59 "dt.getByte()",
60 "typeof dt.getByte()",
61 "error",
62 "number" );
63
64 for ( i = 0; i < a.length; i++ ) {
65 new TestCase(
66 a[i].description +"; "+ a[i].javaFieldName,
67 a[i].jsValue,
68 a[i].javaFieldValue );
69
70 new TestCase(
71 a[i].description +"; " + a[i].javaMethodName,
72 a[i].jsValue,
73 a[i].javaMethodValue );
74
75 new TestCase(
76 a[i].javaTypeName,
77 a[i].jsType,
78 a[i].javaTypeValue );
79
80 }
81
82 test();
83
84 function TestObject( description, javaField, javaMethod, javaType,
85 jsValue, jsType )
86 {
87 eval (description );
88
89 this.description = description;
90 this.javaFieldName = javaField;
91 this.javaFieldValue = eval( javaField );
92 this.javaMethodName = javaMethod;
93 this.javaMethodValue = eval( javaMethod );
94 this.javaTypeName = javaType,
95 this.javaTypeValue = typeof this.javaFieldValue;
96
97 this.jsValue = jsValue;
98 this.jsType = jsType;
99 }