--- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJavaImporter.java 2014-10-10 17:42:57.288713655 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJavaImporter.java 2014-10-10 17:42:57.016712321 +0530 @@ -25,6 +25,7 @@ package jdk.nashorn.internal.objects; +import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.isValid; import jdk.internal.dynalink.CallSiteDescriptor; @@ -36,9 +37,11 @@ import jdk.nashorn.internal.objects.annotations.Function; import jdk.nashorn.internal.objects.annotations.ScriptClass; import jdk.nashorn.internal.runtime.Context; +import jdk.nashorn.internal.runtime.JSType; import jdk.nashorn.internal.runtime.NativeJavaPackage; import jdk.nashorn.internal.runtime.PropertyMap; import jdk.nashorn.internal.runtime.ScriptObject; +import jdk.nashorn.internal.runtime.ScriptRuntime; import jdk.nashorn.internal.runtime.UnwarrantedOptimismException; /** @@ -94,33 +97,30 @@ } /** - * "No such property" call placeholder. - * - * 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. + * "No such property" handler. * * @param self self reference * @param name property name - * @return never returns + * @return value of the missing property */ @Function(attributes = Attribute.NOT_ENUMERABLE) 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 - * - * 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. + * "No such method call" handler * * @param self self reference * @param args arguments to method - * @return never returns + * @return never returns always throw TypeError */ @Function(attributes = Attribute.NOT_ENUMERABLE) 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 --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/WithObject.java 2014-10-10 17:42:58.760720967 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/WithObject.java 2014-10-10 17:42:58.468719521 +0530 @@ -210,6 +210,19 @@ } @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 public void setSplitState(final int state) { getNonWithParent().setSplitState(state); } --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Messages.properties 2014-10-10 17:43:00.056727391 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Messages.properties 2014-10-10 17:42:59.768725976 +0530 @@ -73,6 +73,7 @@ type.error.not.an.object={0} is not an Object type.error.not.a.boolean={0} is not a Boolean 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.regexp={0} is not a RegExp type.error.not.a.string={0} is not a String --- /dev/null 2014-10-10 14:19:26.500390794 +0530 +++ new/test/script/basic/JDK-8060101.js 2014-10-10 17:43:00.872731439 +0530 @@ -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; + } + } +}