Java Code Examples for jdk.nashorn.internal.runtime.ScriptObject#getProto()

The following examples show how to use jdk.nashorn.internal.runtime.ScriptObject#getProto() . 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: NativeObject.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.2.4.6 Object.prototype.isPrototypeOf (V)
 *
 * @param self self reference
 * @param v v prototype object to check against
 * @return true if object is prototype of v
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static boolean isPrototypeOf(final Object self, final Object v) {
    if (!(v instanceof ScriptObject)) {
        return false;
    }

    final Object obj   = Global.toObject(self);
    ScriptObject proto = (ScriptObject)v;

    do {
        proto = proto.getProto();
        if (proto == obj) {
            return true;
        }
    } while (proto != null);

    return false;
}
 
Example 2
Source File: NativeObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.2.4.6 Object.prototype.isPrototypeOf (V)
 *
 * @param self self reference
 * @param v v prototype object to check against
 * @return true if object is prototype of v
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static boolean isPrototypeOf(final Object self, final Object v) {
    if (!(v instanceof ScriptObject)) {
        return false;
    }

    final Object obj   = Global.toObject(self);
    ScriptObject proto = (ScriptObject)v;

    do {
        proto = proto.getProto();
        if (proto == obj) {
            return true;
        }
    } while (proto != null);

    return false;
}
 
Example 3
Source File: NativeObject.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.2.4.6 Object.prototype.isPrototypeOf (V)
 *
 * @param self self reference
 * @param v v prototype object to check against
 * @return true if object is prototype of v
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static boolean isPrototypeOf(final Object self, final Object v) {
    if (!(v instanceof ScriptObject)) {
        return false;
    }

    final Object obj   = Global.toObject(self);
    ScriptObject proto = (ScriptObject)v;

    do {
        proto = proto.getProto();
        if (proto == obj) {
            return true;
        }
    } while (proto != null);

    return false;
}
 
Example 4
Source File: NativeObject.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.2.4.6 Object.prototype.isPrototypeOf (V)
 *
 * @param self self reference
 * @param v v prototype object to check against
 * @return true if object is prototype of v
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static boolean isPrototypeOf(final Object self, final Object v) {
    if (!(v instanceof ScriptObject)) {
        return false;
    }

    final Object obj   = Global.toObject(self);
    ScriptObject proto = (ScriptObject)v;

    do {
        proto = proto.getProto();
        if (proto == obj) {
            return true;
        }
    } while (proto != null);

    return false;
}
 
Example 5
Source File: NativeObject.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.2.4.6 Object.prototype.isPrototypeOf (V)
 *
 * @param self self reference
 * @param v v prototype object to check against
 * @return true if object is prototype of v
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static boolean isPrototypeOf(final Object self, final Object v) {
    if (!(v instanceof ScriptObject)) {
        return false;
    }

    final Object obj   = Global.toObject(self);
    ScriptObject proto = (ScriptObject)v;

    do {
        proto = proto.getProto();
        if (proto == obj) {
            return true;
        }
    } while (proto != null);

    return false;
}
 
Example 6
Source File: NativeObject.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.2.4.6 Object.prototype.isPrototypeOf (V)
 *
 * @param self self reference
 * @param v v prototype object to check against
 * @return true if object is prototype of v
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object isPrototypeOf(final Object self, final Object v) {
    if (!(v instanceof ScriptObject)) {
        return false;
    }

    final Object obj   = Global.toObject(self);
    ScriptObject proto = (ScriptObject)v;

    do {
        proto = proto.getProto();
        if (proto == obj) {
            return true;
        }
    } while (proto != null);

    return false;
}
 
Example 7
Source File: Global.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isError(final ScriptObject sobj) {
    final ScriptObject errorProto = getErrorPrototype();
    ScriptObject proto = sobj.getProto();
    while (proto != null) {
        if (proto == errorProto) {
            return true;
        }
        proto = proto.getProto();
    }
    return false;
}
 
Example 8
Source File: NativeArray.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasInheritedArrayEntries(final ScriptObject self) {
    ScriptObject proto = self.getProto();
    while (proto != null) {
        if (proto.hasArrayEntries()) {
            return true;
        }
        proto = proto.getProto();
    }

    return false;
}
 
Example 9
Source File: Global.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * These classes are generated by nasgen tool and so we have to use
 * reflection to load and create new instance of these classes.
 */
private ScriptObject initConstructor(final String name) {
    try {
        // Assuming class name pattern for built-in JS constructors.
        final StringBuilder sb = new StringBuilder("jdk.nashorn.internal.objects.");

        sb.append("Native");
        sb.append(name);
        sb.append("$Constructor");

        final Class<?>     funcClass = Class.forName(sb.toString());
        final ScriptObject res       = (ScriptObject)funcClass.newInstance();

        if (res instanceof ScriptFunction) {
            // All global constructor prototypes are not-writable,
            // not-enumerable and not-configurable.
            final ScriptFunction func = (ScriptFunction)res;
            func.modifyOwnProperty(func.getProperty("prototype"), Attribute.NON_ENUMERABLE_CONSTANT);
        }

        if (res.getProto() == null) {
            res.setProto(getObjectPrototype());
        }

        return res;

    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 10
Source File: NativeArray.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasInheritedArrayEntries(final ScriptObject self) {
    ScriptObject proto = self.getProto();
    while (proto != null) {
        if (proto.hasArrayEntries()) {
            return true;
        }
        proto = proto.getProto();
    }

    return false;
}
 
Example 11
Source File: NativeArray.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasInheritedArrayEntries(final ScriptObject self) {
    ScriptObject proto = self.getProto();
    while (proto != null) {
        if (proto.hasArrayEntries()) {
            return true;
        }
        proto = proto.getProto();
    }

    return false;
}
 
Example 12
Source File: Global.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Is the given ScriptObject an ECMAScript Error object?
 *
 * @param sobj the object being checked
 * @return true if sobj is an Error object
 */
public boolean isError(final ScriptObject sobj) {
    final ScriptObject errorProto = getErrorPrototype();
    ScriptObject proto = sobj.getProto();
    while (proto != null) {
        if (proto == errorProto) {
            return true;
        }
        proto = proto.getProto();
    }
    return false;
}
 
Example 13
Source File: Global.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isError(final ScriptObject sobj) {
    final ScriptObject errorProto = getErrorPrototype();
    ScriptObject proto = sobj.getProto();
    while (proto != null) {
        if (proto == errorProto) {
            return true;
        }
        proto = proto.getProto();
    }
    return false;
}
 
Example 14
Source File: Global.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Is the given ScriptObject an ECMAScript Error object?
 *
 * @param sobj the object being checked
 * @return true if sobj is an Error object
 */
public boolean isError(final ScriptObject sobj) {
    final ScriptObject errorProto = getErrorPrototype();
    ScriptObject proto = sobj.getProto();
    while (proto != null) {
        if (proto == errorProto) {
            return true;
        }
        proto = proto.getProto();
    }
    return false;
}
 
Example 15
Source File: Global.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Is the given ScriptObject an ECMAScript Error object?
 *
 * @param sobj the object being checked
 * @return true if sobj is an Error object
 */
public boolean isError(final ScriptObject sobj) {
    final ScriptObject errorProto = getErrorPrototype();
    ScriptObject proto = sobj.getProto();
    while (proto != null) {
        if (proto == errorProto) {
            return true;
        }
        proto = proto.getProto();
    }
    return false;
}
 
Example 16
Source File: NativeObject.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private static ScriptObject get__proto__(final Object self) {
    // See ES6 draft spec: B.2.2.1.1 get Object.prototype.__proto__
    // Step 1 Let O be the result of calling ToObject passing the this.
    final ScriptObject sobj = Global.checkObject(Global.toObject(self));
    return sobj.getProto();
}
 
Example 17
Source File: NativeArray.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasInheritedArrayEntries(final ScriptObject self) {
    ScriptObject proto = self.getProto();
    while (proto != null) {
        if (proto.hasArrayEntries()) {
            return true;
        }
        proto = proto.getProto();
    }

    return false;
}
 
Example 18
Source File: NativeArray.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasInheritedArrayEntries(final ScriptObject self) {
    ScriptObject proto = self.getProto();
    while (proto != null) {
        if (proto.hasArrayEntries()) {
            return true;
        }
        proto = proto.getProto();
    }

    return false;
}
 
Example 19
Source File: NativeObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private static ScriptObject get__proto__(final Object self) {
    // See ES6 draft spec: B.2.2.1.1 get Object.prototype.__proto__
    // Step 1 Let O be the result of calling ToObject passing the this.
    final ScriptObject sobj = Global.checkObject(Global.toObject(self));
    return sobj.getProto();
}
 
Example 20
Source File: NativeArray.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasInheritedArrayEntries(final ScriptObject self) {
    ScriptObject proto = self.getProto();
    while (proto != null) {
        if (proto.hasArrayEntries()) {
            return true;
        }
        proto = proto.getProto();
    }

    return false;
}