Debian Codegraph @

rhino/testsrc/tests/lc3/ArrayMethods/byte-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 = 'byte-001.js';
7
8 /**
9 * java array objects "inherit" JS string methods. verify that byte arrays
10 * can inherit JavaScript Array object methods
11 *
12 *
13 */
14 var SECTION = "java array object inheritance JavaScript Array methods";
15 var VERSION = "1_4";
16 var TITLE = "LiveConnect 3.0 " + SECTION;
17
18 startTest();
19
20 var a = new Array();
21
22 a[a.length] = new TestObject(
23 "var b"+a.length+" = new java.lang.String(\"hello\").getBytes(); b"+a.length+".join() +''",
24 "b"+a.length,
25 "join",
26 true,
27 "104,101,108,108,111" );
28
29 a[a.length] = new TestObject(
30 "var b"+a.length+" = new java.lang.String(\"JavaScript\").getBytes(); b"+a.length+".reverse().join() +''",
31 "b"+a.length,
32 "reverse",
33 true,
34 getCharValues("tpircSavaJ") );
35
36 a[a.length] = new TestObject(
37 "var b"+a.length+" = new java.lang.String(\"JavaScript\").getBytes(); b"+a.length+".sort().join() +''",
38 "b"+a.length,
39 "sort",
40 true,
41 "105,112,114,116,118,74,83,97,97,99" );
42
43 a[a.length] = new TestObject(
44 "var b"+a.length+" = new java.lang.String(\"JavaScript\").getBytes(); b"+a.length+".sort().join() +''",
45 "b"+a.length,
46 "sort",
47 true,
48 "105,112,114,116,118,74,83,97,97,99" );
49
50 test();
51
52 // given a string, return a string consisting of the char value of each
53 // character in the string, separated by commas
54
55 function getCharValues(string) {
56 for ( var c = 0, cString = ""; c < string.length; c++ ) {
57 cString += string.charCodeAt(c) + ((c+1 < string.length) ? "," : "");
58 }
59 return cString;
60 }
61
62 // figure out what methods exist
63 // if there is no java method with the same name as a js method, should
64 // be able to invoke the js method without casting to a js string. also
65 // the method should equal the same method of String.prototype.
66 // if there is a java method with the same name as a js method, invoking
67 // the method should call the java method
68
69 function TestObject( description, ob, method, override, expect ) {
70 this.description = description;
71 this.object = ob;
72 this.method = method;
73 this.override = override
74 this.expect;
75
76 this.result = eval(description);
77
78 this.isJSMethod = eval( ob +"."+ method +" == Array.prototype." + method );
79
80 // verify result of method
81
82 new TestCase(
83 description,
84 expect,
85 this.result );
86
87 // verify that method is the method of Array.prototype
88
89 new TestCase(
90 ob +"." + method +" == Array.prototype." + method,
91 override,
92 this.isJSMethod );
93
94 // verify that it's not cast to JS Array type
95
96 new TestCase(
97 ob + ".getClass().getName() +''",
98 "[B",
99 eval( ob+".getClass().getName() +''") );
100
101 }