Skip to content

Commit 9dff105

Browse files
woessgilles-duboscq
authored andcommitted
Refactor PropertyDescriptor and ensure that data property descriptor value is not null.
1 parent 8feb1dc commit 9dff105

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/access/JSGetOwnPropertyNode.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,20 @@ PropertyDescriptor array(JSDynamicObject thisObj, Object propertyKey,
126126
if (JSRuntime.isArrayIndex(idx)) {
127127
ScriptArray array = typeProfile.profile(JSAbstractArray.arrayGetArrayType(thisObj));
128128
if (array.hasElement(thisObj, idx)) {
129-
Object value = needValue ? array.getElement(thisObj, idx) : null;
130-
return PropertyDescriptor.createData(value, true, needWritability && !array.isFrozen(), needConfigurability && !array.isSealed());
129+
PropertyDescriptor desc = PropertyDescriptor.createEmpty();
130+
if (needEnumerability) {
131+
desc.setEnumerable(true);
132+
}
133+
if (needConfigurability) {
134+
desc.setConfigurable(!array.isSealed());
135+
}
136+
if (needWritability) {
137+
desc.setWritable(!array.isFrozen());
138+
}
139+
if (needValue) {
140+
desc.setValue(array.getElement(thisObj, idx));
141+
}
142+
return desc;
131143
}
132144
}
133145
noSuchElementBranch.enter();
@@ -188,22 +200,18 @@ private PropertyDescriptor ordinaryGetOwnProperty(JSDynamicObject thisObj, Prope
188200
if (hasPropertyBranch.profile(prop == null)) {
189201
return null;
190202
}
191-
PropertyDescriptor d;
203+
PropertyDescriptor d = PropertyDescriptor.createEmpty();
192204
if (isDataPropertyBranch.profile(JSProperty.isData(prop))) {
193-
Object value = needValue ? getDataPropertyValue(thisObj, prop) : null;
194-
d = PropertyDescriptor.createData(value);
195205
if (needWritability) {
196206
d.setWritable(JSProperty.isWritable(prop));
197207
}
208+
if (needValue) {
209+
d.setValue(getDataPropertyValue(thisObj, prop));
210+
}
198211
} else if (isAccessorPropertyBranch.profile(JSProperty.isAccessor(prop))) {
199212
if (needValue) {
200-
Accessor acc = (Accessor) prop.getLocation().get(thisObj);
201-
d = PropertyDescriptor.createAccessor(acc.getGetter(), acc.getSetter());
202-
} else {
203-
d = PropertyDescriptor.createAccessor(null, null);
213+
d.setAccessor((Accessor) prop.getLocation().get(thisObj));
204214
}
205-
} else {
206-
d = PropertyDescriptor.createEmpty();
207215
}
208216
if (needEnumerability) {
209217
d.setEnumerable(JSProperty.isEnumerable(prop));

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/objects/PropertyDescriptor.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,7 @@ public static PropertyDescriptor createData(Object value, boolean isEnumerable,
8484
}
8585

8686
public static PropertyDescriptor createData(Object value, int attributes) {
87-
PropertyDescriptor desc = new PropertyDescriptor();
88-
desc.setValue(value);
89-
desc.setEnumerable(JSAttributes.isEnumerable(attributes));
90-
desc.setWritable(JSAttributes.isWritable(attributes));
91-
desc.setConfigurable(JSAttributes.isConfigurable(attributes));
92-
return desc;
87+
return createData(value, JSAttributes.isEnumerable(attributes), JSAttributes.isWritable(attributes), JSAttributes.isConfigurable(attributes));
9388
}
9489

9590
public static PropertyDescriptor createData(Object value) {
@@ -117,10 +112,7 @@ public static PropertyDescriptor createAccessor(Object getter, Object setter) {
117112
}
118113

119114
public static PropertyDescriptor createAccessor(Object getter, Object setter, int attributes) {
120-
PropertyDescriptor desc = createAccessor(getter, setter);
121-
desc.setEnumerable(JSAttributes.isEnumerable(attributes));
122-
desc.setConfigurable(JSAttributes.isConfigurable(attributes));
123-
return desc;
115+
return createAccessor(getter, setter, JSAttributes.isEnumerable(attributes), JSAttributes.isConfigurable(attributes));
124116
}
125117

126118
public static PropertyDescriptor createAccessor(Object getter, Object setter, boolean isEnumerable, boolean isConfigurable) {
@@ -138,6 +130,8 @@ public Object getValue() {
138130
}
139131

140132
public void setValue(Object value) {
133+
assert !isAccessorDescriptor() : this;
134+
assert value != null;
141135
this.data = value;
142136
this.flags |= HAS_VALUE;
143137
}
@@ -174,6 +168,12 @@ public void setSet(Object set) {
174168
this.flags |= HAS_SET;
175169
}
176170

171+
public void setAccessor(Accessor accessor) {
172+
assert !isDataDescriptor() : this;
173+
this.data = accessor;
174+
this.flags |= HAS_GET | HAS_SET;
175+
}
176+
177177
public boolean getEnumerable() {
178178
return (this.flags & ENUMERABLE) != 0;
179179
}

0 commit comments

Comments
 (0)