Java Code Examples for jdk.nashorn.internal.objects.annotations.Attribute#NOT_ENUMERABLE

The following examples show how to use jdk.nashorn.internal.objects.annotations.Attribute#NOT_ENUMERABLE . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * ECMA 15.5.4.8 String.prototype.lastIndexOf (searchString, position)
 * @param self   self reference
 * @param search string to search for
 * @param pos    position to start search
 * @return last position of match or -1
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static int lastIndexOf(final Object self, final Object search, final Object pos) {

    final String str       = checkObjectToString(self);
    final String searchStr = JSType.toString(search);
    final int length       = str.length();

    int end;

    if (pos == UNDEFINED) {
        end = length;
    } else {
        final double numPos = JSType.toNumber(pos);
        end = Double.isNaN(numPos) ? length : (int)numPos;
        if (end < 0) {
            end = 0;
        } else if (end > length) {
            end = length;
        }
    }


    return str.lastIndexOf(searchStr, end);
}
 
Example 2
/**
 * ECMA 15.2.3.2 Object.getPrototypeOf ( O )
 *
 * @param  self self reference
 * @param  obj object to get prototype from
 * @return the prototype of an object
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getPrototypeOf(final Object self, final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).getProto();
    } else if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).getProto();
    } else {
        final JSType type = JSType.of(obj);
        if (type == JSType.OBJECT) {
            // host (Java) objects have null __proto__
            return null;
        }

        // must be some JS primitive
        throw notAnObject(obj);
    }
}
 
Example 3
/**
 * Set 8-bit signed int at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to read from
 * @param value byte value to set
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object setInt8(final Object self, final Object byteOffset, final Object value) {
    try {
        getBuffer(self).put(JSType.toInt32(byteOffset), (byte)JSType.toInt32(value));
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example 4
/**
 * Nashorn extension: String.prototype.trimLeft ( )
 * @param self self reference
 * @return string trimmed left from whitespace
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String trimLeft(final Object self) {

    final String str = checkObjectToString(self);
    int start = 0;
    final int end   = str.length() - 1;

    while (start <= end && ScriptRuntime.isJSWhitespace(str.charAt(start))) {
        start++;
    }

    return str.substring(start, end + 1);
}
 
Example 5
/**
 * Nashorn extension: Function.prototype.toSource
 *
 * @param self self reference
 * @return source for function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String toSource(final Object self) {
    if (!(self instanceof ScriptFunction)) {
        throw typeError("not.a.function", ScriptRuntime.safeToString(self));
    }
    return ((ScriptFunction)self).toSource();
}
 
Example 6
/**
 * Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided.
 *
 * @param self self reference
 * @param errorObj the error object
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object captureStackTrace(final Object self, final Object errorObj) {
    final ScriptObject sobj = Global.checkObject(errorObj);
    initException(sobj);
    sobj.delete(STACK, false);
    if (! sobj.has("stack")) {
        final ScriptFunction getStack = ScriptFunction.createBuiltin("getStack", GET_STACK);
        final ScriptFunction setStack = ScriptFunction.createBuiltin("setStack", SET_STACK);
        sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
    }
    return UNDEFINED;
}
 
Example 7
/**
 * Get the capacity of the event queue
 * @param self self reference
 * @return capacity of event queue as an integer
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getEventQueueCapacity(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    Integer cap;
    if (sobj.has(EVENT_QUEUE_CAPACITY)) {
        cap = JSType.toInt32(sobj.get(EVENT_QUEUE_CAPACITY));
    } else {
        setEventQueueCapacity(self, cap = RuntimeEvent.RUNTIME_EVENT_QUEUE_SIZE);
    }
    return cap;
}
 
Example 8
/**
 * Get 16-bit signed int from given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to read from
 * @param littleEndian (optional) flag indicating whether to read in little endian order
 * @return 16-bit signed int value at the byteOffset
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static int getInt16(final Object self, final Object byteOffset, final Object littleEndian) {
    try {
        return getBuffer(self, littleEndian).getShort(JSType.toInt32(byteOffset));
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example 9
/**
 * "No such property" handler.
 *
 * @param self self reference
 * @param name property name
 * @return value of the missing property
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object __noSuchProperty__(final Object self, final Object name) {
    if (! (self instanceof NativeJavaImporter)) {
        throw typeError("not.a.java.importer", ScriptRuntime.safeToString(self));
    }
    return ((NativeJavaImporter)self).createProperty(JSType.toString(name));
}
 
Example 10
/**
 * Setter for ECMA 15.12 - The JSON property
 * @param self self reference
 * @param value value for the JSON property
 */
@Setter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
public static void setJSON(final Object self, final Object value) {
    final Global global = Global.instanceFrom(self);
    global.json = value;
}
 
Example 11
/**
 * ECMA 15.9.5.38 Date.prototype.setMonth (month [, date ] )
 *
 * @param self self reference
 * @param args month (optional second argument is date)
 * @return time
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static double setMonth(final Object self, final Object... args) {
    final NativeDate nd = getNativeDate(self);
    setFields(nd, MONTH, args, true);
    return nd.getTime();
}
 
Example 12
/**
 * ECMA 6 19.4.3.2 Symbol.prototype.toString ( )
 *
 * @param self self reference
 * @return localized string for this Number
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String toString(final Object self) {
    return getSymbolValue(self).toString();
}
 
Example 13
/**
 * Set values
 * @param self   self reference
 * @param array  multiple values of array's type to set
 * @param offset optional start index, interpreted  0 if undefined
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
protected static Object set(final Object self, final Object array, final Object offset) {
    return ArrayBufferView.setImpl(self, array, offset);
}
 
Example 14
/**
 * ECMA 15.8.2.2 acos(x)
 *
 * @param self  self reference
 * @param x     argument
 *
 * @return acos of argument
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static double acos(final Object self, final Object x) {
    return Math.acos(JSType.toNumber(x));
}
 
Example 15
/**
 * Returns an object that is compatible with Java JSON libraries expectations; namely, that if it itself, or any
 * object transitively reachable through it is a JavaScript array, then such objects will be exposed as
 * {@link JSObject} that also implements the {@link List} interface for exposing the array elements. An explicit
 * API is required as otherwise Nashorn exposes all objects externally as {@link JSObject}s that also implement the
 * {@link Map} interface instead. By using this method, arrays will be exposed as {@link List}s and all other
 * objects as {@link Map}s.
 * @param self not used
 * @param obj the object to be exposed in a Java JSON library compatible manner.
 * @return a wrapper around the object that will enforce Java JSON library compatible exposure.
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object asJSONCompatible(final Object self, final Object obj) {
    return ScriptObjectMirror.wrapAsJSONCompatible(obj, Context.getGlobal());
}
 
Example 16
/**
 * ECMA 15.9.5.6 Date.prototype.toLocaleDateString ( )
 *
 * @param self self reference
 * @return string value with the "date" part of the Date in the current time zone and locale
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String toLocaleDateString(final Object self) {
    return toStringImpl(self, FORMAT_LOCAL_DATE);
}
 
Example 17
/**
 * ECMA 15.9.5.43 Date.prototype.toISOString ( )
 *
 * @param self self reference
 * @return string representation of date
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String toISOString(final Object self) {
    return toISOStringImpl(self);
}
 
Example 18
/**
 * Returns the property listener count for a script object
 *
 * @param self self reference
 * @param obj  script object whose listener count is returned
 * @return listener count
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static int getListenerCount(final Object self, final Object obj) {
    return (obj instanceof ScriptObject) ? PropertyListeners.getListenerCount((ScriptObject) obj) : 0;
}
 
Example 19
/**
 * ECMA 15.9.5.9 Date.prototype.getTime ( )
 *
 * @param self self reference
 * @return time
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double getTime(final Object self) {
    final NativeDate nd = getNativeDate(self);
    return (nd != null) ? nd.getTime() : Double.NaN;
}
 
Example 20
/**
 * ECMA 15.5.4.16 String.prototype.toLowerCase ( )
 * @param self self reference
 * @return string to lower case
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String toLowerCase(final Object self) {
    return checkObjectToString(self).toLowerCase(Locale.ROOT);
}