Java Code Examples for jdk.nashorn.internal.objects.Global#newObject()

The following examples show how to use jdk.nashorn.internal.objects.Global#newObject() . 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: JSONFunctions.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) {
    if (Bootstrap.isCallable(reviver)) {
        final ScriptObject root = global.newObject();
        root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
        return walk(root, "", reviver);
    }
    return unfiltered;
}
 
Example 2
Source File: ScriptRuntime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Entering a {@code with} node requires new scope. This is the implementation. When exiting the with statement,
 * use {@link ScriptObject#getProto()} on the scope.
 *
 * @param scope      existing scope
 * @param expression expression in with
 *
 * @return {@link WithObject} that is the new scope
 */
public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
    final Global global = Context.getGlobal();
    if (expression == UNDEFINED) {
        throw typeError(global, "cant.apply.with.to.undefined");
    } else if (expression == null) {
        throw typeError(global, "cant.apply.with.to.null");
    }

    if (expression instanceof ScriptObjectMirror) {
        final Object unwrapped = ScriptObjectMirror.unwrap(expression, global);
        if (unwrapped instanceof ScriptObject) {
            return new WithObject(scope, (ScriptObject)unwrapped);
        }
        // foreign ScriptObjectMirror
        final ScriptObject exprObj = global.newObject();
        NativeObject.bindAllProperties(exprObj, (ScriptObjectMirror)expression);
        return new WithObject(scope, exprObj);
    }

    final Object wrappedExpr = JSType.toScriptObject(global, expression);
    if (wrappedExpr instanceof ScriptObject) {
        return new WithObject(scope, (ScriptObject)wrappedExpr);
    }

    throw typeError(global, "cant.apply.with.to.non.scriptobject");
}
 
Example 3
Source File: JSONFunctions.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) {
    if (reviver instanceof ScriptFunction) {
        final ScriptObject root = global.newObject();
        root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
        return walk(root, "", (ScriptFunction)reviver);
    }
    return unfiltered;
}
 
Example 4
Source File: ScriptRuntime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Entering a {@code with} node requires new scope. This is the implementation. When exiting the with statement,
 * use {@link ScriptObject#getProto()} on the scope.
 *
 * @param scope      existing scope
 * @param expression expression in with
 *
 * @return {@link WithObject} that is the new scope
 */
public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
    final Global global = Context.getGlobal();
    if (expression == UNDEFINED) {
        throw typeError(global, "cant.apply.with.to.undefined");
    } else if (expression == null) {
        throw typeError(global, "cant.apply.with.to.null");
    }

    if (expression instanceof ScriptObjectMirror) {
        final Object unwrapped = ScriptObjectMirror.unwrap(expression, global);
        if (unwrapped instanceof ScriptObject) {
            return new WithObject(scope, (ScriptObject)unwrapped);
        }
        // foreign ScriptObjectMirror
        final ScriptObject exprObj = global.newObject();
        NativeObject.bindAllProperties(exprObj, (ScriptObjectMirror)expression);
        return new WithObject(scope, exprObj);
    }

    final Object wrappedExpr = JSType.toScriptObject(global, expression);
    if (wrappedExpr instanceof ScriptObject) {
        return new WithObject(scope, (ScriptObject)wrappedExpr);
    }

    throw typeError(global, "cant.apply.with.to.non.scriptobject");
}
 
Example 5
Source File: JSONFunctions.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) {
    if (Bootstrap.isCallable(reviver)) {
        final ScriptObject root = global.newObject();
        root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
        return walk(root, "", reviver);
    }
    return unfiltered;
}
 
Example 6
Source File: ScriptRuntime.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Entering a {@code with} node requires new scope. This is the implementation. When exiting the with statement,
 * use {@link ScriptObject#getProto()} on the scope.
 *
 * @param scope      existing scope
 * @param expression expression in with
 *
 * @return {@link WithObject} that is the new scope
 */
public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
    final Global global = Context.getGlobal();
    if (expression == UNDEFINED) {
        throw typeError(global, "cant.apply.with.to.undefined");
    } else if (expression == null) {
        throw typeError(global, "cant.apply.with.to.null");
    }

    if (expression instanceof ScriptObjectMirror) {
        final Object unwrapped = ScriptObjectMirror.unwrap(expression, global);
        if (unwrapped instanceof ScriptObject) {
            return new WithObject(scope, (ScriptObject)unwrapped);
        }
        // foreign ScriptObjectMirror
        final ScriptObject exprObj = global.newObject();
        NativeObject.bindAllProperties(exprObj, (ScriptObjectMirror)expression);
        return new WithObject(scope, exprObj);
    }

    final Object wrappedExpr = JSType.toScriptObject(global, expression);
    if (wrappedExpr instanceof ScriptObject) {
        return new WithObject(scope, (ScriptObject)wrappedExpr);
    }

    throw typeError(global, "cant.apply.with.to.non.scriptobject");
}
 
Example 7
Source File: JSONFunctions.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) {
    if (Bootstrap.isCallable(reviver)) {
        final ScriptObject root = global.newObject();
        root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
        return walk(root, "", reviver);
    }
    return unfiltered;
}
 
Example 8
Source File: ScriptRuntime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Entering a {@code with} node requires new scope. This is the implementation. When exiting the with statement,
 * use {@link ScriptObject#getProto()} on the scope.
 *
 * @param scope      existing scope
 * @param expression expression in with
 *
 * @return {@link WithObject} that is the new scope
 */
public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
    final Global global = Context.getGlobal();
    if (expression == UNDEFINED) {
        throw typeError(global, "cant.apply.with.to.undefined");
    } else if (expression == null) {
        throw typeError(global, "cant.apply.with.to.null");
    }

    if (expression instanceof ScriptObjectMirror) {
        final Object unwrapped = ScriptObjectMirror.unwrap(expression, global);
        if (unwrapped instanceof ScriptObject) {
            return new WithObject(scope, (ScriptObject)unwrapped);
        }
        // foreign ScriptObjectMirror
        final ScriptObject exprObj = global.newObject();
        NativeObject.bindAllProperties(exprObj, (ScriptObjectMirror)expression);
        return new WithObject(scope, exprObj);
    }

    final Object wrappedExpr = JSType.toScriptObject(global, expression);
    if (wrappedExpr instanceof ScriptObject) {
        return new WithObject(scope, (ScriptObject)wrappedExpr);
    }

    throw typeError(global, "cant.apply.with.to.non.scriptobject");
}
 
Example 9
Source File: JSONFunctions.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) {
    if (Bootstrap.isCallable(reviver)) {
        final ScriptObject root = global.newObject();
        root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
        return walk(root, "", reviver);
    }
    return unfiltered;
}
 
Example 10
Source File: ScriptRuntime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Entering a {@code with} node requires new scope. This is the implementation. When exiting the with statement,
 * use {@link ScriptObject#getProto()} on the scope.
 *
 * @param scope      existing scope
 * @param expression expression in with
 *
 * @return {@link WithObject} that is the new scope
 */
public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
    final Global global = Context.getGlobal();
    if (expression == UNDEFINED) {
        throw typeError(global, "cant.apply.with.to.undefined");
    } else if (expression == null) {
        throw typeError(global, "cant.apply.with.to.null");
    }

    if (expression instanceof ScriptObjectMirror) {
        final Object unwrapped = ScriptObjectMirror.unwrap(expression, global);
        if (unwrapped instanceof ScriptObject) {
            return new WithObject(scope, (ScriptObject)unwrapped);
        }
        // foreign ScriptObjectMirror
        final ScriptObject exprObj = global.newObject();
        NativeObject.bindAllProperties(exprObj, (ScriptObjectMirror)expression);
        return new WithObject(scope, exprObj);
    }

    final Object wrappedExpr = JSType.toScriptObject(global, expression);
    if (wrappedExpr instanceof ScriptObject) {
        return new WithObject(scope, (ScriptObject)wrappedExpr);
    }

    throw typeError(global, "cant.apply.with.to.non.scriptobject");
}
 
Example 11
Source File: JSONFunctions.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) {
    if (reviver instanceof ScriptFunction) {
        final ScriptObject root = global.newObject();
        root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
        return walk(root, "", (ScriptFunction)reviver);
    }
    return unfiltered;
}
 
Example 12
Source File: ScriptRuntime.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Entering a {@code with} node requires new scope. This is the implementation. When exiting the with statement,
 * use {@link ScriptObject#getProto()} on the scope.
 *
 * @param scope      existing scope
 * @param expression expression in with
 *
 * @return {@link WithObject} that is the new scope
 */
public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
    final Global global = Context.getGlobal();
    if (expression == UNDEFINED) {
        throw typeError(global, "cant.apply.with.to.undefined");
    } else if (expression == null) {
        throw typeError(global, "cant.apply.with.to.null");
    }

    if (expression instanceof ScriptObjectMirror) {
        final Object unwrapped = ScriptObjectMirror.unwrap(expression, global);
        if (unwrapped instanceof ScriptObject) {
            return new WithObject(scope, (ScriptObject)unwrapped);
        }
        // foreign ScriptObjectMirror
        final ScriptObject exprObj = global.newObject();
        NativeObject.bindAllProperties(exprObj, (ScriptObjectMirror)expression);
        return new WithObject(scope, exprObj);
    }

    final Object wrappedExpr = JSType.toScriptObject(global, expression);
    if (wrappedExpr instanceof ScriptObject) {
        return new WithObject(scope, (ScriptObject)wrappedExpr);
    }

    throw typeError(global, "cant.apply.with.to.non.scriptobject");
}
 
Example 13
Source File: JSONFunctions.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) {
    if (Bootstrap.isCallable(reviver)) {
        final ScriptObject root = global.newObject();
        root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
        return walk(root, "", reviver);
    }
    return unfiltered;
}
 
Example 14
Source File: ScriptRuntime.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Entering a {@code with} node requires new scope. This is the implementation. When exiting the with statement,
 * use {@link ScriptObject#getProto()} on the scope.
 *
 * @param scope      existing scope
 * @param expression expression in with
 *
 * @return {@link WithObject} that is the new scope
 */
public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
    final Global global = Context.getGlobal();
    if (expression == UNDEFINED) {
        throw typeError(global, "cant.apply.with.to.undefined");
    } else if (expression == null) {
        throw typeError(global, "cant.apply.with.to.null");
    }

    if (expression instanceof ScriptObjectMirror) {
        final Object unwrapped = ScriptObjectMirror.unwrap(expression, global);
        if (unwrapped instanceof ScriptObject) {
            return new WithObject(scope, (ScriptObject)unwrapped);
        }
        // foreign ScriptObjectMirror
        final ScriptObject exprObj = global.newObject();
        NativeObject.bindAllProperties(exprObj, (ScriptObjectMirror)expression);
        return new WithObject(scope, exprObj);
    }

    final Object wrappedExpr = JSType.toScriptObject(global, expression);
    if (wrappedExpr instanceof ScriptObject) {
        return new WithObject(scope, (ScriptObject)wrappedExpr);
    }

    throw typeError(global, "cant.apply.with.to.non.scriptobject");
}