NASHORN-592.js revision 2:da1e581c933b
1/*
2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/**
25 * NASHORN-592: test all combos of field types and getters and setters
26 *
27 * @test
28 * @run
29 */
30
31//fortype undefined
32var a;
33
34print(a & 0xff);
35print(a >>> 1);
36print(a * 2);
37print(a + "hej!");
38
39var b;
40b = 17;   //set undefined->int
41
42print(b & 0xff);
43print(b >>> 1);
44print(b * 2);
45print(b + "hej!");
46
47var c;
48c = 17.4711 //set undefined->double
49
50print(c & 0xff);
51print(c >>> 1);
52print(c * 2);
53print(c + "hej!");
54
55var d; // set undefined->double
56d = "Fame and fortune Salamander Yahoo!";
57
58print(d & 0xff);
59print(d >>> 1);
60print(d * 2);
61print(d + "hej!");
62
63// now we have exhausted all getters and undefined->everything setters.
64
65
66var e = 23; // int to everything setters,
67e = 24;     //int to int
68print(e);
69e = (22222 >>> 1); //int to long;
70print(e);
71e = 23.23;  //int to double
72print(e);
73e = 23;     //double to int - still double
74print(e);
75print(e & 0xff);
76e = "Have some pie!" //double to string
77print(e);
78e = 4711.17;
79print(e); //still an object not a double
80
81
82var f = (23222 >>> 1); // long to everything setters,
83f = 34344 >>> 1;     //long to long
84print(f);
85f = 23; //long to int - still long
86print(f);
87f = 23.23;  //long to double
88print(f);
89f = 23;     //double to int - still double
90print(f);
91print(f & 0xff);
92f = "Have some pie!" //double to string
93print(f);
94f = 4711.17;
95print(f); //still an object not a double
96
97var g = 4811.16;
98g = 23; //still double
99print(g);
100g = (222 >>> 1); //still double
101print(g);
102g = 4711.16; //double->double
103print(g);
104g = "I like cake!";
105print(g);  //object to various
106print(g & 0xff);
107print(g * 2);
108print(g >>> 2);
109print(g);
110
111var h = {x:17, y:17.4711, z:"salamander"};
112print(h.x);
113print(h.y);
114print(h.z);
115h.x = 4711.17;
116h.y = "axolotl";
117h.z = "lizard";
118print(h.x);
119print(h.y);
120print(h.z);
121