< prev index next >
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java
Print this page
@@ -147,11 +147,11 @@
private ArrayData arrayData;
/** Method handle to retrieve prototype of this object */
public static final MethodHandle GETPROTO = findOwnMH_V("getProto", ScriptObject.class);
- static final MethodHandle MEGAMORPHIC_GET = findOwnMH_V("megamorphicGet", Object.class, String.class, boolean.class);
+ static final MethodHandle MEGAMORPHIC_GET = findOwnMH_V("megamorphicGet", Object.class, String.class, boolean.class, boolean.class);
static final MethodHandle GLOBALFILTER = findOwnMH_S("globalFilter", Object.class, Object.class);
static final MethodHandle DECLARE_AND_SET = findOwnMH_V("declareAndSet", void.class, String.class, Object.class);
private static final MethodHandle TRUNCATINGFILTER = findOwnMH_S("truncatingFilter", Object[].class, int.class, Object[].class);
private static final MethodHandle KNOWNFUNCPROPGUARDSELF = findOwnMH_S("knownFunctionPropertyGuardSelf", boolean.class, Object.class, PropertyMap.class, MethodHandle.class, ScriptFunction.class);
@@ -2033,23 +2033,23 @@
return inv.addSwitchPoint(findBuiltinSwitchPoint(name));
}
private static GuardedInvocation findMegaMorphicGetMethod(final CallSiteDescriptor desc, final String name, final boolean isMethod) {
Context.getContextTrusted().getLogger(ObjectClassGenerator.class).warning("Megamorphic getter: " + desc + " " + name + " " +isMethod);
- final MethodHandle invoker = MH.insertArguments(MEGAMORPHIC_GET, 1, name, isMethod);
+ final MethodHandle invoker = MH.insertArguments(MEGAMORPHIC_GET, 1, name, isMethod, NashornCallSiteDescriptor.isScope(desc));
final MethodHandle guard = getScriptObjectGuard(desc.getMethodType(), true);
return new GuardedInvocation(invoker, guard);
}
@SuppressWarnings("unused")
- private Object megamorphicGet(final String key, final boolean isMethod) {
+ private Object megamorphicGet(final String key, final boolean isMethod, final boolean isScope) {
final FindProperty find = findProperty(key, true);
if (find != null) {
return find.getObjectValue();
}
- return isMethod ? getNoSuchMethod(key, INVALID_PROGRAM_POINT) : invokeNoSuchProperty(key, INVALID_PROGRAM_POINT);
+ return isMethod ? getNoSuchMethod(key, isScope, INVALID_PROGRAM_POINT) : invokeNoSuchProperty(key, isScope, INVALID_PROGRAM_POINT);
}
// Marks a property as declared and sets its value. Used as slow path for block-scoped LET and CONST
@SuppressWarnings("unused")
private void declareAndSet(final String key, final Object value) {
@@ -2380,23 +2380,26 @@
}
/**
* Invoke fall back if a property is not found.
* @param name Name of property.
+ * @param isScope is this a scope access?
* @param programPoint program point
* @return Result from call.
*/
- protected Object invokeNoSuchProperty(final String name, final int programPoint) {
+ protected Object invokeNoSuchProperty(final String name, final boolean isScope, final int programPoint) {
final FindProperty find = findProperty(NO_SUCH_PROPERTY_NAME, true);
Object ret = UNDEFINED;
if (find != null) {
final Object func = find.getObjectValue();
if (func instanceof ScriptFunction) {
- ret = ScriptRuntime.apply((ScriptFunction)func, this, name);
+ final ScriptFunction sfunc = (ScriptFunction)func;
+ final Object self = isScope && sfunc.isStrict()? UNDEFINED : this;
+ ret = ScriptRuntime.apply(sfunc, self, name);
}
}
if (isValid(programPoint)) {
throw new UnwarrantedOptimismException(ret, programPoint);
@@ -2407,25 +2410,28 @@
/**
* Get __noSuchMethod__ as a function bound to this object and {@code name} if it is defined.
* @param name the method name
+ * @param isScope is this a scope access?
* @return the bound function, or undefined
*/
- private Object getNoSuchMethod(final String name, final int programPoint) {
+ private Object getNoSuchMethod(final String name, final boolean isScope, final int programPoint) {
final FindProperty find = findProperty(NO_SUCH_METHOD_NAME, true);
if (find == null) {
- return invokeNoSuchProperty(name, programPoint);
+ return invokeNoSuchProperty(name, isScope, programPoint);
}
final Object value = find.getObjectValue();
if (!(value instanceof ScriptFunction)) {
return UNDEFINED;
}
- return ((ScriptFunction)value).createBound(this, new Object[] {name});
+ final ScriptFunction func = (ScriptFunction)value;
+ final Object self = isScope && func.isStrict()? UNDEFINED : this;
+ return func.createBound(self, new Object[] {name});
}
private GuardedInvocation createEmptyGetter(final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck, final String name) {
if (NashornCallSiteDescriptor.isOptimistic(desc)) {
throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
@@ -2736,11 +2742,11 @@
if (find != null) {
return getIntValue(find, programPoint);
}
}
- return JSType.toInt32(invokeNoSuchProperty(key, programPoint));
+ return JSType.toInt32(invokeNoSuchProperty(key, false, programPoint));
}
@Override
public int getInt(final Object key, final int programPoint) {
final Object primitiveKey = JSType.toPrimitive(key, String.class);
@@ -2818,11 +2824,11 @@
if (find != null) {
return getLongValue(find, programPoint);
}
}
- return JSType.toLong(invokeNoSuchProperty(key, programPoint));
+ return JSType.toLong(invokeNoSuchProperty(key, false, programPoint));
}
@Override
public long getLong(final Object key, final int programPoint) {
final Object primitiveKey = JSType.toPrimitive(key, String.class);
@@ -2900,11 +2906,11 @@
if (find != null) {
return getDoubleValue(find, programPoint);
}
}
- return JSType.toNumber(invokeNoSuchProperty(key, INVALID_PROGRAM_POINT));
+ return JSType.toNumber(invokeNoSuchProperty(key, false, INVALID_PROGRAM_POINT));
}
@Override
public double getDouble(final Object key, final int programPoint) {
final Object primitiveKey = JSType.toPrimitive(key, String.class);
@@ -2981,11 +2987,11 @@
if (find != null) {
return find.getObjectValue();
}
}
- return invokeNoSuchProperty(key, INVALID_PROGRAM_POINT);
+ return invokeNoSuchProperty(key, false, INVALID_PROGRAM_POINT);
}
@Override
public Object get(final Object key) {
final Object primitiveKey = JSType.toPrimitive(key, String.class);
< prev index next >