JDK-8134569.js revision 1418:ca0e29811b81
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 createEval() {
66    return eval("Object.create({})");
67}
68
69function p(o) { print(o.x) }
70
71var a, b;
72
73create();
74a = create();
75b = create();
76a.__proto__.x = 123;
77
78p(a);
79p(b);
80
81a = create();
82b = create();
83b.__proto__.x = 123;
84
85p(a);
86p(b);
87
88a = createEmpty();
89b = createEmpty();
90a.__proto__.x = 123;
91
92p(a);
93p(b);
94
95a = createEmpty();
96b = createEmpty();
97b.__proto__.x = 123;
98
99p(a);
100p(b);
101
102a = createDeep();
103b = createDeep();
104a.__proto__.__proto__.x = 123;
105
106p(a);
107p(b);
108
109a = createDeep();
110b = createDeep();
111b.__proto__.__proto__.x = 123;
112
113p(a);
114p(b);
115
116a = createEval();
117b = createEval();
118a.__proto__.x = 123;
119
120p(a);
121p(b);
122
123a = createEval();
124b = createEval();
125b.__proto__.x = 123;
126
127p(a);
128p(b);
129