Using rhino on Android, how should I get the function(Member) handle of JS

46 views
Skip to first unread message

jackor liao

unread,
Aug 12, 2023, 10:49:52 PM8/12/23
to mozilla-rhino

I try to use opentype.js in android, there is a function like this:

opentype.Font.prototype.stringToGlyphIndexes = function (s, options) { 
         .... 
        return bidi.getTextGlyphs(s);
 };

i don't know how to call it in Java. I try to call it using executeJSFunction function like this:

Function function = (Function) scope.get("stringToGlyphIndexes", scope);
function.call(rhino, scope, scope, new String[]{"Test"});

but Logcat gives an error message of TypeError: undefined is not a function. How should I call this JS function?

P

unread,
Oct 23, 2023, 9:16:51 AM10/23/23
to mozilla-rhino
Calling JavaScript functions from Java is described here: https://rhino.github.io/tutorials/embedding_tutorial/#calling-javascript-functions

But, if you get a 'TypeError: undefined is not a function' error, it seems to me that  scope.get("stringToGlyphIndexes"scope)
 doesn't return a value at all. 

Not knowing opentype.js at all, but just looking at the snippet you provided, it seems you first need to have a reference to opentype.Font, as stringToGlyphIndexes  is a method on opentype.Font
Reply all
Reply to author
Forward
0 new messages