diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyListeners.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyListeners.java index ca64212c654..a6e5ec363fa 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyListeners.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyListeners.java @@ -54,7 +54,13 @@ public class PropertyListeners { */ PropertyListeners(final PropertyListeners listener) { if (listener != null && listener.listeners != null) { - this.listeners = new WeakHashMap<>(listener.listeners); + this.listeners = new WeakHashMap<>(); + // We need to copy the nested weak sets in order to avoid concurrent modification issues, see JDK-8146274 + synchronized (listener) { + for (final Map.Entry entry : listener.listeners.entrySet()) { + this.listeners.put(entry.getKey(), new WeakPropertyMapSet(entry.getValue())); + } + } } } @@ -228,7 +234,15 @@ public class PropertyListeners { private static class WeakPropertyMapSet { - private final WeakHashMap map = new WeakHashMap<>(); + private final WeakHashMap map; + + WeakPropertyMapSet() { + this.map = new WeakHashMap<>(); + } + + WeakPropertyMapSet(final WeakPropertyMapSet set) { + this.map = new WeakHashMap<>(set.map); + } void add(final PropertyMap propertyMap) { map.put(propertyMap, Boolean.TRUE); diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties index e3310559a31..567c7871846 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties @@ -24,7 +24,7 @@ Object.preventExtensions=prevents new properties from ever being added to the gi Object.isSealed=tells if an object is sealed or not -Object.isFrozen=tells if an object is fronzen or not +Object.isFrozen=tells if an object is frozen or not Object.isExtensible=tells if an object is extensible or not @@ -32,7 +32,7 @@ Object.keys=returns an array of the given object's own enumerable properties Object=creates a new script object or converts given value as a script object -Object.prototype.toString=returns a string representing of this object +Object.prototype.toString=returns a string representation of this object Object.prototype.hasOwnProperty=tells whether this object has the specified property or not @@ -42,3 +42,12 @@ Object.prototype.propertyIsEnumerable=tells whether the given property is enumer Object.bindProperties=binds the source object's properties to the target object (nashorn extension) +Function=creates a new function with the given parameters and function body + +Function.prototype.toString=returns a string representation of this function + +Function.prototype.apply=invokes the function with the given this-reference and arguments array + +Function.prototype.call=invokes the function with the given this-reference and arguments + +Function.prototype.bind=returns a new function with bound this-reference and arguments