1212import com .orientechnologies .orient .core .metadata .function .OFunction ;
1313import com .orientechnologies .orient .core .metadata .security .ORole ;
1414import com .orientechnologies .orient .core .metadata .security .ORule ;
15- import com .orientechnologies .orient .core .sql .executor .OResultInternal ;
1615import com .orientechnologies .orient .core .sql .executor .OResultSet ;
1716import java .util .ArrayList ;
1817import java .util .HashMap ;
@@ -168,23 +167,7 @@ public Object executeFunction(
168167
169168 Value result = ctx .eval (language , scriptManager .getFunctionInvoke (f , args ));
170169
171- Object finalResult ;
172- if (result .isNull ()) {
173- finalResult = null ;
174- } else if (result .hasArrayElements ()) {
175- final List <Object > array = new ArrayList <>((int ) result .getArraySize ());
176- for (int i = 0 ; i < result .getArraySize (); ++i )
177- array .add (new OResultInternal (result .getArrayElement (i ).asHostObject ()));
178- finalResult = array ;
179- } else if (result .isHostObject ()) {
180- finalResult = result .asHostObject ();
181- } else if (result .isString ()) {
182- finalResult = result .asString ();
183- } else if (result .isNumber ()) {
184- finalResult = result .asDouble ();
185- } else {
186- finalResult = result ;
187- }
170+ Object finalResult = toObject (result );
188171 scriptManager .unbind (null , bindings , null , null );
189172 return finalResult ;
190173 } catch (PolyglotException e ) {
@@ -197,6 +180,27 @@ public Object executeFunction(
197180 }
198181 }
199182
183+ protected Object toObject (Value result ) {
184+ Object finalResult ;
185+ if (result .isNull ()) {
186+ finalResult = null ;
187+ } else if (result .hasArrayElements ()) {
188+ final List <Object > array = new ArrayList <>((int ) result .getArraySize ());
189+ for (int i = 0 ; i < result .getArraySize (); ++i )
190+ array .add (toObject (result .getArrayElement (i )));
191+ finalResult = array ;
192+ } else if (result .isHostObject ()) {
193+ finalResult = result .asHostObject ();
194+ } else if (result .isString ()) {
195+ finalResult = result .asString ();
196+ } else if (result .isNumber ()) {
197+ finalResult = result .asDouble ();
198+ } else {
199+ finalResult = transformer .toResult (result );
200+ }
201+ return finalResult ;
202+ }
203+
200204 @ Override
201205 public void close (String iDatabaseName ) {
202206 OResourcePool <ODatabaseDocumentInternal , Context > contextPool =
0 commit comments