Package booton.translator

Examples of booton.translator.Javascript


     * @param scriptable A target scriptable source.
     */
    final Object executeAsJavascript(Method method) {
        Class source = method.getDeclaringClass();
        String sourceName = source.getSimpleName();
        Javascript script = Javascript.getScript(source);

        try {
            // compile as Javascript
            String compiled = script.write(defined);

            // script engine read it
            engine.execute(html, compiled, sourceName, 1);

            // write test script
            String wraped = Javascript.writeMethodCode(Throwable.class, "wrap", Object.class, "e");
            String encode = Javascript.writeMethodCode(ClientStackTrace.class, "encode", Throwable.class, wraped);
            String invoker = "try {" + Javascript.writeMethodCode(source, method.getName()) + ";} catch(e) {" + encode + ";}";

            // invoke test script
            Object result = engine.execute(html, invoker, sourceName, 1);

            if (result == null || result instanceof Undefined || result instanceof UniqueTag) {
                return null; // success
            } else {
                // fail (AssertionError) or error

                // decode as Java's error and rethrow it
                Source code = new Source(sourceName, compiled.length() != 0 ? compiled : script.write());
                Throwable throwable = ClientStackTrace.decode((String) result, code);

                if (throwable instanceof AssertionError || throwable instanceof InternalError) {
                    dumpCode(code);

                    throwable = new PowerAssertOffError(throwable);
                }
                throw I.quiet(throwable);
            }
        } catch (ScriptException e) {
            dumpCode(source);
            // script parse error (translation fails) or runtime error
            Source code = new Source(sourceName, script.write());

            if (e.getScriptSourceCode() == null) {
                Throwable cause = e.getCause();

                if (cause instanceof EcmaError) {
View Full Code Here

TOP

Related Classes of booton.translator.Javascript

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.