src/jdk/nashorn/internal/runtime/ScriptObject.java
Print this page
*** 1322,1332 ****
* return an array of own property keys associated with the object.
*
* @param all True if to include non-enumerable keys.
* @return Array of keys.
*/
! public String[] getOwnKeys(final boolean all) {
final List<Object> keys = new ArrayList<>();
final PropertyMap selfMap = this.getMap();
final ArrayData array = getArray();
final long length = array.length();
--- 1322,1344 ----
* return an array of own property keys associated with the object.
*
* @param all True if to include non-enumerable keys.
* @return Array of keys.
*/
! public final String[] getOwnKeys(final boolean all) {
! return getOwnKeys(all, null);
! }
!
! /**
! * return an array of own property keys associated with the object.
! *
! * @param all True if to include non-enumerable keys.
! * @param nonEnumerable set of non-enumerable properties seen already.Used
! to filter out shadowed, but enumerable properties from proto children.
! * @return Array of keys.
! */
! protected String[] getOwnKeys(final boolean all, final Set<String> nonEnumerable) {
final List<Object> keys = new ArrayList<>();
final PropertyMap selfMap = this.getMap();
final ArrayData array = getArray();
final long length = array.length();
*** 1336,1347 ****
keys.add(JSType.toString(i));
}
}
for (final Property property : selfMap.getProperties()) {
! if (all || property.isEnumerable()) {
! keys.add(property.getKey());
}
}
return keys.toArray(new String[keys.size()]);
}
--- 1348,1372 ----
keys.add(JSType.toString(i));
}
}
for (final Property property : selfMap.getProperties()) {
! final boolean enumerable = property.isEnumerable();
! final String key = property.getKey();
! if (all) {
! keys.add(key);
! } else if (enumerable) {
! // either we don't have non-enumerable filter set or filter set
! // does not contain the current property.
! if (nonEnumerable == null || !nonEnumerable.contains(key)) {
! keys.add(key);
! }
! } else {
! // store this non-enumerable property for later proto walk
! if (nonEnumerable != null) {
! nonEnumerable.add(key);
! }
}
}
return keys.toArray(new String[keys.size()]);
}
*** 2396,2407 ****
}
@Override
protected void init() {
final Set<String> keys = new LinkedHashSet<>();
for (ScriptObject self = object; self != null; self = self.getProto()) {
! keys.addAll(Arrays.asList(self.getOwnKeys(false)));
}
this.values = keys.toArray(new String[keys.size()]);
}
}
--- 2421,2433 ----
}
@Override
protected void init() {
final Set<String> keys = new LinkedHashSet<>();
+ final Set<String> nonEnumerable = new HashSet<>();
for (ScriptObject self = object; self != null; self = self.getProto()) {
! keys.addAll(Arrays.asList(self.getOwnKeys(false, nonEnumerable)));
}
this.values = keys.toArray(new String[keys.size()]);
}
}
*** 2411,2422 ****
}
@Override
protected void init() {
final ArrayList<Object> valueList = new ArrayList<>();
for (ScriptObject self = object; self != null; self = self.getProto()) {
! for (final String key : self.getOwnKeys(false)) {
valueList.add(self.get(key));
}
}
this.values = valueList.toArray(new Object[valueList.size()]);
}
--- 2437,2449 ----
}
@Override
protected void init() {
final ArrayList<Object> valueList = new ArrayList<>();
+ final Set<String> nonEnumerable = new HashSet<>();
for (ScriptObject self = object; self != null; self = self.getProto()) {
! for (final String key : self.getOwnKeys(false, nonEnumerable)) {
valueList.add(self.get(key));
}
}
this.values = valueList.toArray(new Object[valueList.size()]);
}