Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem running javascript code in rhino

28 views
Skip to first unread message

chris idr

unread,
Sep 24, 2008, 9:00:18 AM9/24/08
to rhino Dev
HI I am trying to run this code:
global.currentHangManWord = "a word of any sort";
var curChar = "";
curChar = global.currentHangManWord.charAt(pos-1);
within rhino.

I have added the global object via
Object globalObj = cx.newObject(scope);
org.mozilla.javascript.ScriptableObject.putProperty( scope, "global",
globalObj );

then i call the script code.
Object result = cx.evaluateString(scope, code, "<javascript>", 1, null);

NOTES: cx is a Context object.

PROBLEM :
i keep getting this error
TypeError: Cannot call method "charAt" of undefined (<javascript>#8)
executing code=


can anyone enlighten me as to what i am doing wrong please?

Kind Regards

Chris Wade


chris idr

unread,
Sep 27, 2008, 5:17:21 AM9/27/08
to rhino Dev

carlos

unread,
Oct 3, 2008, 8:03:05 AM10/3/08
to

hey chris,
Sounds like your context finds in your scope object (walking down to
find the base) some global property...
that's why it is not registered on top level;
try this instead; if scope is your top level scope, than
scope.put("global", scope, globalObj );

should work that way..
cheers
carlos

0 new messages