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