jdk.nashorn.internal.runtime.PropertyMap Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.PropertyMap. 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: MapCreator.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a property map based on a set of fields.
 *
 * @param hasArguments  does the created object have an "arguments" property
 * @param fieldCount    Number of fields in use.
 * @param fieldMaximum  Number of fields available.
 * @param evalCode      is this property map created for 'eval' code?
 * @return New map populated with accessor properties.
 */
PropertyMap makeFieldMap(final boolean hasArguments, final boolean dualFields, final int fieldCount, final int fieldMaximum, final boolean evalCode) {
    final List<Property> properties = new ArrayList<>();
    assert tuples != null;

    for (final MapTuple<T> tuple : tuples) {
        final String   key         = tuple.key;
        final Symbol   symbol      = tuple.symbol;
        final Class<?> initialType = dualFields ? tuple.getValueType() : Object.class;

        if (symbol != null && !isValidArrayIndex(getArrayIndex(key))) {
            final int      flags    = getPropertyFlags(symbol, hasArguments, evalCode, dualFields);
            final Property property = new AccessorProperty(
                    key,
                    flags,
                    structure,
                    symbol.getFieldIndex(),
                    initialType);
            properties.add(property);
        }
    }

    return PropertyMap.newMap(properties, structure.getName(), fieldCount, fieldMaximum, 0);
}
 
Example #3
Source File: MapCreator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a property map based on a set of fields.
 *
 * @param hasArguments does the created object have an "arguments" property
 * @param fieldCount    Number of fields in use.
 * @param fieldMaximum Number of fields available.
 *
 * @return New map populated with accessor properties.
 */
PropertyMap makeFieldMap(final boolean hasArguments, final int fieldCount, final int fieldMaximum) {
    final List<Property> properties = new ArrayList<>();
    assert keys != null;

    for (int i = 0, length = keys.size(); i < length; i++) {
        final String key    = keys.get(i);
        final Symbol symbol = symbols.get(i);

        if (symbol != null && !isValidArrayIndex(getArrayIndex(key))) {
            properties.add(new AccessorProperty(key, getPropertyFlags(symbol, hasArguments), structure, symbol.getFieldIndex()));
        }
    }

    return PropertyMap.newMap(properties, fieldCount, fieldMaximum, 0);
}
 
Example #4
Source File: NativeStrictArguments.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
NativeStrictArguments(final Object[] values, final int numParams,final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    setIsArguments();

    final ScriptFunction func = Global.instance().getTypeErrorThrower();
    // We have to fill user accessor functions late as these are stored
    // in this object rather than in the PropertyMap of this object.
    final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
    initUserAccessors("caller", flags, func, func);
    initUserAccessors("callee", flags, func, func);

    setArray(ArrayData.allocate(values));
    this.length = values.length;

    // extend/truncate named arg array as needed and copy values
    this.namedArgs = new Object[numParams];
    if (numParams > values.length) {
        Arrays.fill(namedArgs, UNDEFINED);
    }
    System.arraycopy(values, 0, namedArgs, 0, Math.min(namedArgs.length, values.length));
}
 
Example #5
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 #6
Source File: MapCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a property map based on a set of fields.
 *
 * @param hasArguments  does the created object have an "arguments" property
 * @param fieldCount    Number of fields in use.
 * @param fieldMaximum  Number of fields available.
 * @param evalCode      is this property map created for 'eval' code?
 * @return New map populated with accessor properties.
 */
PropertyMap makeFieldMap(final boolean hasArguments, final boolean dualFields, final int fieldCount, final int fieldMaximum, final boolean evalCode) {
    final List<Property> properties = new ArrayList<>();
    assert tuples != null;

    for (final MapTuple<T> tuple : tuples) {
        final String   key         = tuple.key;
        final Symbol   symbol      = tuple.symbol;
        final Class<?> initialType = dualFields ? tuple.getValueType() : Object.class;

        if (symbol != null && !isValidArrayIndex(getArrayIndex(key))) {
            final int      flags    = getPropertyFlags(symbol, hasArguments, evalCode, dualFields);
            final Property property = new AccessorProperty(
                    key,
                    flags,
                    structure,
                    symbol.getFieldIndex(),
                    initialType);
            properties.add(property);
        }
    }

    return PropertyMap.newMap(properties, structure.getName(), fieldCount, fieldMaximum, 0);
}
 
Example #7
Source File: MapCreator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a property map based on a set of fields.
 *
 * @param hasArguments does the created object have an "arguments" property
 * @param fieldCount    Number of fields in use.
 * @param fieldMaximum Number of fields available.
 *
 * @return New map populated with accessor properties.
 */
PropertyMap makeFieldMap(final boolean hasArguments, final int fieldCount, final int fieldMaximum) {
    final List<Property> properties = new ArrayList<>();
    assert keys != null;

    for (int i = 0, length = keys.size(); i < length; i++) {
        final String key    = keys.get(i);
        final Symbol symbol = symbols.get(i);

        if (symbol != null && !isValidArrayIndex(getArrayIndex(key))) {
            properties.add(new AccessorProperty(key, getPropertyFlags(symbol, hasArguments), structure, symbol.getFieldIndex()));
        }
    }

    return PropertyMap.newMap(properties, fieldCount, fieldMaximum, 0);
}
 
Example #8
Source File: MapCreator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
PropertyMap makeSpillMap(final boolean hasArguments, final boolean dualFields) {
    final List<Property> properties = new ArrayList<>();
    int spillIndex = 0;
    assert tuples != null;

    for (final MapTuple<T> tuple : tuples) {
        final String key    = tuple.key;
        final Symbol symbol = tuple.symbol;
        final Class<?> initialType = dualFields ? tuple.getValueType() : Object.class;

        if (symbol != null && !isValidArrayIndex(getArrayIndex(key))) {
            final int flags = getPropertyFlags(symbol, hasArguments, false, dualFields);
            properties.add(
                    new SpillProperty(
                            key,
                            flags,
                            spillIndex++,
                            initialType));
        }
    }

    return PropertyMap.newMap(properties, structure.getName(), 0, 0, spillIndex);
}
 
Example #9
Source File: NativeRangeError.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
private NativeRangeError(final Object msg, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
    NativeError.initException(this);
}
 
Example #10
Source File: ObjectClassGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add an empty <init> method to the JavaScript class.
 *
 * @param classEmitter Open class emitter.
 * @param className    Name of JavaScript class.
 */
private static void newEmptyInit(final String className, final ClassEmitter classEmitter) {
    final MethodEmitter emptyInit = classEmitter.init();
    emptyInit.begin();
    emptyInit.load(Type.OBJECT, JAVA_THIS.slot());
    emptyInit.loadNull();
    emptyInit.invoke(constructorNoLookup(className, PropertyMap.class));
    emptyInit.returnVoid();
    emptyInit.end();
}
 
Example #11
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Load a constant from the constant array. This is only public to be callable from the objects
 * subpackage. Do not call directly.
 *
 * @param object object to load
 */
void loadConstant(final Object object) {
    final String       unitClassName = unit.getUnitClassName();
    final ClassEmitter classEmitter  = unit.getClassEmitter();
    final int          index         = compiler.getConstantData().add(object);
    final Class<?>     cls           = object.getClass();

    if (cls == PropertyMap.class) {
        method.load(index);
        method.invokestatic(unitClassName, GET_MAP.symbolName(), methodDescriptor(PropertyMap.class, int.class));
        classEmitter.needGetConstantMethod(PropertyMap.class);
    } else if (cls.isArray()) {
        method.load(index);
        final String methodName = ClassEmitter.getArrayMethodName(cls);
        method.invokestatic(unitClassName, methodName, methodDescriptor(cls, int.class));
        classEmitter.needGetConstantMethod(cls);
    } else {
        method.loadConstants().load(index).arrayload();
        if (object instanceof ArrayData) {
            // avoid cast to non-public ArrayData subclass
            method.checkcast(ArrayData.class);
            method.invoke(virtualCallNoLookup(ArrayData.class, "copy", ArrayData.class));
        } else if (cls != Object.class) {
            method.checkcast(cls);
        }
    }
}
 
Example #12
Source File: ObjectClassGenerator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static MethodEmitter newInitWithSpillArraysMethod(final ClassEmitter classEmitter, final Class<?> superClass) {
    final MethodEmitter init = classEmitter.init(PropertyMap.class, long[].class, Object[].class);
    init.begin();
    init.load(Type.OBJECT, JAVA_THIS.slot());
    init.load(Type.OBJECT, INIT_MAP.slot());
    init.load(Type.LONG_ARRAY, 2);
    init.load(Type.OBJECT_ARRAY, 3);
    init.invoke(constructorNoLookup(superClass, PropertyMap.class, long[].class, Object[].class));

    return init;
}
 
Example #13
Source File: NativeReferenceError.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
private NativeReferenceError(final Object msg, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
    NativeError.initException(this);
}
 
Example #14
Source File: ConstantData.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(final Object other) {
    if (!(other instanceof PropertyMapWrapper)) {
        return false;
    }
    final PropertyMap otherMap = ((PropertyMapWrapper) other).propertyMap;
    return propertyMap == otherMap
            || (Arrays.equals(propertyMap.getProperties(), otherMap.getProperties())
                && Objects.equals(propertyMap.getClassName(), otherMap.getClassName()));
}
 
Example #15
Source File: NativeJSAdapter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
NativeJSAdapter(final Object overrides, final ScriptObject adaptee, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    this.adaptee = wrapAdaptee(adaptee);
    if (overrides instanceof ScriptObject) {
        this.overrides = true;
        final ScriptObject sobj = (ScriptObject)overrides;
        this.addBoundProperties(sobj);
    } else {
        this.overrides = false;
    }
}
 
Example #16
Source File: Global.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static PropertyMap checkAndGetMap(final Context context) {
    // security check first
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(Context.NASHORN_CREATE_GLOBAL));
    }

    Objects.requireNonNull(context);

    return $nasgenmap$;
}
 
Example #17
Source File: NativeArguments.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
NativeArguments(final Object[] arguments, final Object callee, final int numParams, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    setIsArguments();
    setArray(ArrayData.allocate(arguments));
    this.length = arguments.length;
    this.callee = callee;
    this.numMapped = Math.min(numParams, arguments.length);
    this.numParams = numParams;
}
 
Example #18
Source File: NativeError.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
private NativeError(final Object msg, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
    initException(this);
}
 
Example #19
Source File: ObjectClassGenerator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allocate and initialize a new <init> method.
 *
 * @param classEmitter  Open class emitter.
 *
 * @return Open method emitter.
 */
private static MethodEmitter newInitMethod(final ClassEmitter classEmitter) {
    final MethodEmitter init = classEmitter.init(PropertyMap.class);
    init.begin();
    init.load(Type.OBJECT, JAVA_THIS.slot());
    init.load(Type.OBJECT, INIT_MAP.slot());
    init.invoke(constructorNoLookup(ScriptObject.class, PropertyMap.class));

    return init;
}
 
Example #20
Source File: NativeReferenceError.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
private NativeReferenceError(final Object msg, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
    NativeError.initException(this);
}
 
Example #21
Source File: NativeEvalError.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
private NativeEvalError(final Object msg, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
    NativeError.initException(this);
}
 
Example #22
Source File: ScriptFunctionImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static PropertyMap createStrictModeMap(final PropertyMap map) {
    final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
    PropertyMap newMap = map;
    // Need to add properties directly to map since slots are assigned speculatively by newUserAccessors.
    newMap = newMap.addProperty(map.newUserAccessors("arguments", flags));
    newMap = newMap.addProperty(map.newUserAccessors("caller", flags));
    return newMap;
}
 
Example #23
Source File: ObjectClassGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add an empty <init> method to the JavaScript class.
 *
 * @param classEmitter Open class emitter.
 * @param className    Name of JavaScript class.
 */
private static void newEmptyInit(final ClassEmitter classEmitter, final String className) {
    final MethodEmitter emptyInit = classEmitter.init();
    emptyInit.begin();
    emptyInit.load(Type.OBJECT, JAVA_THIS.slot());
    emptyInit.loadNull();
    emptyInit.invoke(constructorNoLookup(className, PropertyMap.class));
    emptyInit.returnVoid();
    emptyInit.end();
}
 
Example #24
Source File: NativeEvalError.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
private NativeEvalError(final Object msg, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
    NativeError.initException(this);
}
 
Example #25
Source File: NativeReferenceError.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
private NativeReferenceError(final Object msg, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
    NativeError.initException(this);
}
 
Example #26
Source File: NativeDate.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private NativeDate(final double time, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    final ScriptEnvironment env = Global.getEnv();

    this.time = time;
    this.timezone = env._timezone;
}
 
Example #27
Source File: NativeReferenceError.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
private NativeReferenceError(final Object msg, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
    NativeError.initException(this);
}
 
Example #28
Source File: ObjectClassGenerator.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add an empty <init> method to the JavaScript class.
 *
 * @param classEmitter Open class emitter.
 * @param className    Name of JavaScript class.
 */
private static void newEmptyInit(final ClassEmitter classEmitter, final String className) {
    final MethodEmitter emptyInit = classEmitter.init();
    emptyInit.begin();
    emptyInit.load(Type.OBJECT, JAVA_THIS.slot());
    emptyInit.loadNull();
    emptyInit.invoke(constructorNoLookup(className, PropertyMap.class));
    emptyInit.returnVoid();
    emptyInit.end();
}
 
Example #29
Source File: ObjectClassGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add an empty <init> method to the JavaScript class.
 *
 * @param classEmitter Open class emitter.
 * @param className    Name of JavaScript class.
 */
private static void newAllocate(final String className, final ClassEmitter classEmitter) {
    final MethodEmitter allocate = classEmitter.method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), ALLOCATE.symbolName(), ScriptObject.class, PropertyMap.class);
    allocate.begin();
    allocate._new(className, Type.typeFor(ScriptObject.class));
    allocate.dup();
    allocate.load(Type.typeFor(PropertyMap.class), 0);
    allocate.invoke(constructorNoLookup(className, PropertyMap.class));
    allocate._return();
    allocate.end();
}
 
Example #30
Source File: NativeNumber.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
static PropertyMap getInitialMap() {
    return $nasgenmap$;
}