src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java
Print this page
*** 302,311 ****
--- 302,328 ----
*/
public void addBoundProperties(final ScriptObject source, final Property[] properties) {
PropertyMap newMap = this.getMap();
for (final Property property : properties) {
+ newMap = addBoundProperty(newMap, source, property);
+ }
+
+ this.setMap(newMap);
+ }
+
+ /**
+ * Add a bound property from {@code source}, using the interim property map {@code propMap}, and return the
+ * new interim property map.
+ *
+ * @param propMap the property map
+ * @param source the source object
+ * @param property the property to be added
+ * @return the new property map
+ */
+ protected PropertyMap addBoundProperty(final PropertyMap propMap, final ScriptObject source, final Property property) {
+ PropertyMap newMap = propMap;
final String key = property.getKey();
final Property oldProp = newMap.findProperty(key);
if (oldProp == null) {
if (property instanceof UserAccessorProperty) {
// Note: we copy accessor functions to this object which is semantically different from binding.
*** 322,334 ****
!(oldProp.isWritable() && oldProp.isEnumerable())) {
throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
}
}
}
! }
!
! this.setMap(newMap);
}
/**
* Copy all properties from the array with their receiver bound to the source.
*
--- 339,349 ----
!(oldProp.isWritable() && oldProp.isEnumerable())) {
throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
}
}
}
! return newMap;
}
/**
* Copy all properties from the array with their receiver bound to the source.
*
*** 508,518 ****
} else {
return UNDEFINED;
}
}
! private void invalidateGlobalConstant(final String key) {
final GlobalConstants globalConstants = getGlobalConstants();
if (globalConstants != null) {
globalConstants.delete(key);
}
}
--- 523,537 ----
} else {
return UNDEFINED;
}
}
! /**
! * Invalidate any existing global constant method handles that may exist for {@code key}.
! * @param key the property name
! */
! protected void invalidateGlobalConstant(final String key) {
final GlobalConstants globalConstants = getGlobalConstants();
if (globalConstants != null) {
globalConstants.delete(key);
}
}