< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java

Print this page

        

@@ -1246,11 +1246,11 @@
 
         if (oldProto != newProto) {
             proto = newProto;
 
             // Let current listeners know that the prototype has changed
-            getMap().protoChanged(true);
+            getMap().protoChanged();
             // Replace our current allocator map with one that is associated with the new prototype.
             setMap(getMap().changeProto(newProto));
         }
     }
 

@@ -2118,37 +2118,49 @@
     public final SwitchPoint[] getProtoSwitchPoints(final String name, final ScriptObject owner) {
         if (owner == this || getProto() == null) {
             return null;
         }
 
-        final List<SwitchPoint> switchPoints = new ArrayList<>();
+        final Set<SwitchPoint> switchPoints = new HashSet<>();
+        SwitchPoint switchPoint = getProto().getMap().getSwitchPoint(name);
+
+        if (switchPoint == null) {
+            switchPoint = new SwitchPoint();
+            for (ScriptObject obj = this; obj != owner && obj.getProto() != null; obj = obj.getProto()) {
+                obj.getProto().getMap().addSwitchPoint(name, switchPoint);
+            }
+        }
+
+        switchPoints.add(switchPoint);
+
         for (ScriptObject obj = this; obj != owner && obj.getProto() != null; obj = obj.getProto()) {
-            final ScriptObject parent = obj.getProto();
-            parent.getMap().addListener(name, obj.getMap());
-            final SwitchPoint sp = parent.getMap().getSharedProtoSwitchPoint();
-            if (sp != null && !sp.hasBeenInvalidated()) {
-                switchPoints.add(sp);
+            final SwitchPoint sharedProtoSwitchPoint = obj.getProto().getMap().getSharedProtoSwitchPoint();
+            if (sharedProtoSwitchPoint != null && !sharedProtoSwitchPoint.hasBeenInvalidated()) {
+                switchPoints.add(sharedProtoSwitchPoint);
             }
         }
 
-        switchPoints.add(getMap().getSwitchPoint(name));
         return switchPoints.toArray(new SwitchPoint[0]);
     }
 
     // Similar to getProtoSwitchPoints method above, but used for additional prototype switchpoints of
     // properties that are known not to exist, e.g. the original property name in a __noSuchProperty__ invocation.
     final SwitchPoint getProtoSwitchPoint(final String name) {
         if (getProto() == null) {
             return null;
         }
 
+        SwitchPoint switchPoint = getProto().getMap().getSwitchPoint(name);
+
+        if (switchPoint == null) {
+            switchPoint = new SwitchPoint();
         for (ScriptObject obj = this; obj.getProto() != null; obj = obj.getProto()) {
-            final ScriptObject parent = obj.getProto();
-            parent.getMap().addListener(name, obj.getMap());
+                obj.getProto().getMap().addSwitchPoint(name, switchPoint);
+            }
         }
 
-        return getMap().getSwitchPoint(name);
+        return switchPoint;
     }
 
     private void checkSharedProtoMap() {
         // Check if our map has an expected shared prototype property map. If it has, make sure that
         // the prototype map has not been invalidated, and that it does match the actual map of the prototype.
< prev index next >