nashorn/test/script/basic/JDK-8062132.js
author hannesw
Fri, 31 Oct 2014 10:06:52 +0100
changeset 27356 2d407b9be8b0
permissions -rw-r--r--
8062132: Nashorn incorrectly binds this for constructor created by another function Reviewed-by: jlaskey, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27356
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
     1
/*
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
     4
 * 
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
     8
 * 
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    13
 * accompanied this code).
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    14
 * 
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    18
 * 
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    21
 * questions.
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    22
 */
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    23
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    24
/**
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    25
 * 8062132: Nashorn incorrectly binds "this" for constructor created by another function
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    26
 *
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    27
 * @test
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    28
 * @run
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    29
 */
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    30
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    31
function subclass(parentCtor, proto) {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    32
    function C() {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    33
        parentCtor.call(this);
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    34
    }
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    35
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    36
    C.prototype = Object.create(parentCtor.prototype);
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    37
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    38
    for (var prop in proto) {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    39
        if (proto.hasOwnProperty(prop)) {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    40
            C.prototype[prop] = proto[prop];
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    41
        }
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    42
    }
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    43
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    44
    return C;
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    45
}
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    46
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    47
var Parent = function() {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    48
    this.init();
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    49
};
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    50
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    51
Parent.prototype = {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    52
    init: null
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    53
};
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    54
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    55
var Child1 = subclass(Parent, {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    56
    prop1: 1,
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    57
    init: function() {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    58
        print('child 1');
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    59
    }
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    60
});
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    61
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    62
var Child2 = subclass(Parent, {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    63
    init: function() {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    64
        print('child 2');
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    65
    }
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    66
});
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    67
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    68
var Child3 = subclass(Parent, {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    69
    prop1: 1,
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    70
    init: function() {
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    71
        print('child 3');
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    72
    }
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    73
});
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    74
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    75
new Child1();
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    76
new Child2();
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    77
new Child3();
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    78
new Child1();
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    79
new Child2();
2d407b9be8b0 8062132: Nashorn incorrectly binds this for constructor created by another function
hannesw
parents:
diff changeset
    80
new Child3();