@@ -175,15 +175,19 @@ public void visitObjectArray(int index, int count) {
175175
176176 @ TruffleBoundary
177177 boolean putGeneric (DynamicObject object , Object key , Object value , int newPropertyFlags , int putFlags , Shape s , Property existingProperty ) {
178- if (existingProperty == null && Flags .isSetExisting (putFlags )) {
179- return false ;
180- }
181- if (existingProperty != null && !Flags .isUpdateFlags (putFlags ) && existingProperty .getLocation ().canStore (value )) {
182- existingProperty .getLocation ().setSafe (object , value , false , false );
183- return true ;
178+ if (existingProperty == null ) {
179+ if (Flags .isPutIfPresent (putFlags )) {
180+ return false ;
181+ }
184182 } else {
185- return putGenericSlowPath (object , key , value , newPropertyFlags , putFlags , s , existingProperty );
183+ if (Flags .isPutIfAbsent (putFlags )) {
184+ return true ;
185+ } else if (!Flags .isUpdateFlags (putFlags ) && existingProperty .getLocation ().canStore (value )) {
186+ existingProperty .getLocation ().setSafe (object , value , false , false );
187+ return true ;
188+ }
186189 }
190+ return putGenericSlowPath (object , key , value , newPropertyFlags , putFlags , s , existingProperty );
187191 }
188192
189193 private boolean putGenericSlowPath (DynamicObject object , Object key , Object value , int newPropertyFlags , int putFlags ,
@@ -197,12 +201,14 @@ private boolean putGenericSlowPath(DynamicObject object, Object key, Object valu
197201 oldShape = object .getShape ();
198202 final Property existingProperty = reusePropertyLookup (key , initialShape , propertyOfInitialShape , oldShape );
199203 if (existingProperty == null ) {
200- if (Flags .isSetExisting (putFlags )) {
204+ if (Flags .isPutIfPresent (putFlags )) {
201205 return false ;
202206 } else {
203207 newShape = defineProperty (oldShape , key , value , newPropertyFlags , existingProperty , putFlags );
204208 property = newShape .getProperty (key );
205209 }
210+ } else if (Flags .isPutIfAbsent (putFlags )) {
211+ return true ;
206212 } else if (Flags .isUpdateFlags (putFlags ) && newPropertyFlags != existingProperty .getFlags ()) {
207213 newShape = defineProperty (oldShape , key , value , newPropertyFlags , existingProperty , putFlags );
208214 property = newShape .getProperty (key );
@@ -211,6 +217,7 @@ private boolean putGenericSlowPath(DynamicObject object, Object key, Object valu
211217 newShape = oldShape ;
212218 property = existingProperty ;
213219 } else {
220+ assert !Flags .isUpdateFlags (putFlags ) || newPropertyFlags == existingProperty .getFlags ();
214221 newShape = defineProperty (oldShape , key , value , existingProperty .getFlags (), existingProperty , putFlags );
215222 property = newShape .getProperty (key );
216223 }
@@ -224,6 +231,8 @@ private boolean putGenericSlowPath(DynamicObject object, Object key, Object valu
224231 location .setSafe (object , value , false , true );
225232 DynamicObjectSupport .setShapeWithStoreFence (object , newShape );
226233 updateShape (object );
234+ } else if (Flags .isPutIfAbsent (putFlags )) {
235+ return true ;
227236 } else {
228237 location .setSafe (object , value , false , false );
229238 }
0 commit comments