8049222: JSType class exposes public mutable arrays
Reviewed-by: hannesw, sundar
This commit is contained in:
parent
27ba0956b6
commit
7620f47068
@ -550,7 +550,7 @@ public final class ObjectClassGenerator implements Loggable {
|
||||
}
|
||||
|
||||
//no optimism here. we do unconditional conversion to types
|
||||
private static MethodHandle createGetterInner(final Class<?> forType, final Class<?> type, final MethodHandle primitiveGetter, final MethodHandle objectGetter, final MethodHandle[] converters, final int programPoint) {
|
||||
private static MethodHandle createGetterInner(final Class<?> forType, final Class<?> type, final MethodHandle primitiveGetter, final MethodHandle objectGetter, final List<MethodHandle> converters, final int programPoint) {
|
||||
final int fti = forType == null ? TYPE_UNDEFINED_INDEX : getAccessorTypeIndex(forType);
|
||||
final int ti = getAccessorTypeIndex(type);
|
||||
//this means fail if forType != type
|
||||
@ -564,7 +564,7 @@ public final class ObjectClassGenerator implements Loggable {
|
||||
if (isOptimistic) {
|
||||
//return undefined if asking for object. otherwise throw UnwarrantedOptimismException
|
||||
if (ti == TYPE_OBJECT_INDEX) {
|
||||
return MH.dropArguments(GET_UNDEFINED[TYPE_OBJECT_INDEX], 0, Object.class);
|
||||
return MH.dropArguments(GET_UNDEFINED.get(TYPE_OBJECT_INDEX), 0, Object.class);
|
||||
}
|
||||
//throw exception
|
||||
return MH.asType(
|
||||
@ -578,7 +578,7 @@ public final class ObjectClassGenerator implements Loggable {
|
||||
getter.type().changeReturnType(type));
|
||||
}
|
||||
//return an undefined and coerce it to the appropriate type
|
||||
return MH.dropArguments(GET_UNDEFINED[ti], 0, Object.class);
|
||||
return MH.dropArguments(GET_UNDEFINED.get(ti), 0, Object.class);
|
||||
}
|
||||
|
||||
assert forType != null;
|
||||
@ -604,7 +604,7 @@ public final class ObjectClassGenerator implements Loggable {
|
||||
return MH.filterReturnValue(
|
||||
objectGetter,
|
||||
MH.insertArguments(
|
||||
converters[ti],
|
||||
converters.get(ti),
|
||||
1,
|
||||
programPoint));
|
||||
}
|
||||
@ -631,7 +631,7 @@ public final class ObjectClassGenerator implements Loggable {
|
||||
final MethodHandle tgetter = getterForType(forType, primitiveGetter, objectGetter);
|
||||
if (fti == TYPE_OBJECT_INDEX) {
|
||||
if (fti != ti) {
|
||||
return MH.filterReturnValue(tgetter, CONVERT_OBJECT[ti]);
|
||||
return MH.filterReturnValue(tgetter, CONVERT_OBJECT.get(ti));
|
||||
}
|
||||
return tgetter;
|
||||
}
|
||||
|
@ -220,23 +220,23 @@ public enum JSType {
|
||||
public static final int TYPE_OBJECT_INDEX = 3; //getAccessorTypeIndex(Object.class);
|
||||
|
||||
/** object conversion quickies with JS semantics - used for return value and parameter filter */
|
||||
public static final MethodHandle[] CONVERT_OBJECT = {
|
||||
public static final List<MethodHandle> CONVERT_OBJECT = toUnmodifiableList(
|
||||
JSType.TO_INT32.methodHandle(),
|
||||
JSType.TO_UINT32.methodHandle(),
|
||||
JSType.TO_NUMBER.methodHandle(),
|
||||
null
|
||||
};
|
||||
);
|
||||
|
||||
/**
|
||||
* object conversion quickies with JS semantics - used for return value and parameter filter, optimistic
|
||||
* throws exception upon incompatible type (asking for a narrower one than the storage)
|
||||
*/
|
||||
public static final MethodHandle[] CONVERT_OBJECT_OPTIMISTIC = {
|
||||
public static final List<MethodHandle> CONVERT_OBJECT_OPTIMISTIC = toUnmodifiableList(
|
||||
JSType.TO_INT32_OPTIMISTIC.methodHandle(),
|
||||
JSType.TO_LONG_OPTIMISTIC.methodHandle(),
|
||||
JSType.TO_NUMBER_OPTIMISTIC.methodHandle(),
|
||||
null
|
||||
};
|
||||
);
|
||||
|
||||
/** The value of Undefined cast to an int32 */
|
||||
public static final int UNDEFINED_INT = 0;
|
||||
@ -249,12 +249,12 @@ public enum JSType {
|
||||
* Method handles for getters that return undefined coerced
|
||||
* to the appropriate type
|
||||
*/
|
||||
public static final MethodHandle[] GET_UNDEFINED = new MethodHandle[] {
|
||||
public static final List<MethodHandle> GET_UNDEFINED = toUnmodifiableList(
|
||||
MH.constant(int.class, UNDEFINED_INT),
|
||||
MH.constant(long.class, UNDEFINED_LONG),
|
||||
MH.constant(double.class, UNDEFINED_DOUBLE),
|
||||
MH.constant(Object.class, Undefined.getUndefined()),
|
||||
};
|
||||
MH.constant(Object.class, Undefined.getUndefined())
|
||||
);
|
||||
|
||||
private static final double INT32_LIMIT = 4294967296.0;
|
||||
|
||||
@ -1820,5 +1820,7 @@ public enum JSType {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final List<MethodHandle> toUnmodifiableList(final MethodHandle... methodHandles) {
|
||||
return Collections.unmodifiableList(Arrays.asList(methodHandles));
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ public final class UserAccessorProperty extends SpillProperty {
|
||||
MH.filterReturnValue(
|
||||
getter,
|
||||
MH.insertArguments(
|
||||
CONVERT_OBJECT_OPTIMISTIC[getAccessorTypeIndex(type)],
|
||||
CONVERT_OBJECT_OPTIMISTIC.get(getAccessorTypeIndex(type)),
|
||||
1,
|
||||
programPoint)),
|
||||
getter.type().changeReturnType(type));
|
||||
|
Loading…
Reference in New Issue
Block a user