Debian Codegraph @

rhino/testsrc/tests/lc2/Methods/method-003.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 = 'method-003.js';
7
8 /**
9 File Name: method-003.js
10 Description:
11
12 JavaMethod objects are of the type "function" since they implement the
13 [[Call]] method.
14
15
16 @author [email protected]
17 @version 1.00
18 */
19 var SECTION = "LiveConnect Objects";
20 var VERSION = "1_3";
21 var TITLE = "Type and Class of Java Methods";
22
23 startTest();
24 writeHeaderToLog( SECTION + " "+ TITLE);
25
26 // All JavaMethods are of the type "function"
27 var E_TYPE = "function";
28
29 // All JavaMethods [[Class]] property is Function
30 var E_JSCLASS = "[object Function]";
31
32 // Create arrays of actual results (java_array) and
33 // expected results (test_array).
34
35 var java_array = new Array();
36 var test_array = new Array();
37
38 var i = 0;
39
40 java_array[i] = new JavaValue( java.lang.System.out.println );
41 test_array[i] = new TestValue( "java.lang.System.out.println" );
42 i++;
43
44 for ( i = 0; i < java_array.length; i++ ) {
45 CompareValues( java_array[i], test_array[i] );
46 }
47
48 test();
49
50 function CompareValues( javaval, testval ) {
51 // Check type, which should be E_TYPE
52 new TestCase( SECTION,
53 "typeof (" + testval.description +" )",
54 testval.type,
55 javaval.type );
56
57 // Check JavaScript class, which should be E_JSCLASS
58 new TestCase( SECTION,
59 "(" + testval.description +" ).getJSClass()",
60 testval.jsclass,
61 javaval.jsclass );
62 }
63 function JavaValue( value ) {
64 this.type = typeof value;
65 // Object.prototype.toString will show its JavaScript wrapper object.
66 value.getJSClass = Object.prototype.toString;
67 this.jsclass = value.getJSClass();
68 return this;
69 }
70 function TestValue( description ) {
71 this.description = description;
72 this.type = E_TYPE;
73 this.jsclass = E_JSCLASS;
74 return this;
75 }