8060101: AssertionError: __noSuchProperty__ placeholder called from NativeJavaImporter

Reviewed-by: attila, jlaskey
This commit is contained in:
Athijegannathan Sundararajan 2014-10-10 17:59:22 +05:30
parent 5fed7c392c
commit f2913f0270
4 changed files with 80 additions and 12 deletions

View File

@ -25,6 +25,7 @@
package jdk.nashorn.internal.objects; package jdk.nashorn.internal.objects;
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.isValid; import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.isValid;
import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.CallSiteDescriptor;
@ -36,9 +37,11 @@ import jdk.nashorn.internal.objects.annotations.Constructor;
import jdk.nashorn.internal.objects.annotations.Function; import jdk.nashorn.internal.objects.annotations.Function;
import jdk.nashorn.internal.objects.annotations.ScriptClass; import jdk.nashorn.internal.objects.annotations.ScriptClass;
import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.NativeJavaPackage; import jdk.nashorn.internal.runtime.NativeJavaPackage;
import jdk.nashorn.internal.runtime.PropertyMap; import jdk.nashorn.internal.runtime.PropertyMap;
import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptRuntime;
import jdk.nashorn.internal.runtime.UnwarrantedOptimismException; import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
/** /**
@ -94,33 +97,30 @@ public final class NativeJavaImporter extends ScriptObject {
} }
/** /**
* "No such property" call placeholder. * "No such property" handler.
*
* This can never be called as we override {@link ScriptObject#noSuchProperty}. We do declare it here as it's a signal
* to {@link jdk.nashorn.internal.runtime.WithObject} that it's worth trying doing a {@code noSuchProperty} on this object.
* *
* @param self self reference * @param self self reference
* @param name property name * @param name property name
* @return never returns * @return value of the missing property
*/ */
@Function(attributes = Attribute.NOT_ENUMERABLE) @Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object __noSuchProperty__(final Object self, final Object name) { public static Object __noSuchProperty__(final Object self, final Object name) {
throw new AssertionError("__noSuchProperty__ placeholder called"); if (! (self instanceof NativeJavaImporter)) {
throw typeError("not.a.java.importer", ScriptRuntime.safeToString(self));
}
return ((NativeJavaImporter)self).createProperty(JSType.toString(name));
} }
/** /**
* "No such method call" placeholder * "No such method call" handler
*
* This can never be called as we override {@link ScriptObject#noSuchMethod}. We do declare it here as it's a signal
* to {@link jdk.nashorn.internal.runtime.WithObject} that it's worth trying doing a noSuchProperty on this object.
* *
* @param self self reference * @param self self reference
* @param args arguments to method * @param args arguments to method
* @return never returns * @return never returns always throw TypeError
*/ */
@Function(attributes = Attribute.NOT_ENUMERABLE) @Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object __noSuchMethod__(final Object self, final Object... args) { public static Object __noSuchMethod__(final Object self, final Object... args) {
throw new AssertionError("__noSuchMethod__ placeholder called"); throw typeError("not.a.function", ScriptRuntime.safeToString(args[0]));
} }
@Override @Override

View File

@ -209,6 +209,19 @@ public final class WithObject extends ScriptObject implements Scope {
return super.findProperty(key, deep, start); return super.findProperty(key, deep, start);
} }
@Override
protected Object invokeNoSuchProperty(final String name, final int programPoint) {
FindProperty find = expression.findProperty(NO_SUCH_PROPERTY_NAME, true);
if (find != null) {
final Object func = find.getObjectValue();
if (func instanceof ScriptFunction) {
return ScriptRuntime.apply((ScriptFunction)func, expression, name);
}
}
return getProto().invokeNoSuchProperty(name, programPoint);
}
@Override @Override
public void setSplitState(final int state) { public void setSplitState(final int state) {
getNonWithParent().setSplitState(state); getNonWithParent().setSplitState(state);

View File

@ -73,6 +73,7 @@ type.error.strict.getter.setter.poison=In strict mode, "caller", "callee", and "
type.error.not.an.object={0} is not an Object type.error.not.an.object={0} is not an Object
type.error.not.a.boolean={0} is not a Boolean type.error.not.a.boolean={0} is not a Boolean
type.error.not.a.date={0} is not a Date type.error.not.a.date={0} is not a Date
type.error.not.a.java.importer={0} is not a JavaImporter object
type.error.not.a.number={0} is not a Number type.error.not.a.number={0} is not a Number
type.error.not.a.regexp={0} is not a RegExp type.error.not.a.regexp={0} is not a RegExp
type.error.not.a.string={0} is not a String type.error.not.a.string={0} is not a String

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* JDK-8060101: AssertionError: __noSuchProperty__ placeholder called from NativeJavaImporter
*
* @test
* @run
*/
var constant = 0.50;
var ind = 0.0;
// make sure callsites are exercised quite a few times
// to induce megamorphic callsite for with/JavaImporter
// combo - which triggered that AssertionError.
for (var i = 0; i < 50; i++) {
var math = new JavaImporter(java.lang.StrictMath);
ind += 10.0;
with (math) {
StrictMath.exp(-constant*ind);
}
}
for (var i = 0; i < 50; i++) {
var math = new JavaImporter(java.lang.StrictMath);
try {
math.Foo();
} catch (e) {
if (! (e instanceof TypeError)) {
throw e;
}
}
}