Java Code Examples for jdk.nashorn.internal.runtime.arrays.ArrayData#setLength()

The following examples show how to use jdk.nashorn.internal.runtime.arrays.ArrayData#setLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
  * Numeric length setter for length property
  *
  * @param newLength new length to set
  */
public final void setLength(final long newLength) {
    ArrayData data = getArray();
    final long arrayLength = data.length();
    if (newLength == arrayLength) {
        return;
    }

    if (newLength > arrayLength) {
        setArray(data.ensure(newLength - 1).safeDelete(arrayLength, newLength - 1, false));
        return;
    }

    if (newLength < arrayLength) {
       long actualLength = newLength;

       // Check for numeric keys in property map and delete them or adjust length, depending on whether
       // they're defined as configurable. See ES5 #15.4.5.2
       if (getMap().containsArrayKeys()) {

           for (long l = arrayLength - 1; l >= newLength; l--) {
               final FindProperty find = findProperty(JSType.toString(l), false);

               if (find != null) {

                   if (find.getProperty().isConfigurable()) {
                       deleteOwnProperty(find.getProperty());
                   } else {
                       actualLength = l + 1;
                       break;
                   }
               }
           }
       }

       setArray(data.shrink(actualLength));
       data.setLength(actualLength);
   }
}
 
Example 2
Source File: ScriptObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
  * Numeric length setter for length property
  *
  * @param newLength new length to set
  */
public final void setLength(final long newLength) {
    ArrayData data = getArray();
    final long arrayLength = data.length();
    if (newLength == arrayLength) {
        return;
    }

    if (newLength > arrayLength) {
        setArray(data.ensure(newLength - 1).safeDelete(arrayLength, newLength - 1, false));
        return;
    }

    if (newLength < arrayLength) {
       long actualLength = newLength;

       // Check for numeric keys in property map and delete them or adjust length, depending on whether
       // they're defined as configurable. See ES5 #15.4.5.2
       if (getMap().containsArrayKeys()) {

           for (long l = arrayLength - 1; l >= newLength; l--) {
               final FindProperty find = findProperty(JSType.toString(l), false);

               if (find != null) {

                   if (find.getProperty().isConfigurable()) {
                       deleteOwnProperty(find.getProperty());
                   } else {
                       actualLength = l + 1;
                       break;
                   }
               }
           }
       }

       setArray(data.shrink(actualLength));
       data.setLength(actualLength);
   }
}
 
Example 3
Source File: ScriptObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
  * Numeric length setter for length property
  *
  * @param newLength new length to set
  */
public final void setLength(final long newLength) {
    ArrayData data = getArray();
    final long arrayLength = data.length();
    if (newLength == arrayLength) {
        return;
    }

    if (newLength > arrayLength) {
        setArray(data.ensure(newLength - 1).safeDelete(arrayLength, newLength - 1, false));
        return;
    }

    if (newLength < arrayLength) {
       long actualLength = newLength;

       // Check for numeric keys in property map and delete them or adjust length, depending on whether
       // they're defined as configurable. See ES5 #15.4.5.2
       if (getMap().containsArrayKeys()) {

           for (long l = arrayLength - 1; l >= newLength; l--) {
               final FindProperty find = findProperty(JSType.toString(l), false);

               if (find != null) {

                   if (find.getProperty().isConfigurable()) {
                       deleteOwnProperty(find.getProperty());
                   } else {
                       actualLength = l + 1;
                       break;
                   }
               }
           }
       }

       setArray(data.shrink(actualLength));
       data.setLength(actualLength);
   }
}
 
Example 4
Source File: ScriptObject.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
  * Numeric length setter for length property
  *
  * @param newLength new length to set
  */
public final void setLength(final long newLength) {
    final ArrayData data = getArray();
    final long arrayLength = data.length();
    if (newLength == arrayLength) {
        return;
    }

    if (newLength > arrayLength) {
        setArray(data.ensure(newLength - 1).safeDelete(arrayLength, newLength - 1, false));
        return;
    }

    if (newLength < arrayLength) {
       long actualLength = newLength;

       // Check for numeric keys in property map and delete them or adjust length, depending on whether
       // they're defined as configurable. See ES5 #15.4.5.2
       if (getMap().containsArrayKeys()) {

           for (long l = arrayLength - 1; l >= newLength; l--) {
               final FindProperty find = findProperty(JSType.toString(l), false);

               if (find != null) {

                   if (find.getProperty().isConfigurable()) {
                       deleteOwnProperty(find.getProperty());
                   } else {
                       actualLength = l + 1;
                       break;
                   }
               }
           }
       }

       setArray(data.shrink(actualLength));
       data.setLength(actualLength);
   }
}
 
Example 5
Source File: ScriptObject.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
  * Numeric length setter for length property
  *
  * @param newLength new length to set
  */
public final void setLength(final long newLength) {
    ArrayData data = getArray();
    final long arrayLength = data.length();
    if (newLength == arrayLength) {
        return;
    }

    if (newLength > arrayLength) {
        setArray(data.ensure(newLength - 1).safeDelete(arrayLength, newLength - 1, false));
        return;
    }

    if (newLength < arrayLength) {
       long actualLength = newLength;

       // Check for numeric keys in property map and delete them or adjust length, depending on whether
       // they're defined as configurable. See ES5 #15.4.5.2
       if (getMap().containsArrayKeys()) {

           for (long l = arrayLength - 1; l >= newLength; l--) {
               final FindProperty find = findProperty(JSType.toString(l), false);

               if (find != null) {

                   if (find.getProperty().isConfigurable()) {
                       deleteOwnProperty(find.getProperty());
                   } else {
                       actualLength = l + 1;
                       break;
                   }
               }
           }
       }

       setArray(data.shrink(actualLength));
       data.setLength(actualLength);
   }
}
 
Example 6
Source File: ScriptObject.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
  * Numeric length setter for length property
  *
  * @param newLength new length to set
  */
public final void setLength(final long newLength) {
    ArrayData data = getArray();
    final long arrayLength = data.length();
    if (newLength == arrayLength) {
        return;
    }

    if (newLength > arrayLength) {
        setArray(data.ensure(newLength - 1).safeDelete(arrayLength, newLength - 1, false));
        return;
    }

    if (newLength < arrayLength) {
       long actualLength = newLength;

       // Check for numeric keys in property map and delete them or adjust length, depending on whether
       // they're defined as configurable. See ES5 #15.4.5.2
       if (getMap().containsArrayKeys()) {

           for (long l = arrayLength - 1; l >= newLength; l--) {
               final FindProperty find = findProperty(JSType.toString(l), false);

               if (find != null) {

                   if (find.getProperty().isConfigurable()) {
                       deleteOwnProperty(find.getProperty());
                   } else {
                       actualLength = l + 1;
                       break;
                   }
               }
           }
       }

       setArray(data.shrink(actualLength));
       data.setLength(actualLength);
   }
}
 
Example 7
Source File: ScriptObject.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
  * Numeric length setter for length property
  *
  * @param newLength new length to set
  */
public final void setLength(final long newLength) {
    ArrayData data = getArray();
    final long arrayLength = data.length();
    if (newLength == arrayLength) {
        return;
    }

    if (newLength > arrayLength) {
        data = data.ensure(newLength - 1);
        if (data.canDelete(arrayLength, newLength - 1, false)) {
           data = data.delete(arrayLength, newLength - 1);
        }
        setArray(data);
        return;
    }

    if (newLength < arrayLength) {
       long actualLength = newLength;

       // Check for numeric keys in property map and delete them or adjust length, depending on whether
       // they're defined as configurable. See ES5 #15.4.5.2
       if (getMap().containsArrayKeys()) {

           for (long l = arrayLength - 1; l >= newLength; l--) {
               final FindProperty find = findProperty(JSType.toString(l), false);

               if (find != null) {

                   if (find.getProperty().isConfigurable()) {
                       deleteOwnProperty(find.getProperty());
                   } else {
                       actualLength = l + 1;
                       break;
                   }
               }
           }
       }

       setArray(data.shrink(actualLength));
       data.setLength(actualLength);
   }
}