JDK-8134569.js revision 1429:b4eb53200105
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
31function 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
41function createEmpty() {
42    function C() {
43        return this;
44    }
45    return new C();
46}
47
48function 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
65function createDeeper() {
66    function C() {
67        this.i1 = 1;
68        this.i2 = 2;
69        this.i3 = 3;
70        return this;
71    }
72    function D() {
73        this.p1 = 1;
74        this.p2 = 2;
75        this.p3 = 3;
76        return this;
77    }
78    function E() {
79        this.e1 = 1;
80        this.e2 = 2;
81        this.e3 = 3;
82        return this;
83    }
84    D.prototype = new E();
85    C.prototype = new D();
86    return new C();
87}
88
89function createEval() {
90    return eval("Object.create({})");
91}
92
93function p(o) { print(o.x) }
94
95function e(o) { print(o.e1) }
96
97var a, b, c;
98
99create();
100a = create();
101b = create();
102c = create();
103a.__proto__.x = 123;
104
105p(a);
106p(b);
107p(c);
108
109a = create();
110b = create();
111c = create();
112b.__proto__.x = 123;
113
114p(a);
115p(b);
116p(c);
117
118a = createEmpty();
119b = createEmpty();
120c = createEmpty();
121a.__proto__.x = 123;
122
123p(a);
124p(b);
125p(c);
126
127a = createEmpty();
128b = createEmpty();
129c = createEmpty();
130b.__proto__.x = 123;
131
132p(a);
133p(b);
134p(c);
135
136a = createDeep();
137b = createDeep();
138c = createDeep();
139a.__proto__.__proto__.x = 123;
140
141p(a);
142p(b);
143p(c);
144
145a = createDeep();
146b = createDeep();
147c = createDeep();
148b.__proto__.__proto__.x = 123;
149
150p(a);
151p(b);
152p(c);
153
154a = createDeeper();
155b = createDeeper();
156c = createDeeper();
157a.__proto__.__proto__.__proto__.x = 123;
158
159p(a);
160p(b);
161p(c);
162
163a = createDeeper();
164b = createDeeper();
165c = createDeeper();
166b.__proto__.__proto__.__proto__.x = 123;
167
168p(a);
169p(b);
170p(c);
171
172a = createDeeper();
173b = createDeeper();
174c = createDeeper();
175a.__proto__.__proto__ = null;
176
177e(a);
178e(b);
179e(c);
180
181a = createDeeper();
182b = createDeeper();
183c = createDeeper();
184b.__proto__.__proto__ = null;
185
186e(a);
187e(b);
188e(c);
189
190
191a = createEval();
192b = createEval();
193c = createEval();
194a.__proto__.x = 123;
195
196p(a);
197p(b);
198p(c);
199
200a = createEval();
201b = createEval();
202c = createEval();
203b.__proto__.x = 123;
204
205p(a);
206p(b);
207p(c);
208