16147
|
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-592a: test all combos of field types and getters and setters
|
|
26 |
* This time use dual field representation
|
|
27 |
*
|
|
28 |
* @test
|
|
29 |
* @option --dual-fields
|
|
30 |
* @run
|
|
31 |
*/
|
|
32 |
|
|
33 |
//fortype undefined
|
|
34 |
var a;
|
|
35 |
|
|
36 |
print(a & 0xff);
|
|
37 |
print(a >>> 1);
|
|
38 |
print(a * 2);
|
|
39 |
print(a + "hej!");
|
|
40 |
|
|
41 |
var b;
|
|
42 |
b = 17; //set undefined->int
|
|
43 |
|
|
44 |
print(b & 0xff);
|
|
45 |
print(b >>> 1);
|
|
46 |
print(b * 2);
|
|
47 |
print(b + "hej!");
|
|
48 |
|
|
49 |
var c;
|
|
50 |
c = 17.4711 //set undefined->double
|
|
51 |
|
|
52 |
print(c & 0xff);
|
|
53 |
print(c >>> 1);
|
|
54 |
print(c * 2);
|
|
55 |
print(c + "hej!");
|
|
56 |
|
|
57 |
var d; // set undefined->double
|
|
58 |
d = "Fame and fortune Salamander Yahoo!";
|
|
59 |
|
|
60 |
print(d & 0xff);
|
|
61 |
print(d >>> 1);
|
|
62 |
print(d * 2);
|
|
63 |
print(d + "hej!");
|
|
64 |
|
|
65 |
// now we have exhausted all getters and undefined->everything setters.
|
|
66 |
|
|
67 |
|
|
68 |
var e = 23; // int to everything setters,
|
|
69 |
e = 24; //int to int
|
|
70 |
print(e);
|
|
71 |
e = (22222 >>> 1); //int to long;
|
|
72 |
print(e);
|
|
73 |
e = 23.23; //int to double
|
|
74 |
print(e);
|
|
75 |
e = 23; //double to int - still double
|
|
76 |
print(e);
|
|
77 |
print(e & 0xff);
|
|
78 |
e = "Have some pie!" //double to string
|
|
79 |
print(e);
|
|
80 |
e = 4711.17;
|
|
81 |
print(e); //still an object not a double
|
|
82 |
|
|
83 |
|
|
84 |
var f = (23222 >>> 1); // long to everything setters,
|
|
85 |
f = 34344 >>> 1; //long to long
|
|
86 |
print(f);
|
|
87 |
f = 23; //long to int - still long
|
|
88 |
print(f);
|
|
89 |
f = 23.23; //long to double
|
|
90 |
print(f);
|
|
91 |
f = 23; //double to int - still double
|
|
92 |
print(f);
|
|
93 |
print(f & 0xff);
|
|
94 |
f = "Have some pie!" //double to string
|
|
95 |
print(f);
|
|
96 |
f = 4711.17;
|
|
97 |
print(f); //still an object not a double
|
|
98 |
|
|
99 |
var g = 4811.16;
|
|
100 |
g = 23; //still double
|
|
101 |
print(g);
|
|
102 |
g = (222 >>> 1); //still double
|
|
103 |
print(g);
|
|
104 |
g = 4711.16; //double->double
|
|
105 |
print(g);
|
|
106 |
g = "I like cake!";
|
|
107 |
print(g); //object to various
|
|
108 |
print(g & 0xff);
|
|
109 |
print(g * 2);
|
|
110 |
print(g >>> 2);
|
|
111 |
print(g);
|
|
112 |
|
|
113 |
var h = {x:17, y:17.4711, z:"salamander"};
|
|
114 |
print(h.x);
|
|
115 |
print(h.y);
|
|
116 |
print(h.z);
|
|
117 |
h.x = 4711.17;
|
|
118 |
h.y = "axolotl";
|
|
119 |
h.z = "lizard";
|
|
120 |
print(h.x);
|
|
121 |
print(h.y);
|
|
122 |
print(h.z);
|