aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jdk/nashorn/internal/objects/NativeJavaImporter.java5
-rw-r--r--src/jdk/nashorn/internal/runtime/NativeJavaPackage.java37
-rw-r--r--src/jdk/nashorn/internal/runtime/ScriptObject.java3
3 files changed, 31 insertions, 14 deletions
diff --git a/src/jdk/nashorn/internal/objects/NativeJavaImporter.java b/src/jdk/nashorn/internal/objects/NativeJavaImporter.java
index 3e46a2c7..56baf66d 100644
--- a/src/jdk/nashorn/internal/objects/NativeJavaImporter.java
+++ b/src/jdk/nashorn/internal/objects/NativeJavaImporter.java
@@ -134,6 +134,11 @@ public final class NativeJavaImporter extends ScriptObject {
return createAndSetProperty(desc) ? super.lookup(desc, request) : super.noSuchMethod(desc, request);
}
+ @Override
+ protected Object invokeNoSuchProperty(final String name) {
+ return createProperty(name);
+ }
+
private boolean createAndSetProperty(final CallSiteDescriptor desc) {
final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
final Object value = createProperty(name);
diff --git a/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java b/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java
index 534d495c..591fd327 100644
--- a/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java
+++ b/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java
@@ -198,8 +198,26 @@ public final class NativeJavaPackage extends ScriptObject {
@Override
public GuardedInvocation noSuchProperty(final CallSiteDescriptor desc, final LinkRequest request) {
final String propertyName = desc.getNameToken(2);
- final String fullName = name.isEmpty() ? propertyName : name + "." + propertyName;
+ createProperty(propertyName);
+ return super.lookup(desc, request);
+ }
+
+ @Override
+ protected Object invokeNoSuchProperty(final String name) {
+ return createProperty(name);
+ }
+
+ @Override
+ public GuardedInvocation noSuchMethod(final CallSiteDescriptor desc, final LinkRequest request) {
+ return noSuchProperty(desc, request);
+ }
+
+ private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
+ return MH.findStatic(MethodHandles.lookup(), NativeJavaPackage.class, name, MH.type(rtype, types));
+ }
+ private Object createProperty(final String propertyName) {
+ final String fullName = name.isEmpty() ? propertyName : name + "." + propertyName;
final Context context = Context.getContextTrusted();
Class<?> javaClass = null;
@@ -209,21 +227,14 @@ public final class NativeJavaPackage extends ScriptObject {
//ignored
}
+ final Object propertyValue;
if (javaClass == null) {
- set(propertyName, new NativeJavaPackage(fullName, getProto()), false);
+ propertyValue = new NativeJavaPackage(fullName, getProto());
} else {
- set(propertyName, StaticClass.forClass(javaClass), false);
+ propertyValue = StaticClass.forClass(javaClass);
}
- return super.lookup(desc, request);
- }
-
- @Override
- public GuardedInvocation noSuchMethod(final CallSiteDescriptor desc, final LinkRequest request) {
- return noSuchProperty(desc, request);
- }
-
- private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
- return MH.findStatic(MethodHandles.lookup(), NativeJavaPackage.class, name, MH.type(rtype, types));
+ set(propertyName, propertyValue, false);
+ return propertyValue;
}
}
diff --git a/src/jdk/nashorn/internal/runtime/ScriptObject.java b/src/jdk/nashorn/internal/runtime/ScriptObject.java
index 152681a6..4b85ed4e 100644
--- a/src/jdk/nashorn/internal/runtime/ScriptObject.java
+++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java
@@ -2093,12 +2093,13 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
return createEmptyGetter(desc, name);
}
+
/**
* Invoke fall back if a property is not found.
* @param name Name of property.
* @return Result from call.
*/
- private Object invokeNoSuchProperty(final String name) {
+ protected Object invokeNoSuchProperty(final String name) {
final FindProperty find = findProperty(NO_SUCH_PROPERTY_NAME, true);
if (find != null) {