RPA Toolkit
RJS code segments reused
authorMartin Stoilov <martin@rpasearch.com>
Mon, 16 May 2011 06:59:12 +0000 (23:59 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Mon, 16 May 2011 06:59:12 +0000 (23:59 -0700)
rjs/rjs.c
tests/testrjs/rjs-simple.c

index 6176100..c92d788 100644 (file)
--- a/rjs/rjs.c
+++ b/rjs/rjs.c
@@ -47,7 +47,7 @@ void rjs_engine_destroy(rjs_engine_t *jse)
        rlong i;
        if (jse) {
                for (i = 0; i < r_array_length(jse->cgs); i++) {
-//                     rvm_codegen_destroy(r_array_index(jse->cgs, i, rvm_codegen_t*));
+                       rvm_codegen_destroy(r_array_index(jse->cgs, i, rvm_codegen_t*));
                }
                r_array_destroy(jse->cgs);
                rjs_parser_destroy(jse->pa);
@@ -84,14 +84,12 @@ rint rjs_engine_compile(rjs_engine_t *jse, const rchar *script, rsize_t size)
        }
 
        topcg =  r_array_empty(jse->cgs) ? NULL : r_array_last(jse->cgs, rvm_codegen_t*);
-       if (!topcg || (topcg->userdata & RJS_COMPILER_CODEGENKEEP) == 0) {
+       if (!topcg || (topcg->userdata & RJS_COMPILER_CODEGENKEEP) == 1) {
                topcg = rvm_codegen_create();
                r_array_add(jse->cgs, &topcg);
        } else {
-               topcg->userdata = 0;
                rvm_codegen_clear(topcg);
        }
-       r_printf("cgs size: %ld\n", r_array_length(jse->cgs));
        topcg->userdata = 0;
        if (rjs_compiler_compile(jse->co, records, topcg) < 0) {
                topcg->userdata = 0;
index 3a9c74b..91e57de 100644 (file)
 int main(int argc, char *argv[])
 {
        rjs_engine_t *jse = rjs_engine_create();
-       rchar test_script1[] = "(2+3)*3;";
-       rchar test_script2[] = "var person = new Object(); person.name = 'Martin'; person.age = 25; person.job = 'slacker';";
+       char test_script1[] = "(2+3)*3;";
+       char test_script2[] = "function person(name, age, job) {this.name = name; this.age = age; this.job = job;} var me = new person('Martin', 25, 'Slacker');";
 
 //     jse->debugexec = 1;
-       r_printf("script: %s, result: %ld\n", test_script1, rvm_reg_long(rjs_engine_exec_s(jse, test_script1)));
+       r_printf("script: %s result: %ld\n", test_script1, rvm_reg_long(rjs_engine_exec_s(jse, test_script1)));
        rjs_engine_exec_s(jse, test_script2);
-       r_printf("Name: %s\n", r_string_ansi(rvm_reg_string(rjs_engine_exec_s(jse, "person.name;"))));
-       r_printf("Job: %s\n", r_string_ansi(rvm_reg_string(rjs_engine_exec_s(jse, "person.job;"))));
-
+       r_printf("Name: %s\n", r_string_ansi(rvm_reg_string(rjs_engine_exec_s(jse, "me.name;"))));
+       r_printf("Job: %s\n", r_string_ansi(rvm_reg_string(rjs_engine_exec_s(jse, "me.job;"))));
+       r_printf("Description: %s\n", r_string_ansi(rvm_reg_string(rjs_engine_exec_s(jse, "'Name = ' + me.name + ', Job = ' + me.job;"))));
        rjs_engine_destroy(jse);
        return 0;
 }