author | serb |
Tue, 29 Mar 2016 17:03:18 +0300 | |
changeset 36787 | 402e5e40f6e5 |
parent 34721 | 59801fbd042e |
permissions | -rw-r--r-- |
34721
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
1 |
/* |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
2 |
* This is the test JavaScript program used in jjs-fileTest.sh |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
3 |
*/ |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
4 |
|
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
5 |
// good old 'hello world'! |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
6 |
print('hello'); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
7 |
|
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
8 |
// basic number manipulation |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
9 |
var v = 2 + 5; |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
10 |
v *= 5; |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
11 |
v.doubleValue(); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
12 |
v = v + " is the value"; |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
13 |
if (v != 0) { |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
14 |
print('yes v != 0'); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
15 |
} |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
16 |
|
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
17 |
// basic java access |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
18 |
java.lang.System.out.println('hello world from script'); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
19 |
|
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
20 |
// basic stream manipulation |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
21 |
var al = new java.util.ArrayList(); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
22 |
al.add("hello"); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
23 |
al.add("world"); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
24 |
// script functions for lambas |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
25 |
al.stream().map(function(s) s.toUpperCase()).forEach(print); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
26 |
|
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
27 |
// interface implementation |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
28 |
new java.lang.Runnable() { |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
29 |
run: function() { |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
30 |
print('I am runnable'); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
31 |
} |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
32 |
}.run(); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
33 |
|
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
34 |
// java class extension |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
35 |
var MyList = Java.extend(java.util.ArrayList); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
36 |
var m = new MyList() { |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
37 |
size: function() { |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
38 |
print("size called"); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
39 |
// call super.size() |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
40 |
return Java.super(m).size(); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
41 |
} |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
42 |
}; |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
43 |
|
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
44 |
print("is m an ArrayList? " + (m instanceof java.util.ArrayList)); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
45 |
m.add("hello"); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
46 |
m.add("world"); |
59801fbd042e
8145750: jjs fails to run simple scripts with security manager turned on
sundar
parents:
diff
changeset
|
47 |
print(m.size()); |