Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
Do GraalVM JavaScript's JS-to-Java object conversions contain type information?

To mimic on GraalVM JavaScript some of Node's functions under util.types, I turned to Java functions that I can access through Java.type or the Java package global variables. GraalVM's has internal functions like JSProxy.isJSProxy and JSSet.isJSSet that do this. I made them accessible by marking them as a exported, recompiled, and tested them (I accessed them with, e.g., Java.type("com.oracle.truffle.js.builtins.runtime.JSProxy").isJSProxy).

As I found out, GraalVM JavaScript's internal functions are useless to me. For example, JSProxy.isJSProxy only returns true if it is passed an instance of JSProxyObject. Oracle's documentation says that

JavaScript objects are exposed to Java code as instances of com.oracle.truffle.api.interop.java.TruffleMap. This class implements Java’s Map interface.

TruffleMap doesn't appear in the source code of GraalVM JavaScript and only appears once in the source code of GraalVM, so it's likely deprecated, but that's besides the point because the representation method is probably the same.

Whatever the external Java-side representation of JS objects is right now, does it contain information about what the object's type on the JavaScript side is? Can I determine if it's a JS proxy? Can I determine if it's a Set object? (And so on for native JavaScript object types.)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To be honest your question is quite confusing to me, but are you just looking for the instanceof operator?

import org.graalvm.polyglot.*;
import org.graalvm.polyglot.proxy.*;

public class Test {
    public static class MyClass {
        public int id = 42;
    }

    public static void main(String[] args) {
       try (Context context = Context.newBuilder().allowAllAccess(true).build()) {
            context.getBindings("js").putMember("javaObj", new MyClass());
            boolean valid = context
              .eval("js", "javaObj instanceof Java.type('Test$MyClass')")
              .asBoolean();
            assert valid;
        }
    }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda