nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java
changeset 18618 136279c4cbe6
parent 18617 f6fe338f62c3
child 18620 2e4082f4cc69
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java	Wed Jun 26 08:36:53 2013 -0300
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptObject.java	Wed Jun 26 15:40:52 2013 +0200
@@ -170,13 +170,30 @@
         }
 
         this.arrayData = ArrayData.EMPTY_ARRAY;
-
-        if (map == null) {
-            this.setMap(PropertyMap.newMap(getClass()));
-            return;
+        this.setMap(map == null ? PropertyMap.newMap(getClass()) : map);
+    }
+
+    /**
+     * Constructor that directly sets the prototype to {@code proto} and property map to
+     * {@code map} without invalidating the map as calling {@link #setProto(ScriptObject)}
+     * would do. This should only be used for objects that are always constructed with the
+     * same combination of prototype and property map.
+     *
+     * @param proto the prototype object
+     * @param map intial {@link PropertyMap}
+     */
+    protected ScriptObject(final ScriptObject proto, final PropertyMap map) {
+        if (Context.DEBUG) {
+            ScriptObject.count++;
         }
 
-        this.setMap(map);
+        this.arrayData = ArrayData.EMPTY_ARRAY;
+        this.setMap(map == null ? PropertyMap.newMap(getClass()) : map);
+        this.proto = proto;
+
+        if (proto != null) {
+            proto.setIsPrototype();
+        }
     }
 
     /**