Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda