hannesw@1075: /* hannesw@1075: * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. hannesw@1075: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. hannesw@1075: * hannesw@1075: * This code is free software; you can redistribute it and/or modify it hannesw@1075: * under the terms of the GNU General Public License version 2 only, as hannesw@1075: * published by the Free Software Foundation. hannesw@1075: * hannesw@1075: * This code is distributed in the hope that it will be useful, but WITHOUT hannesw@1075: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or hannesw@1075: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License hannesw@1075: * version 2 for more details (a copy is included in the LICENSE file that hannesw@1075: * accompanied this code). hannesw@1075: * hannesw@1075: * You should have received a copy of the GNU General Public License version hannesw@1075: * 2 along with this work; if not, write to the Free Software Foundation, hannesw@1075: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. hannesw@1075: * hannesw@1075: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA hannesw@1075: * or visit www.oracle.com if you need additional information or have any hannesw@1075: * questions. hannesw@1075: */ hannesw@1075: hannesw@1075: /** hannesw@1075: * 8062132: Nashorn incorrectly binds "this" for constructor created by another function hannesw@1075: * hannesw@1075: * @test hannesw@1075: * @run hannesw@1075: */ hannesw@1075: hannesw@1075: function subclass(parentCtor, proto) { hannesw@1075: function C() { hannesw@1075: parentCtor.call(this); hannesw@1075: } hannesw@1075: hannesw@1075: C.prototype = Object.create(parentCtor.prototype); hannesw@1075: hannesw@1075: for (var prop in proto) { hannesw@1075: if (proto.hasOwnProperty(prop)) { hannesw@1075: C.prototype[prop] = proto[prop]; hannesw@1075: } hannesw@1075: } hannesw@1075: hannesw@1075: return C; hannesw@1075: } hannesw@1075: hannesw@1075: var Parent = function() { hannesw@1075: this.init(); hannesw@1075: }; hannesw@1075: hannesw@1075: Parent.prototype = { hannesw@1075: init: null hannesw@1075: }; hannesw@1075: hannesw@1075: var Child1 = subclass(Parent, { hannesw@1075: prop1: 1, hannesw@1075: init: function() { hannesw@1075: print('child 1'); hannesw@1075: } hannesw@1075: }); hannesw@1075: hannesw@1075: var Child2 = subclass(Parent, { hannesw@1075: init: function() { hannesw@1075: print('child 2'); hannesw@1075: } hannesw@1075: }); hannesw@1075: hannesw@1075: var Child3 = subclass(Parent, { hannesw@1075: prop1: 1, hannesw@1075: init: function() { hannesw@1075: print('child 3'); hannesw@1075: } hannesw@1075: }); hannesw@1075: hannesw@1075: new Child1(); hannesw@1075: new Child2(); hannesw@1075: new Child3(); hannesw@1075: new Child1(); hannesw@1075: new Child2(); hannesw@1075: new Child3();