469 newMap = new PropertyMap(newProperties, className, fieldCount - 1, fieldMaximum, spillLength, containsArrayKeys());
470 newMap.freeSlots = freeSlots;
471 } else {
472 newMap = new PropertyMap(this, newProperties);
473 newMap.updateFreeSlots(property, null);
474 }
475 addToHistory(property, newMap);
476 }
477
478 return newMap;
479 }
480
481 /**
482 * Replace an existing property with a new one.
483 *
484 * @param oldProperty Property to replace.
485 * @param newProperty New {@link Property}.
486 *
487 * @return New {@link PropertyMap} with {@link Property} replaced.
488 */
489 PropertyMap replaceProperty(final Property oldProperty, final Property newProperty) {
490 if (listeners != null) {
491 listeners.propertyModified(oldProperty, newProperty);
492 }
493 // Add replaces existing property.
494 final PropertyHashMap newProperties = properties.immutableReplace(oldProperty, newProperty);
495 final PropertyMap newMap = new PropertyMap(this, newProperties);
496 /*
497 * See ScriptObject.modifyProperty and ScriptObject.setUserAccessors methods.
498 *
499 * This replaceProperty method is called only for the following three cases:
500 *
501 * 1. To change flags OR TYPE of an old (cloned) property. We use the same spill slots.
502 * 2. To change one UserAccessor property with another - user getter or setter changed via
503 * Object.defineProperty function. Again, same spill slots are re-used.
504 * 3. Via ScriptObject.setUserAccessors method to set user getter and setter functions
505 * replacing the dummy AccessorProperty with null method handles (added during map init).
506 *
507 * In case (1) and case(2), the property type of old and new property is same. For case (3),
508 * the old property is an AccessorProperty and the new one is a UserAccessorProperty property.
509 */
|
469 newMap = new PropertyMap(newProperties, className, fieldCount - 1, fieldMaximum, spillLength, containsArrayKeys());
470 newMap.freeSlots = freeSlots;
471 } else {
472 newMap = new PropertyMap(this, newProperties);
473 newMap.updateFreeSlots(property, null);
474 }
475 addToHistory(property, newMap);
476 }
477
478 return newMap;
479 }
480
481 /**
482 * Replace an existing property with a new one.
483 *
484 * @param oldProperty Property to replace.
485 * @param newProperty New {@link Property}.
486 *
487 * @return New {@link PropertyMap} with {@link Property} replaced.
488 */
489 public PropertyMap replaceProperty(final Property oldProperty, final Property newProperty) {
490 if (listeners != null) {
491 listeners.propertyModified(oldProperty, newProperty);
492 }
493 // Add replaces existing property.
494 final PropertyHashMap newProperties = properties.immutableReplace(oldProperty, newProperty);
495 final PropertyMap newMap = new PropertyMap(this, newProperties);
496 /*
497 * See ScriptObject.modifyProperty and ScriptObject.setUserAccessors methods.
498 *
499 * This replaceProperty method is called only for the following three cases:
500 *
501 * 1. To change flags OR TYPE of an old (cloned) property. We use the same spill slots.
502 * 2. To change one UserAccessor property with another - user getter or setter changed via
503 * Object.defineProperty function. Again, same spill slots are re-used.
504 * 3. Via ScriptObject.setUserAccessors method to set user getter and setter functions
505 * replacing the dummy AccessorProperty with null method handles (added during map init).
506 *
507 * In case (1) and case(2), the property type of old and new property is same. For case (3),
508 * the old property is an AccessorProperty and the new one is a UserAccessorProperty property.
509 */
|