I tried to execute such code:

  final Scriptable scope = cx.initStandardObjects();
  final Script json = cx.compileString(JSON_CODE, "JSON", 1, null);
  scope.put("JSON", scope, json);
  scope.put("args", scope, params);
  final Function script = cx.compileFunction(scope, code, "main", 1,
null);
  return Context.toString(script.call(cx, scope, scope, null));

Where JSON_CODE is a string which contains JSON JavaScript code.
"params" - string with json object. (for example: { "name":"test22"})
"code" is my cusomt JS function:

function main() {
  var myJSON = eval('('+args+')');
  return JSON.stringify(myJSON));
}

And it doesn't work. I received:

org.mozilla.javascript.EcmaError: TypeError: Cannot find default value
for object. (main#3)

On 6 июл, 00:21, Attila Szegedi <[EMAIL PROTECTED]> wrote:
> On Jul 5, 2008, at 10:48 PM, DarkIT wrote:
>
> > Thank's
> > But how can i include this library to rhino ? that all other functions
> > in different contexts and scopes can use it.
>
> Well, simplest approach is: you can load it into a Script object, and  
> then execute it in a scope, and then execute the Script object  
> representing your actual program in the same scope object.
>
> > Also it's more general question how can I write Java and JavaScript
> > function which can comunicate without efforts - just write "brigde"
> > which will do all work for given object type.
>
> Well, Rhino does quite a lot of automatic marshaling of values from JS  
> to Java and back already. I think you'd find what's in there already  
> will be sufficient.
>
> Attila.

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to