src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java
Print this page
@@ -302,10 +302,27 @@
*/
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,13 +339,11 @@
!(oldProp.isWritable() && oldProp.isEnumerable())) {
throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
}
}
}
- }
-
- this.setMap(newMap);
+ return newMap;
}
/**
* Copy all properties from the array with their receiver bound to the source.
*
@@ -508,11 +523,15 @@
} else {
return UNDEFINED;
}
}
- private void invalidateGlobalConstant(final String key) {
+ /**
+ * 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);
}
}