Java Code Examples for jdk.nashorn.internal.objects.annotations.Where#CONSTRUCTOR

The following examples show how to use jdk.nashorn.internal.objects.annotations.Where#CONSTRUCTOR . 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: NativeError.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
 */
@SuppressWarnings("unused")
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object captureStackTrace(final Object self, final Object errorObj) {
    Global.checkObject(errorObj);
    final ScriptObject sobj = (ScriptObject)errorObj;
    new ECMAException(sobj, null); //constructor has side effects
    sobj.delete("stack", false);
    final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK);
    final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK);
    sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
    return UNDEFINED;
}
 
Example 2
Source File: NativeDebug.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Expands the event queue capacity, or truncates if capacity is lower than
 * current capacity. Then only the newest entries are kept
 * @param self self reference
 * @param newCapacity new capacity
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void expandEventQueueCapacity(final Object self, final Object newCapacity) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int nc = JSType.toInt32(newCapacity);
    while (q.size() > nc) {
        q.removeFirst();
    }
    setEventQueueCapacity(self, nc);
}
 
Example 3
Source File: NativeObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.3.12 Object.isFrozen ( O )
 *
 * @param self self reference
 * @param obj check whether an object
 * @return true if object is frozen, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static boolean isFrozen(final Object self, final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).isFrozen();
    } else if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).isFrozen();
    } else {
        throw notAnObject(obj);
    }
}
 
Example 4
Source File: NativeObject.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.3.9 Object.freeze ( O )
 *
 * @param self self reference
 * @param obj object to freeze
 * @return frozen object
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object freeze(final Object self, final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).freeze();
    } else if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).freeze();
    } else {
        throw notAnObject(obj);
    }
}
 
Example 5
Source File: NativeObject.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.3.8 Object.seal ( O )
 *
 * @param self self reference
 * @param obj  object to seal
 * @return sealed object
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object seal(final Object self, final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).seal();
    } else if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).seal();
    } else {
        throw notAnObject(obj);
    }
}
 
Example 6
Source File: NativeDate.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.9.4.3 Date.UTC (year, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] )
 *
 * @param self self reference
 * @param args mandatory args are year, month. Optional are date, hours, minutes, seconds and milliseconds
 * @return a time clip according to the ECMA specification
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 7, where = Where.CONSTRUCTOR)
public static double UTC(final Object self, final Object... args) {
    final NativeDate nd = new NativeDate(0);
    final double[] d = convertCtorArgs(args);
    final double time = d == null ? Double.NaN : timeClip(makeDate(d));
    nd.setTime(time);
    return time;
}
 
Example 7
Source File: NativeDebug.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a runtime event to the runtime event queue. The queue has a fixed
 * size {@link RuntimeEvent#RUNTIME_EVENT_QUEUE_SIZE} and the oldest
 * entry will be thrown out of the queue is about to overflow
 * @param self self reference
 * @param event event to add
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void addRuntimeEvent(final Object self, final Object event) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int cap = (Integer)getEventQueueCapacity(self);
    while (q.size() >= cap) {
        q.removeFirst();
    }
    q.addLast(getEvent(event));
}
 
Example 8
Source File: NativeObject.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.3.8 Object.seal ( O )
 *
 * @param self self reference
 * @param obj  object to seal
 * @return sealed object
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object seal(final Object self, final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).seal();
    } else if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).seal();
    } else {
        throw notAnObject(obj);
    }
}
 
Example 9
Source File: NativeDebug.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the ArrayData class for this ScriptObject
 * @param self self
 * @param obj script object to check
 * @return ArrayData class, or undefined if no ArrayData is present
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getArrayDataClass(final Object self, final Object obj) {
    try {
        return ((ScriptObject)obj).getArray().getClass();
    } catch (final ClassCastException e) {
        return ScriptRuntime.UNDEFINED;
    }
}
 
Example 10
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$8 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$8")
public static Object getGroup8(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(8);
}
 
Example 11
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$5 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$5")
public static Object getGroup5(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(5);
}
 
Example 12
Source File: NativeRegExp.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$6 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$6")
public static Object getGroup6(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(6);
}
 
Example 13
Source File: NativeRegExp.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$8 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$8")
public static Object getGroup8(Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(8);
}
 
Example 14
Source File: NativeDebug.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a diagnostic string representing the difference of two property maps.
 * @param self self
 * @param m1 first property map
 * @param m2 second property map
 * @return a diagnostic string representing the difference of two property maps.
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object diffPropertyMaps(final Object self, final Object m1, final Object m2) {
    return PropertyMap.diff((PropertyMap)m1, (PropertyMap)m2);
}
 
Example 15
Source File: NativeMath.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * ECMA 15.8.2.9 floor(x)
 *
 * @param self  self reference
 * @param x     argument
 *
 * @return floor of argument
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static double floor(final Object self, final Object x) {
    return Math.floor(JSType.toNumber(x));
}
 
Example 16
Source File: NativeDate.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * ECMA 15.9.4.4 Date.now ( )
 *
 * @param self self reference
 * @return a Date that points to the current moment in time
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static long now(final Object self) {
    return System.currentTimeMillis();
}
 
Example 17
Source File: NativeMath.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * ECMA 15.8.2.14 random()
 *
 * @param self  self reference
 *
 * @return random number in the range [0..1)
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static double random(final Object self) {
    return Math.random();
}
 
Example 18
Source File: NativeMath.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * ECMA 15.8.2.10 log(x)
 *
 * @param self  self reference
 * @param x     argument
 *
 * @return log of argument
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object log(final Object self, final Object x) {
    return Math.log(JSType.toNumber(x));
}
 
Example 19
Source File: NativeMath.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * ECMA 15.8.2.16 sin(x)
 *
 * @param self  self reference
 * @param x     argument
 *
 * @return sin of x
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static double sin(final Object self, final Object x) {
    return Math.sin(JSType.toNumber(x));
}
 
Example 20
Source File: NativeMath.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * ECMA 15.8.2.18 tan(x)
 *
 * @param self  self reference
 * @param x     argument
 *
 * @return tan of x
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where=Where.CONSTRUCTOR)
public static double tan(final Object self, final Object x) {
    return Math.tan(JSType.toNumber(x));
}