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

The following examples show how to use jdk.nashorn.internal.runtime.ScriptObject#setInitialProto() . 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: JSONParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
    final long[] primitiveSpill = dualFields ? new long[values.size()] : null;
    final Object[] objectSpill = new Object[values.size()];

    for (final Property property : propertyMap.getProperties()) {
        if (!dualFields || property.getType() == Object.class) {
            objectSpill[property.getSlot()] = values.get(property.getSlot());
        } else {
            primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
        }
    }

    final ScriptObject object = dualFields ?
            new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill);
    object.setInitialProto(global.getObjectPrototype());
    object.setArray(arrayData);
    return object;
}
 
Example 2
Source File: JSONParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
    final long[] primitiveSpill = dualFields ? new long[values.size()] : null;
    final Object[] objectSpill = new Object[values.size()];

    for (final Property property : propertyMap.getProperties()) {
        if (!dualFields || property.getType() == Object.class) {
            objectSpill[property.getSlot()] = values.get(property.getSlot());
        } else {
            primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
        }
    }

    final ScriptObject object = dualFields ?
            new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill);
    object.setInitialProto(global.getObjectPrototype());
    object.setArray(arrayData);
    return object;
}
 
Example 3
Source File: JSONParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
    final long[] primitiveSpill = dualFields ? new long[values.size()] : null;
    final Object[] objectSpill = new Object[values.size()];

    for (final Property property : propertyMap.getProperties()) {
        if (!dualFields || property.getType() == Object.class) {
            objectSpill[property.getSlot()] = values.get(property.getSlot());
        } else {
            primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
        }
    }

    final ScriptObject object = dualFields ?
            new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill);
    object.setInitialProto(global.getObjectPrototype());
    object.setArray(arrayData);
    return object;
}
 
Example 4
Source File: JSONParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
    final long[] primitiveSpill = dualFields ? new long[values.size()] : null;
    final Object[] objectSpill = new Object[values.size()];

    for (final Property property : propertyMap.getProperties()) {
        if (!dualFields || property.getType() == Object.class) {
            objectSpill[property.getSlot()] = values.get(property.getSlot());
        } else {
            primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
        }
    }

    final ScriptObject object = dualFields ?
            new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill);
    object.setInitialProto(global.getObjectPrototype());
    object.setArray(arrayData);
    return object;
}
 
Example 5
Source File: JSONParser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
    final long[] primitiveSpill = dualFields ? new long[values.size()] : null;
    final Object[] objectSpill = new Object[values.size()];

    for (final Property property : propertyMap.getProperties()) {
        if (!dualFields || property.getType() == Object.class) {
            objectSpill[property.getSlot()] = values.get(property.getSlot());
        } else {
            primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
        }
    }

    final ScriptObject object = dualFields ?
            new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill);
    object.setInitialProto(global.getObjectPrototype());
    object.setArray(arrayData);
    return object;
}
 
Example 6
Source File: Global.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private ScriptObject initPrototype(final String name, final ScriptObject prototype) {
    try {
        // Assuming class name pattern for JS prototypes
        final String className = PACKAGE_PREFIX + name + "$Prototype";

        final Class<?> funcClass = Class.forName(className);
        final ScriptObject res = (ScriptObject) funcClass.getDeclaredConstructor().newInstance();

        res.setIsBuiltin();
        res.setInitialProto(prototype);
        return res;
    } catch (final Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException)e;
        } else {
            throw new RuntimeException(e);
        }
    }
}
 
Example 7
Source File: JSONParser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
    final long[] primitiveSpill = dualFields ? new long[values.size()] : null;
    final Object[] objectSpill = new Object[values.size()];

    for (final Property property : propertyMap.getProperties()) {
        if (!dualFields || property.getType() == Object.class) {
            objectSpill[property.getSlot()] = values.get(property.getSlot());
        } else {
            primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
        }
    }

    final ScriptObject object = dualFields ?
            new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill);
    object.setInitialProto(global.getObjectPrototype());
    object.setArray(arrayData);
    return object;
}
 
Example 8
Source File: JSONParser.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
    final long[] primitiveSpill = dualFields ? new long[values.size()] : null;
    final Object[] objectSpill = new Object[values.size()];

    for (final Property property : propertyMap.getProperties()) {
        if (!dualFields || property.getType() == Object.class) {
            objectSpill[property.getSlot()] = values.get(property.getSlot());
        } else {
            primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
        }
    }

    final ScriptObject object = dualFields ?
            new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill);
    object.setInitialProto(global.getObjectPrototype());
    object.setArray(arrayData);
    return object;
}
 
Example 9
Source File: Global.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
    final ScriptFunction cons = initConstructor(name, ScriptFunction.class);
    final ScriptObject prototype = ScriptFunction.getPrototype(cons);
    prototype.set(NativeError.NAME, name, 0);
    prototype.set(NativeError.MESSAGE, "", 0);
    prototype.setInitialProto(errorProto);
    tagBuiltinProperties(name, cons);
    return cons;
}
 
Example 10
Source File: Global.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
    final ScriptFunction cons = initConstructor(name, ScriptFunction.class);
    final ScriptObject prototype = ScriptFunction.getPrototype(cons);
    prototype.set(NativeError.NAME, name, 0);
    prototype.set(NativeError.MESSAGE, "", 0);
    prototype.setInitialProto(errorProto);
    tagBuiltinProperties(name, cons);
    return cons;
}
 
Example 11
Source File: Global.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
    final ScriptFunction cons = initConstructor(name, ScriptFunction.class);
    final ScriptObject prototype = ScriptFunction.getPrototype(cons);
    prototype.set(NativeError.NAME, name, 0);
    prototype.set(NativeError.MESSAGE, "", 0);
    prototype.setInitialProto(errorProto);
    tagBuiltinProperties(name, cons);
    return cons;
}
 
Example 12
Source File: Global.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
    final ScriptFunction cons = initConstructor(name, ScriptFunction.class);
    final ScriptObject prototype = ScriptFunction.getPrototype(cons);
    prototype.set(NativeError.NAME, name, 0);
    prototype.set(NativeError.MESSAGE, "", 0);
    prototype.setInitialProto(errorProto);
    tagBuiltinProperties(name, cons);
    return cons;
}
 
Example 13
Source File: Global.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
    final ScriptFunction cons = initConstructor(name, ScriptFunction.class);
    final ScriptObject prototype = ScriptFunction.getPrototype(cons);
    prototype.set(NativeError.NAME, name, 0);
    prototype.set(NativeError.MESSAGE, "", 0);
    prototype.setInitialProto(errorProto);
    tagBuiltinProperties(name, cons);
    return cons;
}
 
Example 14
Source File: Global.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
    final ScriptFunction cons = initConstructor(name, ScriptFunction.class);
    final ScriptObject prototype = ScriptFunction.getPrototype(cons);
    prototype.set(NativeError.NAME, name, 0);
    prototype.set(NativeError.MESSAGE, "", 0);
    prototype.setInitialProto(errorProto);
    tagBuiltinProperties(name, cons);
    return cons;
}
 
Example 15
Source File: Global.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
    final ScriptFunction cons = initConstructor(name, ScriptFunction.class);
    final ScriptObject prototype = ScriptFunction.getPrototype(cons);
    prototype.set(NativeError.NAME, name, 0);
    prototype.set(NativeError.MESSAGE, "", 0);
    prototype.setInitialProto(errorProto);
    tagBuiltinProperties(name, cons);
    return cons;
}