nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java
changeset 26886 18c744ab4df2
parent 26768 751b0f427090
child 27209 30d8609b9561
equal deleted inserted replaced
26786:f0c5e4b732da 26886:18c744ab4df2
   933     /**
   933     /**
   934      * Fast initialization functions for ScriptFunctions that are strict, to avoid
   934      * Fast initialization functions for ScriptFunctions that are strict, to avoid
   935      * creating setters that probably aren't used. Inject directly into the spill pool
   935      * creating setters that probably aren't used. Inject directly into the spill pool
   936      * the defaults for "arguments" and "caller"
   936      * the defaults for "arguments" and "caller"
   937      *
   937      *
   938      * @param key
   938      * @param key           property key
   939      * @param propertyFlags
   939      * @param propertyFlags flags
   940      * @param getter
   940      * @param getter        getter for {@link UserAccessorProperty}, null if not present or N/A
   941      * @param setter
   941      * @param setter        setter for {@link UserAccessorProperty}, null if not present or N/A
   942      */
   942      */
   943     protected final void initUserAccessors(final String key, final int propertyFlags, final ScriptFunction getter, final ScriptFunction setter) {
   943     protected final void initUserAccessors(final String key, final int propertyFlags, final ScriptFunction getter, final ScriptFunction setter) {
   944         final int slot = spillLength;
   944         final int slot = spillLength;
   945         ensureSpillSize(spillLength); //arguments=slot0, caller=slot0
   945         ensureSpillSize(spillLength); //arguments=slot0, caller=slot0
   946         objectSpill[slot] = new UserAccessorProperty.Accessors(getter, setter);
   946         objectSpill[slot] = new UserAccessorProperty.Accessors(getter, setter);
  1747      * @param strict strict mode or not
  1747      * @param strict strict mode or not
  1748      * @return oldValue if property with same key existed already
  1748      * @return oldValue if property with same key existed already
  1749      */
  1749      */
  1750     public Object put(final Object key, final Object value, final boolean strict) {
  1750     public Object put(final Object key, final Object value, final boolean strict) {
  1751         final Object oldValue = get(key);
  1751         final Object oldValue = get(key);
  1752         final int flags = strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0;
  1752         final int scriptObjectFlags = strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0;
  1753         set(key, value, flags);
  1753         set(key, value, scriptObjectFlags);
  1754         return oldValue;
  1754         return oldValue;
  1755     }
  1755     }
  1756 
  1756 
  1757     /**
  1757     /**
  1758      * Put several properties in the ScriptObject given a mapping
  1758      * Put several properties in the ScriptObject given a mapping
  1761      *
  1761      *
  1762      * @param otherMap a {@literal <key,value>} map of properties to add
  1762      * @param otherMap a {@literal <key,value>} map of properties to add
  1763      * @param strict strict mode or not
  1763      * @param strict strict mode or not
  1764      */
  1764      */
  1765     public void putAll(final Map<?, ?> otherMap, final boolean strict) {
  1765     public void putAll(final Map<?, ?> otherMap, final boolean strict) {
  1766         final int flags = strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0;
  1766         final int scriptObjectFlags = strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0;
  1767         for (final Map.Entry<?, ?> entry : otherMap.entrySet()) {
  1767         for (final Map.Entry<?, ?> entry : otherMap.entrySet()) {
  1768             set(entry.getKey(), entry.getValue(), flags);
  1768             set(entry.getKey(), entry.getValue(), scriptObjectFlags);
  1769         }
  1769         }
  1770     }
  1770     }
  1771 
  1771 
  1772     /**
  1772     /**
  1773      * Remove a property from the ScriptObject.
  1773      * Remove a property from the ScriptObject.
  2044     }
  2044     }
  2045 
  2045 
  2046     // Marks a property as declared and sets its value. Used as slow path for block-scoped LET and CONST
  2046     // Marks a property as declared and sets its value. Used as slow path for block-scoped LET and CONST
  2047     @SuppressWarnings("unused")
  2047     @SuppressWarnings("unused")
  2048     private void declareAndSet(final String key, final Object value) {
  2048     private void declareAndSet(final String key, final Object value) {
  2049         final PropertyMap map = getMap();
  2049         final PropertyMap oldMap = getMap();
  2050         final FindProperty find = findProperty(key, false);
  2050         final FindProperty find = findProperty(key, false);
  2051         assert find != null;
  2051         assert find != null;
  2052 
  2052 
  2053         final Property property = find.getProperty();
  2053         final Property property = find.getProperty();
  2054         assert property != null;
  2054         assert property != null;
  2055         assert property.needsDeclaration();
  2055         assert property.needsDeclaration();
  2056 
  2056 
  2057         final PropertyMap newMap = map.replaceProperty(property, property.removeFlags(Property.NEEDS_DECLARATION));
  2057         final PropertyMap newMap = oldMap.replaceProperty(property, property.removeFlags(Property.NEEDS_DECLARATION));
  2058         setMap(newMap);
  2058         setMap(newMap);
  2059         set(key, value, 0);
  2059         set(key, value, 0);
  2060     }
  2060     }
  2061 
  2061 
  2062     /**
  2062     /**