author | hannesw |
Wed, 16 Sep 2015 14:42:32 +0200 | |
changeset 32695 | 9b708b92c695 |
parent 32529 | 5dbfbb64eab7 |
permissions | -rw-r--r-- |
32529 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 |
* JDK-8134569: Add tests for prototype callsites |
|
26 |
* |
|
27 |
* @test |
|
28 |
* @run |
|
29 |
*/ |
|
30 |
||
31 |
function create() { |
|
32 |
function C() { |
|
33 |
this.i1 = 1; |
|
34 |
this.i2 = 2; |
|
35 |
this.i3 = 3; |
|
36 |
return this; |
|
37 |
} |
|
38 |
return new C(); |
|
39 |
} |
|
40 |
||
41 |
function createEmpty() { |
|
42 |
function C() { |
|
43 |
return this; |
|
44 |
} |
|
45 |
return new C(); |
|
46 |
} |
|
47 |
||
48 |
function createDeep() { |
|
49 |
function C() { |
|
50 |
this.i1 = 1; |
|
51 |
this.i2 = 2; |
|
52 |
this.i3 = 3; |
|
53 |
return this; |
|
54 |
} |
|
55 |
function D() { |
|
56 |
this.p1 = 1; |
|
57 |
this.p2 = 2; |
|
58 |
this.p3 = 3; |
|
59 |
return this; |
|
60 |
} |
|
61 |
C.prototype = new D(); |
|
62 |
return new C(); |
|
63 |
} |
|
64 |
||
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
65 |
function createDeeper() { |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
66 |
function C() { |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
67 |
this.i1 = 1; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
68 |
this.i2 = 2; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
69 |
this.i3 = 3; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
70 |
return this; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
71 |
} |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
72 |
function D() { |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
73 |
this.p1 = 1; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
74 |
this.p2 = 2; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
75 |
this.p3 = 3; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
76 |
return this; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
77 |
} |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
78 |
function E() { |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
79 |
this.e1 = 1; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
80 |
this.e2 = 2; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
81 |
this.e3 = 3; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
82 |
return this; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
83 |
} |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
84 |
D.prototype = new E(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
85 |
C.prototype = new D(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
86 |
return new C(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
87 |
} |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
88 |
|
32529 | 89 |
function createEval() { |
90 |
return eval("Object.create({})"); |
|
91 |
} |
|
92 |
||
93 |
function p(o) { print(o.x) } |
|
94 |
||
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
95 |
function e(o) { print(o.e1) } |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
96 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
97 |
var a, b, c; |
32529 | 98 |
|
99 |
create(); |
|
100 |
a = create(); |
|
101 |
b = create(); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
102 |
c = create(); |
32529 | 103 |
a.__proto__.x = 123; |
104 |
||
105 |
p(a); |
|
106 |
p(b); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
107 |
p(c); |
32529 | 108 |
|
109 |
a = create(); |
|
110 |
b = create(); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
111 |
c = create(); |
32529 | 112 |
b.__proto__.x = 123; |
113 |
||
114 |
p(a); |
|
115 |
p(b); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
116 |
p(c); |
32529 | 117 |
|
118 |
a = createEmpty(); |
|
119 |
b = createEmpty(); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
120 |
c = createEmpty(); |
32529 | 121 |
a.__proto__.x = 123; |
122 |
||
123 |
p(a); |
|
124 |
p(b); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
125 |
p(c); |
32529 | 126 |
|
127 |
a = createEmpty(); |
|
128 |
b = createEmpty(); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
129 |
c = createEmpty(); |
32529 | 130 |
b.__proto__.x = 123; |
131 |
||
132 |
p(a); |
|
133 |
p(b); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
134 |
p(c); |
32529 | 135 |
|
136 |
a = createDeep(); |
|
137 |
b = createDeep(); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
138 |
c = createDeep(); |
32529 | 139 |
a.__proto__.__proto__.x = 123; |
140 |
||
141 |
p(a); |
|
142 |
p(b); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
143 |
p(c); |
32529 | 144 |
|
145 |
a = createDeep(); |
|
146 |
b = createDeep(); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
147 |
c = createDeep(); |
32529 | 148 |
b.__proto__.__proto__.x = 123; |
149 |
||
150 |
p(a); |
|
151 |
p(b); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
152 |
p(c); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
153 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
154 |
a = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
155 |
b = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
156 |
c = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
157 |
a.__proto__.__proto__.__proto__.x = 123; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
158 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
159 |
p(a); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
160 |
p(b); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
161 |
p(c); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
162 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
163 |
a = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
164 |
b = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
165 |
c = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
166 |
b.__proto__.__proto__.__proto__.x = 123; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
167 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
168 |
p(a); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
169 |
p(b); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
170 |
p(c); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
171 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
172 |
a = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
173 |
b = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
174 |
c = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
175 |
a.__proto__.__proto__ = null; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
176 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
177 |
e(a); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
178 |
e(b); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
179 |
e(c); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
180 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
181 |
a = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
182 |
b = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
183 |
c = createDeeper(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
184 |
b.__proto__.__proto__ = null; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
185 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
186 |
e(a); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
187 |
e(b); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
188 |
e(c); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
189 |
|
32529 | 190 |
|
191 |
a = createEval(); |
|
192 |
b = createEval(); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
193 |
c = createEval(); |
32529 | 194 |
a.__proto__.x = 123; |
195 |
||
196 |
p(a); |
|
197 |
p(b); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
198 |
p(c); |
32529 | 199 |
|
200 |
a = createEval(); |
|
201 |
b = createEval(); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
202 |
c = createEval(); |
32529 | 203 |
b.__proto__.x = 123; |
204 |
||
205 |
p(a); |
|
206 |
p(b); |
|
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32529
diff
changeset
|
207 |
p(c); |