Package org.mozilla.javascript

Examples of org.mozilla.javascript.ScriptableObject


*/
public final class Main {
    public static void main(String[] args) throws Exception {
        final Context context = Context.enter();
        try {
            final ScriptableObject global = context.initStandardObjects();
            final Module module = new Module("global", new File(System.getProperty("user.dir")));
            module.init(context, global);
        } finally {
            Context.exit();
        }
View Full Code Here


                interpreter.callHandler(function,
                    new RhinoInterpreter.ArgumentsBuilder() {
                        public Object[] buildArguments() {
                            try {
                                Object[] arguments = new Object[1];
                                ScriptableObject so =
                                    (ScriptableObject)interpreter.evaluate
                                    (new StringReader("new Object()"));
                                so.put("success", so,
                                       (success) ?
                                       Boolean.TRUE : Boolean.FALSE);
                                if (mime != null) {
                                    so.put("contentType", so,
                                           Context.toObject(mime,
                                                            windowWrapper));
                                }
                                if (content != null) {
                                    so.put("content", so,
                                           Context.toObject(content,
                                                            windowWrapper));
                                }
                                arguments[0] = so;
                                return arguments;
View Full Code Here

            try {
                interpreter.callMethod(object, COMPLETE,
                                       new RhinoInterpreter.ArgumentsBuilder() {
                                           public Object[] buildArguments() {
                                               Object[] arguments = new Object[1];
                                               ScriptableObject so =
                                                   new NativeObject();
                                               so.put("success", so,
                                                      (success) ?
                                                      Boolean.TRUE : Boolean.FALSE);
                                               if (mime != null) {
                                                   so.put("contentType", so,
                                                          Context.toObject(mime,
                                                                           windowWrapper));
                                               }
                                               if (content != null) {
                                                   so.put("content", so,
                                                          Context.toObject(content,
                                                                           windowWrapper));
                                               }
                                               arguments[0] = so;
                                               return arguments;
View Full Code Here

                interpreter.callHandler(function,
                    new RhinoInterpreter.ArgumentsBuilder() {
                        public Object[] buildArguments() {
                            try {
                                Object[] arguments = new Object[1];
                                ScriptableObject so =
                                    (ScriptableObject)interpreter.evaluate
                                    (new StringReader("new Object()"));
                                so.put("success", so,
                                       (success) ?
                                       Boolean.TRUE : Boolean.FALSE);
                                if (mime != null) {
                                    so.put("contentType", so,
                                           Context.toObject(mime,
                                                            windowWrapper));
                                }
                                if (content != null) {
                                    so.put("content", so,
                                           Context.toObject(content,
                                                            windowWrapper));
                                }
                                arguments[0] = so;
                                return arguments;
View Full Code Here

public class SlingContext extends Context {

    @Override
    public ScriptableObject initStandardObjects(ScriptableObject scope,
            boolean sealed) {
        ScriptableObject rootScope = super.initStandardObjects(scope, sealed);

        // add Sling global objects
        SlingGlobal.init(rootScope, sealed);

        return rootScope;
View Full Code Here

            for (Class<?> clazz : HOSTOBJECT_CLASSES) {
                try {

                    // register the host object
                    ScriptableObject.defineClass(rootScope, clazz);
                    final ScriptableObject host = (ScriptableObject) clazz.newInstance();

                    if (SlingWrapper.class.isAssignableFrom(clazz)) {
                        // SlingWrappers can map to several classes if needed
                        final SlingWrapper hostWrapper = (SlingWrapper) host;
                        for (Class<?> c : hostWrapper.getWrappedClasses()) {
                            SlingWrapFactory.INSTANCE.registerWrapper(c,
                                hostWrapper.getClassName());
                        }
                    } else {
                        // but other ScriptableObjects need to be registered as
                        // well
                        SlingWrapFactory.INSTANCE.registerWrapper(
                            host.getClass(), host.getClassName());
                    }
                } catch (Throwable t) {
                    log.warn("getRootScope: Cannot prepare host object " + clazz, t);
                }
            }
View Full Code Here

        // create a rhino Context and execute the script
        try {
           
            final Context rhinoContext = Context.enter();
            final ScriptableObject scope = new NativeObject();

            // Set the global scope to be our prototype
            scope.setPrototype(rootScope);

            // We want "scope" to be a new top-level scope, so set its parent
            // scope to null. This means that any variables created by assignments
            // will be properties of "scope".
            scope.setParentScope(null);

            // setup the context for use
            rhinoContext.setWrapFactory(SlingWrapFactory.INSTANCE);

            // add initial properties to the scope
View Full Code Here

        // build the code, something like
        //  data = <jsonData> ;
        //  <code>
        final String jsCode = "data=" + jsonData + ";\n" + code;
        final Context rhinoContext = Context.enter();
        final ScriptableObject scope = rhinoContext.initStandardObjects();

        // execute the script, out script variable maps to sw
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        ScriptableObject.putProperty(scope, "out", Context.javaToJS(pw, scope));
View Full Code Here

        }

        public XLoper execute(IFunctionContext context, XLoper[] args) throws RequestException {
            Context ctx = Context.enter();
            Object[] oargs = converter.convert(args, BSFScript.createArgHints(args));
            ScriptableObject so = ctx.initStandardObjects();
            Scriptable argsObj = ctx.newArray(so, oargs);
            so.defineProperty("args", argsObj, ScriptableObject.DONTENUM);
            try {
                return converter.createFrom(script.exec(ctx, so));
            } catch (Throwable t) {
                throw new RequestException(t.getMessage());
            }
View Full Code Here

    @Override
    public Object evaluate(String script, String filename, Map<String, Object> args)
            throws ScriptException, Throwable {
        RhinoContextFactory factory = new RhinoContextFactory(timeLimit);
        Context cx = factory.enterContext();
        ScriptableObject scriptable = new ImporterTopLevel(cx);
        Scriptable scope = cx.initStandardObjects(scriptable);

        for (Map.Entry<String, Object> entry : args.entrySet()) {
            ScriptableObject.putProperty(scope, entry.getKey(),
                    Context.javaToJS(entry.getValue(), scope));
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ScriptableObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.