Debian Codegraph @

rhino/testsrc/tests/lc3/ConvertJSObject/ToInt-002.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 = 'ToInt-002.js';
7
8 /**
9 * Preferred Argument Conversion.
10 *
11 * Passing a JavaScript boolean to a Java method should prefer to call
12 * a Java method of the same name that expects a Java boolean.
13 *
14 */
15 var SECTION = "Preferred argument conversion: JavaScript Object to int";
16 var VERSION = "1_4";
17 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
18 SECTION;
19 startTest();
20
21 var TEST_CLASS = new Packages.com.netscape.javascript.qa.lc3.jsobject.JSObject_007;
22
23 function MyFunction() {
24 return "hello";
25 }
26 MyFunction.valueOf = new Function( "return 999" );
27
28 function MyOtherFunction() {
29 return "goodbye";
30 }
31 MyOtherFunction.valueOf = null;
32 MyOtherFunction.toString = new Function( "return 999" );
33
34 function MyObject(value) {
35 this.value = value;
36 this.valueOf = new Function("return this.value");
37 }
38
39 function MyOtherObject(stringValue) {
40 this.stringValue = String( stringValue );
41 this.toString = new Function( "return this.stringValue" );
42 this.valueOf = null;
43 }
44
45 function AnotherObject( value ) {
46 this.value = value;
47 this.valueOf = new Function( "return this.value" );
48 this.toString = new Function( "return 666" );
49 }
50
51 // should pass MyFunction.valueOf() to ambiguous
52
53 new TestCase(
54 "TEST_CLASS.ambiguous( MyFunction ) +''",
55 "INT",
56 TEST_CLASS.ambiguous( MyFunction )+'' );
57
58 // should pass MyOtherFunction.toString() to ambiguous
59
60 new TestCase(
61 "TEST_CLASS.ambiguous( MyOtherFunction ) +''",
62 "INT",
63 TEST_CLASS.ambiguous( MyOtherFunction )+'' );
64
65 // should pass MyObject.valueOf() to ambiguous
66
67 new TestCase(
68 "TEST_CLASS.ambiguous( new MyObject(12345) ) +''",
69 "INT",
70 TEST_CLASS.ambiguous( new MyObject(12345) )+'' );
71
72 // should pass MyOtherObject.toString() to ambiguous
73
74 new TestCase(
75 "TEST_CLASS.ambiguous( new MyOtherObject(\"12345\") ) +''",
76 "INT",
77 TEST_CLASS.ambiguous( new MyOtherObject("12345") )+'' );
78
79 // should pass AnotherObject.valueOf() to ambiguous
80
81 new TestCase(
82 "TEST_CLASS.ambiguous( new AnotherObject(\"12345\") ) +''",
83 "INT",
84 TEST_CLASS.ambiguous( new AnotherObject("12345") )+'' );
85
86 test();
87