本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED属性的典型用法代码示例。如果您正苦于以下问题:Java ScriptRuntime.UNDEFINED属性的具体用法?Java ScriptRuntime.UNDEFINED怎么用?Java ScriptRuntime.UNDEFINED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类jdk.nashorn.internal.runtime.ScriptRuntime
的用法示例。
在下文中一共展示了ScriptRuntime.UNDEFINED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: join
/**
* ECMA 15.4.4.5 Array.prototype.join (separator)
*
* @param self self reference
* @param separator element separator
* @return string representation after join
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String join(final Object self, final Object separator) {
final StringBuilder sb = new StringBuilder();
final Iterator<Object> iter = arrayLikeIterator(self, true);
final String sep = separator == ScriptRuntime.UNDEFINED ? "," : JSType.toString(separator);
while (iter.hasNext()) {
final Object obj = iter.next();
if (obj != null && obj != ScriptRuntime.UNDEFINED) {
sb.append(JSType.toString(obj));
}
if (iter.hasNext()) {
sb.append(sep);
}
}
return sb.toString();
}
示例2: fastPopObject
@Override
public Object fastPopObject() {
if (length() == 0) {
return ScriptRuntime.UNDEFINED;
}
final int newLength = (int)decreaseLength();
final Object elem = array[newLength];
array[newLength] = ScriptRuntime.EMPTY;
return elem;
}
示例3: isCallable
/**
* Returns if the given object is a "callable"
* @param obj object to be checked for callability
* @return true if the obj is callable
*/
public static boolean isCallable(final Object obj) {
if (obj == ScriptRuntime.UNDEFINED || obj == null) {
return false;
}
return obj instanceof ScriptFunction ||
isJSObjectFunction(obj) ||
BeansLinker.isDynamicMethod(obj) ||
obj instanceof BoundCallable ||
isFunctionalInterfaceObject(obj) ||
obj instanceof StaticClass;
}
示例4: pop
/**
* ECMA 15.4.4.6 Array.prototype.pop ()
*
* @param self self reference
* @return array after pop
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object pop(final Object self) {
try {
final ScriptObject sobj = (ScriptObject)self;
if (bulkable(sobj)) {
return sobj.getArray().pop();
}
final long len = JSType.toUint32(sobj.getLength());
if (len == 0) {
sobj.set("length", 0, CALLSITE_STRICT);
return ScriptRuntime.UNDEFINED;
}
final long index = len - 1;
final Object element = sobj.get(index);
sobj.delete(index, true);
sobj.set("length", index, CALLSITE_STRICT);
return element;
} catch (final ClassCastException | NullPointerException e) {
throw typeError("not.an.object", ScriptRuntime.safeToString(self));
}
}
示例5: set
@Override
public ArrayData set(final int index, final Object value, final boolean strict) {
if (JSType.isRepresentableAsInt(value)) {
return set(index, JSType.toInt32(value), strict);
} else if (value == ScriptRuntime.UNDEFINED) {
return new UndefinedArrayFilter(this).set(index, value, strict);
}
final ArrayData newData = convert(value == null ? Object.class : value.getClass());
return newData.set(index, value, strict);
}
示例6: pop
@Override
public Object pop() {
final int index = (int)length() - 1;
if (super.has(index)) {
final boolean isDeleted = isDeleted(index);
final Object value = super.pop();
lo = Math.min(index + 1, lo);
hi = Math.min(index, hi);
return isDeleted ? ScriptRuntime.UNDEFINED : value;
}
return super.pop();
}
示例7: compareFunction
private static ScriptFunction compareFunction(final Object comparefn) {
if (comparefn == ScriptRuntime.UNDEFINED) {
return null;
}
if (! (comparefn instanceof ScriptFunction)) {
throw typeError("not.a.function", ScriptRuntime.safeToString(comparefn));
}
return (ScriptFunction)comparefn;
}
示例8: sort
private static Object[] sort(final Object[] array, final Object comparefn) {
final ScriptFunction cmp = compareFunction(comparefn);
final List<Object> list = Arrays.asList(array);
final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Global.instance();
Collections.sort(list, new Comparator<Object>() {
private final MethodHandle call_cmp = getCALL_CMP();
@Override
public int compare(final Object x, final Object y) {
if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) {
return 0;
} else if (x == ScriptRuntime.UNDEFINED) {
return 1;
} else if (y == ScriptRuntime.UNDEFINED) {
return -1;
}
if (cmp != null) {
try {
return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y));
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
}
}
return JSType.toString(x).compareTo(JSType.toString(y));
}
});
return list.toArray(new Object[array.length]);
}
示例9: getPropertyType
private static Type getPropertyType(final ScriptObject sobj, final String name) {
final FindProperty find = sobj.findProperty(name, true);
if (find == null) {
return null;
}
final Property property = find.getProperty();
final Class<?> propertyClass = property.getType();
if (propertyClass == null) {
// propertyClass == null means its value is Undefined. It is probably not initialized yet, so we won't make
// a type assumption yet.
return null;
} else if (propertyClass.isPrimitive()) {
return Type.typeFor(propertyClass);
}
final ScriptObject owner = find.getOwner();
if (property.hasGetterFunction(owner)) {
// Can have side effects, so we can't safely evaluate it; since !propertyClass.isPrimitive(), it's Object.
return Type.OBJECT;
}
// Safely evaluate the property, and return the narrowest type for the actual value (e.g. Type.INT for a boxed
// integer).
final Object value = property.needsDeclaration() ? ScriptRuntime.UNDEFINED : property.getObjectValue(owner, owner);
if (value == ScriptRuntime.UNDEFINED) {
return null;
}
return Type.typeFor(JSType.unboxedFieldType(value));
}
示例10: reduceInner
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
final Object callbackfn = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
final boolean initialValuePresent = args.length > 1;
Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;
if (callbackfn == ScriptRuntime.UNDEFINED) {
throw typeError("not.a.function", "undefined");
}
if (!initialValuePresent) {
if (iter.hasNext()) {
initialValue = iter.next();
} else {
throw typeError("array.reduce.invalid.init");
}
}
//if initial value is ScriptRuntime.UNDEFINED - step forward once.
return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();
@Override
protected boolean forEach(final Object val, final long i) throws Throwable {
// TODO: why can't I declare the second arg as Undefined.class?
result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
return true;
}
}.apply();
}
示例11: asObjectArray
@Override
public Object[] asObjectArray() {
final Object[] value = super.asObjectArray();
if (lo < Integer.MAX_VALUE) {
final int end = (int)Math.min(hi + 1, Integer.MAX_VALUE);
for (int i = (int)lo; i < end; i++) {
value[i] = ScriptRuntime.UNDEFINED;
}
}
return value;
}
示例12: get
private Object get(final long index) {
final Object obj = extraElements.get(index);
if (obj == null) {
return ScriptRuntime.UNDEFINED;
}
return obj;
}
示例13: getArrayData
/**
* Return the ArrayData for this ScriptObject
* @param self self
* @param obj script object to check
* @return ArrayData, ArrayDatas have toString methods, return Undefined if data missing
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getArrayData(final Object self, final Object obj) {
try {
return ((ScriptObject)obj).getArray();
} catch (final ClassCastException e) {
return ScriptRuntime.UNDEFINED;
}
}
示例14: translateUndefined
static Object translateUndefined(final Object obj) {
return (obj == ScriptRuntime.UNDEFINED)? null : obj;
}
示例15: pop
@Override
public Object pop() {
return ScriptRuntime.UNDEFINED;
}