Hi,

I try with this:

                                Context context = Context.enter();
                                ScriptableObject scope = 
context.initStandardObjects();

                                ....

                                CompilerEnvirons compilerEnv = new 
CompilerEnvirons();
                                compilerEnv.initFromContext(context);
                                compilerEnv.setGenerateDebugInfo(true);
                                variableElement.setScript("function 
test(){return \"hello
\";}");
                                ClassCompiler compiler = new 
ClassCompiler(compilerEnv);
                                
compiler.setMainMethodClass(variableElement.getName());
                                Object[] classes = compiler.compileToClassFiles
(variableElement.getScript(), variableElement.getName(), 0,
variableElement.getName());

                                GeneratedClassLoader loader = 
context.createClassLoader
(context.getApplicationClassLoader());

                                Class<?> clazz = null;
                                 for (int i = 0; i < classes.length; i += 2) {
                        final String clazzName = (String) classes[i];
                        final byte[] clazzBytes = (byte[]) classes[i
+1];
                        Class<?> c = loader.defineClass(clazzName,
clazzBytes);
                        loader.linkClass(c);
                        if (i == 0) {
                            clazz = c;
                        }
                    }
                    Script scriptObject = (Script)Context.javaToJS
(clazz.newInstance(), scriptableObject);
                    ScriptableObject.putProperty(scriptableObject,
"myObject", scriptObject);
                    Script scriptObject2 = (Script)
context.compileString("myObject.test();","script",0,null);
                                        scriptObject2.exec(context, 
scriptableObject);

But the intrepeter don't found the function "test()" in the script
object "myObject".

Someone can tell me if this is possible?

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

Reply via email to