Skip to content

Support for instanceof of ProxyInstantiable #40

Open
@provegard

Description

@provegard

I'm exposing a "type object" that implements ProxyInstantiable. I wan't to be able to check if the instance returned from newInstance is actually an instance of the type object.

Here's my code:

public class MainType {
    public static void main(String[] args) {
        Context context = Context.create("js");

        context.getBindings("js").putMember("MyType", new TypeLike());

        String src = "var instance = new MyType();\n" +
                "print(instance instanceof MyType);";
        context.eval("js", src);
    }

    public static class TypeLike implements ProxyInstantiable {
        @Override
        public Object newInstance(Value... arguments) {
            return new InstanceLike();
        }
    }

    public static class InstanceLike implements ProxyObject {

        @Override
        public Object getMember(String key) {
            return null;
        }

        @Override
        public Object getMemberKeys() {
            return new String[0];
        }

        @Override
        public boolean hasMember(String key) {
            return false;
        }

        @Override
        public void putMember(String key, Value value) {

        }
    }
}

It prints:

Exception in thread "main" TypeError: Right-hand-side of instanceof is not an object
	at <js> :program(Unnamed:2:35-60)
	at org.graalvm.polyglot.Context.eval(Context.java:336)
	at com.programmaticallyspeaking.gho.MainType.main(MainType.java:16)

I also tried to implement ProxyObject on the host type class, but I get the same result.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestinteropPolyglot Language Interoperability

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions