本文整理汇总了Java中jdk.nashorn.internal.objects.annotations.Function类的典型用法代码示例。如果您正苦于以下问题:Java Function类的具体用法?Java Function怎么用?Java Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Function类属于jdk.nashorn.internal.objects.annotations包,在下文中一共展示了Function类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addRuntimeEvent
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* 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));
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:NativeDebug.java
示例2: expandEventQueueCapacity
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* 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);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:NativeDebug.java
示例3: create
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.2.3.5 Object.create ( O [, Properties] )
*
* @param self self reference
* @param proto prototype object
* @param props properties to define
* @return object created
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static ScriptObject create(final Object self, final Object proto, final Object props) {
if (proto != null) {
Global.checkObject(proto);
}
// FIXME: should we create a proper object with correct number of
// properties?
final ScriptObject newObj = Global.newEmptyInstance();
newObj.setProto((ScriptObject)proto);
if (props != UNDEFINED) {
NativeObject.defineProperties(self, newObj, props);
}
return newObj;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:NativeObject.java
示例4: toString
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.4.4.2 Array.prototype.toString ( )
*
* @param self self reference
* @return string representation of array
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object toString(final Object self) {
final Object obj = Global.toObject(self);
if (obj instanceof ScriptObject) {
final InvokeByName joinInvoker = getJOIN();
final ScriptObject sobj = (ScriptObject)obj;
try {
final Object join = joinInvoker.getGetter().invokeExact(sobj);
if (Bootstrap.isCallable(join)) {
return joinInvoker.getInvoker().invokeExact(join, sobj);
}
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
}
}
// FIXME: should lookup Object.prototype.toString and call that?
return ScriptRuntime.builtinObjectToString(self);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:NativeArray.java
示例5: setFullYear
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.9.5.40 Date.prototype.setFullYear (year [, month [, date ] ] )
*
* @param self self reference
* @param args year (optional second and third arguments are month and date)
* @return time
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
public static double setFullYear(final Object self, final Object... args) {
final NativeDate nd = ensureNativeDate(self);
if (nd.isValidDate()) {
setFields(nd, YEAR, args, true);
} else {
final double[] d = convertArgs(args, 0, YEAR, YEAR, 3);
if (d != null) {
nd.setTime(timeClip(utc(makeDate(makeDay(d[0], d[1], d[2]), 0), nd.getTimeZone())));
} else {
nd.setTime(NaN);
}
}
return nd.getTime();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:NativeDate.java
示例6: call
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.3.4.4 Function.prototype.call (thisArg [ , arg1 [ , arg2, ... ] ] )
*
* @param self self reference
* @param args arguments for call
* @return result of call
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object call(final Object self, final Object... args) {
checkCallable(self);
final Object thiz = (args.length == 0) ? UNDEFINED : args[0];
Object[] arguments;
if (args.length > 1) {
arguments = new Object[args.length - 1];
System.arraycopy(args, 1, arguments, 0, arguments.length);
} else {
arguments = ScriptRuntime.EMPTY_ARRAY;
}
if (self instanceof ScriptFunction) {
return ScriptRuntime.apply((ScriptFunction)self, thiz, arguments);
} else if (self instanceof JSObject) {
return ((JSObject)self).call(thiz, arguments);
}
throw new AssertionError("should not reach here");
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:NativeFunction.java
示例7: push
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.4.4.7 Array.prototype.push (args...)
*
* @param self self reference
* @param args arguments to push
* @return array length after pushes
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object push(final Object self, final Object... args) {
try {
final ScriptObject sobj = (ScriptObject)self;
if (bulkable(sobj) && sobj.getArray().length() + args.length <= JSType.MAX_UINT) {
final ArrayData newData = sobj.getArray().push(true, args);
sobj.setArray(newData);
return newData.length();
}
long len = JSType.toUint32(sobj.getLength());
for (final Object element : args) {
sobj.set(len++, element, CALLSITE_STRICT);
}
sobj.set("length", len, CALLSITE_STRICT);
return len;
} catch (final ClassCastException | NullPointerException e) {
throw typeError(Context.getGlobal(), e, "not.an.object", ScriptRuntime.safeToString(self));
}
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:NativeArray.java
示例8: concat
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.4.4.4 Array.prototype.concat ( [ item1 [ , item2 [ , ... ] ] ] )
*
* @param self self reference
* @param args arguments
* @return resulting NativeArray
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray concat(final Object self, final Object... args) {
final ArrayList<Object> list = new ArrayList<>();
concatToList(list, Global.toObject(self));
for (final Object obj : args) {
concatToList(list, obj);
}
return new NativeArray(list.toArray());
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:NativeArray.java
示例9: getStackTrace
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* Nashorn extension: Error.prototype.getStackTrace()
* "stack" property is an array typed value containing {@link StackTraceElement}
* objects of JavaScript stack frames.
*
* @param self self reference
*
* @return stack trace as a script array.
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object getStackTrace(final Object self) {
final ScriptObject sobj = Global.checkObject(self);
final Object exception = ECMAException.getException(sobj);
Object[] res;
if (exception instanceof Throwable) {
res = NashornException.getScriptFrames((Throwable)exception);
} else {
res = ScriptRuntime.EMPTY_ARRAY;
}
return new NativeArray(res);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:NativeError.java
示例10: getInt16
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* 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");
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:NativeDataView.java
示例11: toString
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.7.4.2 Number.prototype.toString ( [ radix ] )
*
* @param self self reference
* @param radix radix to use for string conversion
* @return string representation of this Number in the given radix
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String toString(final Object self, final Object radix) {
if (radix != UNDEFINED) {
final int intRadix = JSType.toInteger(radix);
if (intRadix != 10) {
if (intRadix < 2 || intRadix > 36) {
throw rangeError("invalid.radix");
}
return JSType.toString(getNumberValue(self), intRadix);
}
}
return JSType.toString(getNumberValue(self));
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:NativeNumber.java
示例12: localeCompare
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.5.4.9 String.prototype.localeCompare (that)
* @param self self reference
* @param that comparison object
* @return result of locale sensitive comparison operation between {@code self} and {@code that}
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {
final String str = checkObjectToString(self);
final Collator collator = Collator.getInstance(Global.getEnv()._locale);
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return collator.compare(str, JSType.toString(that));
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:NativeString.java
示例13: getOwnPropertySymbols
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 2 19.1.2.8 Object.getOwnPropertySymbols ( O )
*
* @param self self reference
* @param obj object to query for property names
* @return array of property names
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static ScriptObject getOwnPropertySymbols(final Object self, final Object obj) {
if (obj instanceof ScriptObject) {
return new NativeArray(((ScriptObject)obj).getOwnSymbols(true));
} else {
// TODO: we don't support this on ScriptObjectMirror objects yet
throw notAnObject(obj);
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:NativeObject.java
示例14: slice
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.5.4.13 String.prototype.slice (start, end)
*
* @param self self reference
* @param start start position for slice
* @param end end position for slice
* @return sliced out substring
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String slice(final Object self, final Object start, final Object end) {
final String str = checkObjectToString(self);
if (end == UNDEFINED) {
return slice(str, JSType.toInteger(start));
}
return slice(str, JSType.toInteger(start), JSType.toInteger(end));
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:NativeString.java
示例15: next
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ES6 23.1.5.2.1 %MapIteratorPrototype%.next()
*
* @param self the self reference
* @param arg the argument
* @return the next result
*/
@Function
public static Object next(final Object self, final Object arg) {
if (!(self instanceof MapIterator)) {
throw typeError("not.a.map.iterator", ScriptRuntime.safeToString(self));
}
return ((MapIterator)self).next(arg);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:MapIterator.java
示例16: defineProperties
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 5.2.3.7 Object.defineProperties ( O, Properties )
*
* @param self self reference
* @param obj object in which to define properties
* @param props properties
* @return object
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static ScriptObject defineProperties(final Object self, final Object obj, final Object props) {
final ScriptObject sobj = Global.checkObject(obj);
final Object propsObj = Global.toObject(props);
if (propsObj instanceof ScriptObject) {
final Object[] keys = ((ScriptObject)propsObj).getOwnKeys(false);
for (final Object key : keys) {
final String prop = JSType.toString(key);
sobj.defineOwnProperty(prop, ((ScriptObject)propsObj).get(prop), true);
}
}
return sobj;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:NativeObject.java
示例17: fromCharCode
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.5.3.2 String.fromCharCode ( [ char0 [ , char1 [ , ... ] ] ] )
* @param self self reference
* @param args array of arguments to be interpreted as char
* @return string with arguments translated to charcodes
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1, where = Where.CONSTRUCTOR)
public static String fromCharCode(final Object self, final Object... args) {
final char[] buf = new char[args.length];
int index = 0;
for (final Object arg : args) {
buf[index++] = (char)JSType.toUint16(arg);
}
return new String(buf);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:NativeString.java
示例18: setPrototypeOf
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* Nashorn extension: Object.setPrototypeOf ( O, proto )
* Also found in ES6 draft specification.
*
* @param self self reference
* @param obj object to set prototype for
* @param proto prototype object to be used
* @return object whose prototype is set
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object setPrototypeOf(final Object self, final Object obj, final Object proto) {
if (obj instanceof ScriptObject) {
((ScriptObject)obj).setPrototypeOf(proto);
return obj;
} else if (obj instanceof ScriptObjectMirror) {
((ScriptObjectMirror)obj).setProto(proto);
return obj;
}
throw notAnObject(obj);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:NativeObject.java
示例19: substring
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* ECMA 15.5.4.15 String.prototype.substring (start, end)
*
* @param self self reference
* @param start start position of substring
* @param end end position of substring
* @return substring given start and end indexes
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String substring(final Object self, final Object start, final Object end) {
final String str = checkObjectToString(self);
if (end == UNDEFINED) {
return substring(str, JSType.toInteger(start));
}
return substring(str, JSType.toInteger(start), JSType.toInteger(end));
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:NativeString.java
示例20: freeze
import jdk.nashorn.internal.objects.annotations.Function; //导入依赖的package包/类
/**
* 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);
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:NativeObject.java
注:本文中的jdk.nashorn.internal.objects.annotations.Function类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论