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