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

208
Visualizações
Return Rhino ScriptableObject as primitive value

I'm using an old Mozilla Rhino library (version 1.7.7.1) in my project and I'm struggling to understand how to implement the host object hierarchy properly.

What I'm trying to do is to have a root host object containing a field which is another Scriptable. This field contains an inner map with String keys and another Scriptable object (Map<String, ListObject>). The ListObject contains an inner String collection and custom functions.

I've created an example code which contains the example of the host object and the fields. The repository is here. The included test can be run with mvn test command.

When I try to run the following code everything works as expected:

var objectMap_foo_0 = root.objectMap['foo'][0];
var objectMap_foo_0_split = objectMap_foo_0.split('|');

The root.objectMap['foo'][0] returns string and I can call javascript split function on it.

But I need to be able to run the following as well:

// should return first value in the inner collection as a default and do split on it
var objectMap_foo = root.objectMap['foo'];
// call custom method (length() in this case)
print(objectMap_foo.length());
var objectMap_foo_split = objectMap_foo.split('|');

The root.objectMap['foo'] should return the first value in the inner collection (which is a string) but right now it returns the ListObject object. The current solution lets me call the custom function length() on the object but I'm not able to use the split function as the returned value is not of type string. The error message I get when running the code above is:

org.mozilla.javascript.EcmaError: TypeError: Cannot find function split in object bar|baz. (script.js#14)

Can someone please help me to achieve the desired functionality so both the custom function length() and the javascript split() function can be used?

about 4 years ago · Juan Pablo Isaza
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