Debian Codegraph @

rhino/testsrc/tests/lc3/forin/array-001.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 = 'array-001.js';
7
8 /**
9 * Verify that for-in loops can be used with java objects.
10 *
11 * Java array members should be enumerated in for... in loops.
12 *
13 *
14 */
15 var SECTION = "array-001";
16 var VERSION = "1_4";
17 var TITLE = "LiveConnect 3.0: for ... in java objects";
18 SECTION;
19 startTest();
20
21 // we just need to know the names of all the expected enumerated
22 // properties. we will get the values to the original objects.
23
24 // for arrays, we just need to know the length, since java arrays
25 // don't have any extra properties
26
27
28 var dt = new Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass;
29
30 var a = new Array();
31
32 a[a.length] = new TestObject(
33 new java.lang.String("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789").getBytes(),
34 "new java.lang.String(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\").getBytes()",
35 36 );
36
37 a[a.length] = new TestObject(
38 dt.PUB_ARRAY_SHORT,
39 "dt.PUB_ARRAY_SHORT",
40 dt.PUB_ARRAY_SHORT.length );
41
42 a[a.length] = new TestObject(
43 dt.PUB_ARRAY_LONG,
44 "dt.PUB_ARRAY_LONG",
45 dt.PUB_ARRAY_LONG.length );
46
47 a[a.length] = new TestObject(
48 dt.PUB_ARRAY_DOUBLE,
49 "dt.PUB_ARRAY_DOUBLE",
50 dt.PUB_ARRAY_DOUBLE.length );
51
52 a[a.length] = new TestObject(
53 dt.PUB_ARRAY_BYTE,
54 "dt.PUB_ARRAY_BYTE",
55 dt.PUB_ARRAY_BYTE.length );
56
57 a[a.length] = new TestObject(
58 dt.PUB_ARRAY_CHAR,
59 "dt.PUB_ARRAY_CHAR",
60 dt.PUB_ARRAY_CHAR.length );
61
62 a[a.length] = new TestObject(
63 dt.PUB_ARRAY_OBJECT,
64 "dt.PUB_ARRAY_OBJECT",
65 dt.PUB_ARRAY_OBJECT.length );
66
67 for ( var i = 0; i < a.length; i++ ) {
68 // check the number of properties of the enumerated object
69 new TestCase(
70 a[i].description +"; length",
71 a[i].items,
72 a[i].enumedArray.pCount );
73
74 for ( var arrayItem = 0; arrayItem < a[i].items; arrayItem++ ) {
75 new TestCase(
76 "["+arrayItem+"]",
77 a[i].javaArray[arrayItem],
78 a[i].enumedArray[arrayItem] );
79 }
80 }
81
82 test();
83
84 function TestObject( arr, descr, len ) {
85 this.javaArray = arr;
86 this.description = descr;
87 this.items = len;
88 this.enumedArray = new enumObject(arr);
89 }
90
91 function enumObject( o ) {
92 this.pCount = 0;
93 for ( var p in o ) {
94 this.pCount++;
95 if ( !isNaN(p) ) {
96 eval( "this["+p+"] = o["+p+"]" );
97 } else {
98 eval( "this." + p + " = o["+ p+"]" );
99 }
100 }
101 }
102