Java Code Examples for jdk.nashorn.internal.runtime.FindProperty#getOwner()

The following examples show how to use jdk.nashorn.internal.runtime.FindProperty#getOwner() . 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: TypeEvaluator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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));
}
 
Example 2
Source File: TypeEvaluator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 3
Source File: TypeEvaluator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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));
}
 
Example 4
Source File: TypeEvaluator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: TypeEvaluator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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));
}
 
Example 6
Source File: TypeEvaluator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: TypeEvaluator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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));
}
 
Example 8
Source File: TypeEvaluator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: TypeEvaluator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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));
}
 
Example 10
Source File: TypeEvaluator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: TypeEvaluator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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));
}
 
Example 12
Source File: TypeEvaluator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: TypeEvaluator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
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));
}
 
Example 14
Source File: TypeEvaluator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
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);
}