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

The following examples show how to use jdk.nashorn.internal.runtime.ScriptFunction#modifyOwnProperty() . These examples are extracted from open source projects. 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
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 Project: jdk8u60   File: Global.java    License: 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
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
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
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 Project: hottub   File: Global.java    License: 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
/**
 * 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 Project: openjdk-8   File: Global.java    License: 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
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 Project: nashorn   File: Global.java    License: 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);
    }
}