Skip to content

Commit

Permalink
app_jsdt: restore JS stack after executing a function
Browse files Browse the repository at this point in the history
(cherry picked from commit acb90b6)
(cherry picked from commit 484d096)
  • Loading branch information
miconda committed Jul 13, 2018
1 parent ed100ad commit 47f13ee
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/modules/app_jsdt/app_jsdt_api.c
Expand Up @@ -737,6 +737,7 @@ int app_jsdt_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2,
int ret;
str txt;
sip_msg_t *bmsg;
duk_idx_t jtop;

if(_sr_J_env.JJ==NULL) {
LM_ERR("js loading state not initialized (call: %s)\n", func);
Expand All @@ -746,7 +747,8 @@ int app_jsdt_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2,
jsdt_kemi_reload_script();

LM_DBG("executing js function: [[%s]]\n", func);
LM_DBG("js top index is: %d\n", duk_get_top(_sr_J_env.JJ));
jtop = duk_get_top(_sr_J_env.JJ);
LM_DBG("js top index is: %d\n", (int)jtop);
duk_get_global_string(_sr_J_env.JJ, func);
if(!duk_is_function(_sr_J_env.JJ, -1))
{
Expand All @@ -756,8 +758,10 @@ int app_jsdt_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2,
duk_get_type(_sr_J_env.JJ, -1));
txt.s = (char*)duk_to_string(_sr_J_env.JJ, -1);
LM_ERR("error from JS: %s\n", (txt.s)?txt.s:"unknown");
duk_set_top(_sr_J_env.JJ, jtop);
return -1;
} else {
duk_set_top(_sr_J_env.JJ, jtop);
return 1;
}
}
Expand Down Expand Up @@ -807,15 +811,16 @@ int app_jsdt_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2,
LM_ERR("error from js: unknown\n");
}
}
duk_pop(_sr_J_env.JJ);
if(n==1) {
duk_set_top(_sr_J_env.JJ, jtop);
return 1;
} else {
LM_ERR("error executing: %s (err: %d)\n", func, ret);
duk_set_top(_sr_J_env.JJ, jtop);
return -1;
}
}
duk_pop(_sr_J_env.JJ);
duk_set_top(_sr_J_env.JJ, jtop);

return 1;
}
Expand Down

0 comments on commit 47f13ee

Please sign in to comment.