nashorn/test/script/basic/JDK-8134569.js
author hannesw
Thu, 10 Sep 2015 13:50:04 +0200
changeset 32529 5dbfbb64eab7
child 32695 9b708b92c695
permissions -rw-r--r--
8134569: Add tests for prototype callsites Reviewed-by: attila, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32529
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
     1
/*
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
     4
 * 
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
     8
 * 
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    13
 * accompanied this code).
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    14
 * 
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    18
 * 
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    21
 * questions.
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    22
 */
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    23
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    24
/**
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    25
 * JDK-8134569: Add tests for prototype callsites
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    26
 *
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    27
 * @test
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    28
 * @run
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    29
 */
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    30
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    31
function create() {
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    32
    function C() {
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    33
        this.i1 = 1;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    34
        this.i2 = 2;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    35
        this.i3 = 3;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    36
        return this;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    37
    }
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    38
    return new C();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    39
}
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    40
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    41
function createEmpty() {
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    42
    function C() {
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    43
        return this;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    44
    }
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    45
    return new C();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    46
}
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    47
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    48
function createDeep() {
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    49
    function C() {
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    50
        this.i1 = 1;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    51
        this.i2 = 2;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    52
        this.i3 = 3;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    53
        return this;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    54
    }
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    55
    function D() {
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    56
        this.p1 = 1;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    57
        this.p2 = 2;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    58
        this.p3 = 3;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    59
        return this;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    60
    }
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    61
    C.prototype = new D();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    62
    return new C();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    63
}
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    64
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    65
function createEval() {
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    66
    return eval("Object.create({})");
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    67
}
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    68
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    69
function p(o) { print(o.x) }
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    70
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    71
var a, b;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    72
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    73
create();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    74
a = create();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    75
b = create();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    76
a.__proto__.x = 123;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    77
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    78
p(a);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    79
p(b);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    80
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    81
a = create();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    82
b = create();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    83
b.__proto__.x = 123;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    84
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    85
p(a);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    86
p(b);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    87
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    88
a = createEmpty();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    89
b = createEmpty();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    90
a.__proto__.x = 123;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    91
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    92
p(a);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    93
p(b);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    94
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    95
a = createEmpty();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    96
b = createEmpty();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    97
b.__proto__.x = 123;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    98
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
    99
p(a);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   100
p(b);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   101
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   102
a = createDeep();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   103
b = createDeep();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   104
a.__proto__.__proto__.x = 123;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   105
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   106
p(a);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   107
p(b);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   108
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   109
a = createDeep();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   110
b = createDeep();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   111
b.__proto__.__proto__.x = 123;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   112
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   113
p(a);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   114
p(b);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   115
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   116
a = createEval();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   117
b = createEval();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   118
a.__proto__.x = 123;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   119
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   120
p(a);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   121
p(b);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   122
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   123
a = createEval();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   124
b = createEval();
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   125
b.__proto__.x = 123;
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   126
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   127
p(a);
5dbfbb64eab7 8134569: Add tests for prototype callsites
hannesw
parents:
diff changeset
   128
p(b);