Java Code Examples for jdk.nashorn.internal.runtime.ScriptFunction#modifyOwnProperty()

The following examples show how to use jdk.nashorn.internal.runtime.ScriptFunction#modifyOwnProperty() . 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: Global.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) {
    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 T res = clazz.cast(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.setInitialProto(getObjectPrototype());
        }

        res.setIsBuiltin();

        return res;
    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: Global.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) {
    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 T res = clazz.cast(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.setInitialProto(getObjectPrototype());
        }

        res.setIsBuiltin();

        return res;
    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: Global.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) {
    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 T res = clazz.cast(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.setInitialProto(getObjectPrototype());
        }

        res.setIsBuiltin();

        return res;
    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: Global.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) {
    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 T res = clazz.cast(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.setInitialProto(getObjectPrototype());
        }

        res.setIsBuiltin();

        return res;
    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
Source File: Global.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) {
    try {
        // Assuming class name pattern for built-in JS constructors.
        final StringBuilder sb = new StringBuilder(PACKAGE_PREFIX);

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

        final Class<?> funcClass = Class.forName(sb.toString());
        final T res = clazz.cast(funcClass.getDeclaredConstructor().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.setInitialProto(getObjectPrototype());
        }

        res.setIsBuiltin();

        return res;
    } catch (final Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException)e;
        } else {
            throw new RuntimeException(e);
        }
    }
}
 
Example 6
Source File: Global.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) {
    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 T res = clazz.cast(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.setInitialProto(getObjectPrototype());
        }

        res.setIsBuiltin();

        return res;
    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 7
Source File: Global.java    From openjdk-8-source 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 8
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 9
Source File: Global.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) {
    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 T res = clazz.cast(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.setInitialProto(getObjectPrototype());
        }

        res.setIsBuiltin();

        return res;
    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 10
Source File: Global.java    From nashorn 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);
    }
}