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-8074693: Different instances of same function use same allocator map
  26  *
  27  * @test
  28  * @run
  29  */
  30 
  31 var lib = {};
  32 
  33 lib.mixin = function(target, source) {
  34     for (var p in source) {
  35         if (source.hasOwnProperty(p) && !target.hasOwnProperty(p)) {
  36             target.prototype[p] = source[p];
  37         }
  38     }
  39 };
  40 
  41 lib.declare = function(def) {
  42     var className = def.name;
  43 
  44     lib[className] = function() {
  45         this.init.apply(this, arguments);
  46     };
  47 
  48     lib.mixin(lib[className], def.members);
  49 };
  50 
  51 
  52 lib.declare({
  53     name: "ClassA",
  54     members: {
  55         init : function () {
  56             print("init A called");
  57         }
  58     }
  59 });
  60 
  61 lib.declare({
  62     name: "ClassB",
  63     members: {
  64         util : function () {
  65             print("util called")
  66         },
  67         init : function() {
  68             print("init B called");
  69         }
  70     }
  71 });
  72 
  73 var objA = new lib.ClassA();
  74 var objB = new lib.ClassB();