// Copyright (c) 2012 Johannes Zellner webmaster@nebulon.de - All Rights Reserved

"use strict";

/*
 **************************************************
 * QuickJS Helper
 **************************************************
 */

// ensure namespace
if (!Quick) {
    var Quick = {};
}

Quick.debug = false;
Quick.verbose = false;

Quick.useQueryFlags = function() {
    // TODO improve detection
    Quick.verbose = (window.location.href.indexOf("verbose") >= 0);
    Quick.debug = (window.location.href.indexOf("debug") >= 0);
}

Quick.compileScriptTagElement = function(script) {
    var tokens = Quick.Tokenizer.parse(script.text);
    Quick.Compiler.render(tokens, function (error, result) {
        if (error) {
            console.log("Error rendering JavaScript on line " + error.line + ": " + error.message);
            console.log(" -- " + error.context);
        } else {
            try {
                console.log("----------------------");
                console.log(result);
                console.log("----------------------");
                eval(result);
            } catch (e) {
                console.log("Error evaluating generated JS code: " + e);
            }
        }
    });
}

Quick.compileScriptTags = function(scriptType) {
    var type = scriptType ? scriptType : "text/jml";

    for (var i = 0; i < window.document.scripts.length; ++i) {
        var script = window.document.scripts[i];
        if (script.type === type) {
            Quick.compileScriptTagElement(script);
        }
    }
}

@@ -1060,19 +1060,201 @@
     
-eval(result
+console.log(%22eval...%22);%0A                var o = new Date();%0A                eval(result);%0A                var n = new Date();%0A                console.log(%22done, eval took time: %22, (n - o), %22ms%22
 );%0A 

add some debug output to quick helper