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

The following examples show how to use jdk.nashorn.internal.runtime.ScriptObject#addBoundProperties() . 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
/**
 * Binds the source mirror object's properties to the target object. Binding
 * properties allows two-way read/write for the properties of the source object.
 * All inherited, enumerable properties are also bound. This method is used to
 * to make 'with' statement work with ScriptObjectMirror as scope object.
 *
 * @param target the target object to which the source object's properties are bound
 * @param source the source object whose properties are bound to the target
 * @return the target object after property binding
 */
public static Object bindAllProperties(final ScriptObject target, final ScriptObjectMirror source) {
    final Set<String> keys = source.keySet();
    // make accessor properties using dynamic invoker getters and setters
    final AccessorProperty[] props = new AccessorProperty[keys.size()];
    int idx = 0;
    for (final String name : keys) {
        final MethodHandle getter = Bootstrap.createDynamicInvoker("dyn:getMethod|getProp|getElem:" + name, MIRROR_GETTER_TYPE);
        final MethodHandle setter = Bootstrap.createDynamicInvoker("dyn:setProp|setElem:" + name, MIRROR_SETTER_TYPE);
        props[idx] = AccessorProperty.create(name, 0, getter, setter);
        idx++;
    }

    target.addBoundProperties(source, props);
    return target;
}
 
Example 2
Source File: NativeObject.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the source mirror object's properties to the target object. Binding
 * properties allows two-way read/write for the properties of the source object.
 * All inherited, enumerable properties are also bound. This method is used to
 * to make 'with' statement work with ScriptObjectMirror as scope object.
 *
 * @param target the target object to which the source object's properties are bound
 * @param source the source object whose properties are bound to the target
 * @return the target object after property binding
 */
public static Object bindAllProperties(final ScriptObject target, final ScriptObjectMirror source) {
    final Set<String> keys = source.keySet();
    // make accessor properties using dynamic invoker getters and setters
    final AccessorProperty[] props = new AccessorProperty[keys.size()];
    int idx = 0;
    for (final String name : keys) {
        final MethodHandle getter = Bootstrap.createDynamicInvoker("dyn:getMethod|getProp|getElem:" + name, MIRROR_GETTER_TYPE);
        final MethodHandle setter = Bootstrap.createDynamicInvoker("dyn:setProp|setElem:" + name, MIRROR_SETTER_TYPE);
        props[idx] = AccessorProperty.create(name, 0, getter, setter);
        idx++;
    }

    target.addBoundProperties(source, props);
    return target;
}
 
Example 3
Source File: NativeObject.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the source mirror object's properties to the target object. Binding
 * properties allows two-way read/write for the properties of the source object.
 * All inherited, enumerable properties are also bound. This method is used to
 * to make 'with' statement work with ScriptObjectMirror as scope object.
 *
 * @param target the target object to which the source object's properties are bound
 * @param source the source object whose properties are bound to the target
 * @return the target object after property binding
 */
public static Object bindAllProperties(final ScriptObject target, final ScriptObjectMirror source) {
    final Set<String> keys = source.keySet();
    // make accessor properties using dynamic invoker getters and setters
    final AccessorProperty[] props = new AccessorProperty[keys.size()];
    int idx = 0;
    for (final String name : keys) {
        final MethodHandle getter = Bootstrap.createDynamicInvoker("dyn:getMethod|getProp|getElem:" + name, MIRROR_GETTER_TYPE);
        final MethodHandle setter = Bootstrap.createDynamicInvoker("dyn:setProp|setElem:" + name, MIRROR_SETTER_TYPE);
        props[idx] = AccessorProperty.create(name, 0, getter, setter);
        idx++;
    }

    target.addBoundProperties(source, props);
    return target;
}
 
Example 4
Source File: NativeObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the source mirror object's properties to the target object. Binding
 * properties allows two-way read/write for the properties of the source object.
 * All inherited, enumerable properties are also bound. This method is used to
 * to make 'with' statement work with ScriptObjectMirror as scope object.
 *
 * @param target the target object to which the source object's properties are bound
 * @param source the source object whose properties are bound to the target
 * @return the target object after property binding
 */
public static Object bindAllProperties(final ScriptObject target, final ScriptObjectMirror source) {
    final Set<String> keys = source.keySet();
    // make accessor properties using dynamic invoker getters and setters
    final AccessorProperty[] props = new AccessorProperty[keys.size()];
    int idx = 0;
    for (final String name : keys) {
        final MethodHandle getter = Bootstrap.createDynamicInvoker("dyn:getMethod|getProp|getElem:" + name, MIRROR_GETTER_TYPE);
        final MethodHandle setter = Bootstrap.createDynamicInvoker("dyn:setProp|setElem:" + name, MIRROR_SETTER_TYPE);
        props[idx] = AccessorProperty.create(name, 0, getter, setter);
        idx++;
    }

    target.addBoundProperties(source, props);
    return target;
}
 
Example 5
Source File: NativeObject.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the source mirror object's properties to the target object. Binding
 * properties allows two-way read/write for the properties of the source object.
 * All inherited, enumerable properties are also bound. This method is used to
 * to make 'with' statement work with ScriptObjectMirror as scope object.
 *
 * @param target the target object to which the source object's properties are bound
 * @param source the source object whose properties are bound to the target
 * @return the target object after property binding
 */
public static Object bindAllProperties(final ScriptObject target, final ScriptObjectMirror source) {
    final Set<String> keys = source.keySet();
    // make accessor properties using dynamic invoker getters and setters
    final AccessorProperty[] props = new AccessorProperty[keys.size()];
    int idx = 0;
    for (final String name : keys) {
        final MethodHandle getter = Bootstrap.createDynamicInvoker("dyn:getMethod|getProp|getElem:" + name, MIRROR_GETTER_TYPE);
        final MethodHandle setter = Bootstrap.createDynamicInvoker("dyn:setProp|setElem:" + name, MIRROR_SETTER_TYPE);
        props[idx] = AccessorProperty.create(name, 0, getter, setter);
        idx++;
    }

    target.addBoundProperties(source, props);
    return target;
}
 
Example 6
Source File: NativeObject.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the source mirror object's properties to the target object. Binding
 * properties allows two-way read/write for the properties of the source object.
 * All inherited, enumerable properties are also bound. This method is used to
 * to make 'with' statement work with ScriptObjectMirror as scope object.
 *
 * @param target the target object to which the source object's properties are bound
 * @param source the source object whose properties are bound to the target
 * @return the target object after property binding
 */
public static Object bindAllProperties(final ScriptObject target, final ScriptObjectMirror source) {
    final Set<String> keys = source.keySet();
    // make accessor properties using dynamic invoker getters and setters
    final AccessorProperty[] props = new AccessorProperty[keys.size()];
    int idx = 0;
    for (final String name : keys) {
        final MethodHandle getter = Bootstrap.createDynamicInvoker("dyn:getMethod|getProp|getElem:" + name, MIRROR_GETTER_TYPE);
        final MethodHandle setter = Bootstrap.createDynamicInvoker("dyn:setProp|setElem:" + name, MIRROR_SETTER_TYPE);
        props[idx] = AccessorProperty.create(name, 0, getter, setter);
        idx++;
    }

    target.addBoundProperties(source, props);
    return target;
}
 
Example 7
Source File: Global.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private synchronized ScriptFunction getBuiltinRegExp() {
    if (this.builtinRegExp == null) {
        this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
        final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
        // initialize default regexp object
        this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
        // RegExp.prototype should behave like a RegExp object. So copy the
        // properties.
        regExpProto.addBoundProperties(DEFAULT_REGEXP);
    }
    return builtinRegExp;
}
 
Example 8
Source File: Global.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private synchronized ScriptFunction getBuiltinRegExp() {
    if (this.builtinRegExp == null) {
        this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
        final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
        // initialize default regexp object
        this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
        // RegExp.prototype should behave like a RegExp object. So copy the
        // properties.
        regExpProto.addBoundProperties(DEFAULT_REGEXP);
    }
    return builtinRegExp;
}
 
Example 9
Source File: Global.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private synchronized ScriptFunction getBuiltinRegExp() {
    if (this.builtinRegExp == null) {
        this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
        final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
        // initialize default regexp object
        this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
        // RegExp.prototype should behave like a RegExp object. So copy the
        // properties.
        regExpProto.addBoundProperties(DEFAULT_REGEXP);
    }
    return builtinRegExp;
}
 
Example 10
Source File: Global.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private synchronized ScriptFunction getBuiltinRegExp() {
    if (this.builtinRegExp == null) {
        this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
        final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
        // initialize default regexp object
        this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
        // RegExp.prototype should behave like a RegExp object. So copy the
        // properties.
        regExpProto.addBoundProperties(DEFAULT_REGEXP);
    }
    return builtinRegExp;
}
 
Example 11
Source File: Global.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private synchronized ScriptFunction getBuiltinRegExp() {
    if (this.builtinRegExp == null) {
        this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
        final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
        // initialize default regexp object
        this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
        // RegExp.prototype should behave like a RegExp object. So copy the
        // properties.
        regExpProto.addBoundProperties(DEFAULT_REGEXP);
    }
    return builtinRegExp;
}
 
Example 12
Source File: NativeObject.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Binds the source mirror object's properties to the target object. Binding
 * properties allows two-way read/write for the properties of the source object.
 * All inherited, enumerable properties are also bound. This method is used to
 * to make 'with' statement work with ScriptObjectMirror as scope object.
 *
 * @param target the target object to which the source object's properties are bound
 * @param source the source object whose properties are bound to the target
 * @return the target object after property binding
 */
public static Object bindAllProperties(final ScriptObject target, final ScriptObjectMirror source) {
    final Set<String> keys = source.keySet();
    // make accessor properties using dynamic invoker getters and setters
    final AccessorProperty[] props = new AccessorProperty[keys.size()];
    int idx = 0;
    for (final String name : keys) {
        props[idx] = createAccessorProperty(name);
        idx++;
    }

    target.addBoundProperties(source, props);
    return target;
}
 
Example 13
Source File: Global.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private synchronized ScriptFunction getBuiltinRegExp() {
    if (this.builtinRegExp == null) {
        this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
        final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
        // initialize default regexp object
        this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
        // RegExp.prototype should behave like a RegExp object. So copy the
        // properties.
        regExpProto.addBoundProperties(DEFAULT_REGEXP);
    }
    return builtinRegExp;
}
 
Example 14
Source File: Global.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private synchronized ScriptFunction getBuiltinRegExp() {
    if (this.builtinRegExp == null) {
        this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class);
        final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp);
        // initialize default regexp object
        this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto);
        // RegExp.prototype should behave like a RegExp object. So copy the
        // properties.
        regExpProto.addBoundProperties(DEFAULT_REGEXP);
    }
    return builtinRegExp;
}