本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptRuntime.EMPTY_ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java ScriptRuntime.EMPTY_ARRAY属性的具体用法?Java ScriptRuntime.EMPTY_ARRAY怎么用?Java ScriptRuntime.EMPTY_ARRAY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类jdk.nashorn.internal.runtime.ScriptRuntime
的用法示例。
在下文中一共展示了ScriptRuntime.EMPTY_ARRAY属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
/**
* 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");
}
示例2: bind
/**
* ECMA 15.3.4.5 Function.prototype.bind (thisArg [, arg1 [, arg2, ...]])
*
* @param self self reference
* @param args arguments for bind
* @return function with bound arguments
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object bind(final Object self, final Object... args) {
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;
}
return Bootstrap.bindCallable(self, thiz, arguments);
}
示例3: getStackTrace
/**
* 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);
}
示例4: splice
/**
* ECMA 15.4.4.12 Array.prototype.splice ( start, deleteCount [ item1 [ , item2 [ , ... ] ] ] )
*
* @param self self reference
* @param args arguments
* @return result of splice
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object splice(final Object self, final Object... args) {
final Object obj = Global.toObject(self);
if (!(obj instanceof ScriptObject)) {
return ScriptRuntime.UNDEFINED;
}
final Object start = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
final Object deleteCount = args.length > 1 ? args[1] : ScriptRuntime.UNDEFINED;
Object[] items;
if (args.length > 2) {
items = new Object[args.length - 2];
System.arraycopy(args, 2, items, 0, items.length);
} else {
items = ScriptRuntime.EMPTY_ARRAY;
}
final ScriptObject sobj = (ScriptObject)obj;
final long len = JSType.toUint32(sobj.getLength());
final long relativeStart = JSType.toLong(start);
final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
final long actualDeleteCount = Math.min(Math.max(JSType.toLong(deleteCount), 0), len - actualStart);
NativeArray returnValue;
if (actualStart <= Integer.MAX_VALUE && actualDeleteCount <= Integer.MAX_VALUE && bulkable(sobj)) {
try {
returnValue = new NativeArray(sobj.getArray().fastSplice((int)actualStart, (int)actualDeleteCount, items.length));
// Since this is a dense bulkable array we can use faster defineOwnProperty to copy new elements
int k = (int) actualStart;
for (int i = 0; i < items.length; i++, k++) {
sobj.defineOwnProperty(k, items[i]);
}
} catch (final UnsupportedOperationException uoe) {
returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
}
} else {
returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
}
return returnValue;
}
示例5: BoundCallable
BoundCallable(final Object callable, final Object boundThis, final Object[] boundArgs) {
this.callable = callable;
this.boundThis = boundThis;
this.boundArgs = isEmptyArray(boundArgs) ? ScriptRuntime.EMPTY_ARRAY : boundArgs.clone();
}
示例6: asObjectArray
@Override
public Object[] asObjectArray() {
return ScriptRuntime.EMPTY_ARRAY;
}
示例7: splice
/**
* ECMA 15.4.4.12 Array.prototype.splice ( start, deleteCount [ item1 [ , item2 [ , ... ] ] ] )
*
* @param self self reference
* @param args arguments
* @return result of splice
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object splice(final Object self, final Object... args) {
final Object obj = Global.toObject(self);
if (!(obj instanceof ScriptObject)) {
return ScriptRuntime.UNDEFINED;
}
final ScriptObject sobj = (ScriptObject)obj;
final long len = JSType.toUint32(sobj.getLength());
final long relativeStart = JSType.toLong(args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED);
final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
final long actualDeleteCount;
Object[] items = ScriptRuntime.EMPTY_ARRAY;
if (args.length == 0) {
actualDeleteCount = 0;
} else if (args.length == 1) {
actualDeleteCount = len - actualStart;
} else {
actualDeleteCount = Math.min(Math.max(JSType.toLong(args[1]), 0), len - actualStart);
if (args.length > 2) {
items = new Object[args.length - 2];
System.arraycopy(args, 2, items, 0, items.length);
}
}
NativeArray returnValue;
if (actualStart <= Integer.MAX_VALUE && actualDeleteCount <= Integer.MAX_VALUE && bulkable(sobj)) {
try {
returnValue = new NativeArray(sobj.getArray().fastSplice((int)actualStart, (int)actualDeleteCount, items.length));
// Since this is a dense bulkable array we can use faster defineOwnProperty to copy new elements
int k = (int) actualStart;
for (int i = 0; i < items.length; i++, k++) {
sobj.defineOwnProperty(k, items[i]);
}
} catch (final UnsupportedOperationException uoe) {
returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
}
} else {
returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
}
return returnValue;
}