On Feb 1, 11:29 am, [EMAIL PROTECTED] wrote:
> Great that is exactly what I am looking for.  I even created an
> interface to specify the function signatures.  However:
>
> Java Program:
> public class trigger {
>
>     public static void main(String[] args) {
>         test e = new test();
>         System.out.println("Sum: " + e.sum(10, 20));
>         System.out.println("Times: " + e.times(10, 20));
>      }
>
> }
>
> when executing it:
>
> java trigger
>
> results in:
>
> Exception in thread "main" java.lang.RuntimeException: No Context
> associated with current Thread
>          at org.mozilla.javascript.Context.getContext(Context.java:2277)
>          at org.mozilla.javascript.JavaMembers.<init>(JavaMembers.java:68)
>          at
> org.mozilla.javascript.JavaMembers.lookupClass(JavaMembers.java:759)
>          at
> org.mozilla.javascript.NativeJavaObject.initMembers(NativeJavaObject.java:90)
>          at
> org.mozilla.javascript.NativeJavaObject.<init>(NativeJavaObject.java:80)
>          at
> org.mozilla.javascript.JavaAdapter.createAdapterWrapper(JavaAdapter.java:145)
>          at test.<init>(<adapter>)
>          at trigger.main(trigger.java:4)
>
> Interface:
> public interface sample {
>      public int sum(int a, int b);
>      public int times(int a, int b);
>
> }
>
> Javascript:
> function sum(a, b) {
>    return a+b;
>
> }
>
> function times(a, b) {
>    return a*b;
>
> }
>
> JSC:
> java org.mozilla.javascript.tools.jsc.Main -extends java.lang.Object
> -implements sample test.js
>
> javap test
> Compiled from "<adapter>"
> public class test extends java.lang.Object implements sample{
>      public final org.mozilla.javascript.ContextFactory factory;
>      public final org.mozilla.javascript.Scriptable delegee;
>      public final org.mozilla.javascript.Scriptable self;
>      public test(org.mozilla.javascript.ContextFactory,
> org.mozilla.javascript.Scriptable);
>      public test(org.mozilla.javascript.ContextFactory,
> org.mozilla.javascript.Scriptable, org.mozilla.javascript.Scriptable);
>      public test();
>      public int sum(int, int);
>      public int times(int, int);
>
> }
>
> Thanks,
> -Edwin S. Ramirez

Yes, that's correct; you'll need to have a Context associated with the
current thread. Rhino uses this to maintain runtime information. See
http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/Context.html,
in particular the call(ContextAction) or enter() methods.

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

Reply via email to