本文整理汇总了Java中jdk.nashorn.internal.runtime.Property.hasGetterFunction方法的典型用法代码示例。如果您正苦于以下问题:Java Property.hasGetterFunction方法的具体用法?Java Property.hasGetterFunction怎么用?Java Property.hasGetterFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.Property
的用法示例。
在下文中一共展示了Property.hasGetterFunction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPropertyType
import jdk.nashorn.internal.runtime.Property; //导入方法依赖的package包/类
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));
}
示例2: evaluatePropertySafely
import jdk.nashorn.internal.runtime.Property; //导入方法依赖的package包/类
private static Object evaluatePropertySafely(final ScriptObject sobj, final String name) {
final FindProperty find = sobj.findProperty(name, true);
if (find == null) {
return null;
}
final Property property = find.getProperty();
final ScriptObject owner = find.getOwner();
if (property.hasGetterFunction(owner)) {
// Possible side effects; can't evaluate safely
return null;
}
return property.getObjectValue(owner, owner);
}