Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure next and orderedNext are null for slots in HashSlotMap. #1748

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rhino/src/main/java/org/mozilla/javascript/AccessorSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ public class AccessorSlot extends Slot {
super(oldSlot);
}

@Override
AccessorSlot copySlot() {
var newSlot = new AccessorSlot(this);
newSlot.value = value;
newSlot.getter = getter;
newSlot.setter = setter;
newSlot.next = null;
newSlot.orderedNext = null;
return newSlot;
}

// The Getter and Setter may each be of a different type (JavaScript function, Java
// function, or neither). So, use an abstraction to distinguish them.
transient Getter getter;
Expand Down
13 changes: 12 additions & 1 deletion rhino/src/main/java/org/mozilla/javascript/HashSlotMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@
*/
public class HashSlotMap implements SlotMap {

private final LinkedHashMap<Object, Slot> map = new LinkedHashMap<>();
private final LinkedHashMap<Object, Slot> map;

public HashSlotMap() {
map = new LinkedHashMap<>();
}

public HashSlotMap(SlotMap oldMap) {
map = new LinkedHashMap<>(oldMap.size());
for (Slot n : oldMap) {
add(n.copySlot());
}
}

@Override
public int size() {
Expand Down
13 changes: 13 additions & 0 deletions rhino/src/main/java/org/mozilla/javascript/LambdaAccessorSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ public class LambdaAccessorSlot extends Slot {
super(oldSlot);
}

@Override
LambdaAccessorSlot copySlot() {
var newSlot = new LambdaAccessorSlot(this);
newSlot.value = value;
newSlot.getter = getter;
newSlot.setter = setter;
newSlot.getterFunction = getterFunction;
newSlot.setterFunction = setterFunction;
newSlot.next = null;
newSlot.orderedNext = null;
return newSlot;
}

@Override
boolean isValueSlot() {
return false;
Expand Down
11 changes: 11 additions & 0 deletions rhino/src/main/java/org/mozilla/javascript/LambdaSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ public class LambdaSlot extends Slot {
super(oldSlot);
}

@Override
LambdaSlot copySlot() {
var newSlot = new LambdaSlot(this);
newSlot.value = value;
newSlot.getter = getter;
newSlot.setter = setter;
newSlot.next = null;
newSlot.orderedNext = null;
return newSlot;
}

transient Supplier<Object> getter;
transient Consumer<Object> setter;

Expand Down
9 changes: 9 additions & 0 deletions rhino/src/main/java/org/mozilla/javascript/LazyLoadSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ public class LazyLoadSlot extends Slot {
super(oldSlot);
}

@Override
LazyLoadSlot copySlot() {
var newSlot = new LazyLoadSlot(this);
newSlot.value = value;
newSlot.next = null;
newSlot.orderedNext = null;
return newSlot;
}

@Override
public Object getValue(Scriptable start) {
Object val = this.value;
Expand Down
7 changes: 7 additions & 0 deletions rhino/src/main/java/org/mozilla/javascript/Slot.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public class Slot implements Serializable {
this.attributes = (short) attributes;
}

Slot copySlot() {
var newSlot = new Slot(this);
newSlot.next = null;
newSlot.orderedNext = null;
return newSlot;
}

/**
* Return true if this is a base-class "Slot". Sadly too much code breaks if we try to do this
* any other way.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ public void unlockRead(long stamp) {
*/
protected void checkMapSize() {
if ((map instanceof EmbeddedSlotMap) && map.size() >= LARGE_HASH_SIZE) {
SlotMap newMap = new HashSlotMap();
for (Slot s : map) {
newMap.add(s);
}
SlotMap newMap = new HashSlotMap(map);
map = newMap;
}
}
Expand Down
Loading