Module: kamailio
Branch: master
Commit: acb90b6634e65a21c655e9bb94c1af00c138e6d4
URL:
https://github.com/kamailio/kamailio/commit/acb90b6634e65a21c655e9bb94c1af0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-07-09T15:41:59+02:00
app_jsdt: restore JS stack after executing a function
---
Modified: src/modules/app_jsdt/app_jsdt_api.c
---
Diff:
https://github.com/kamailio/kamailio/commit/acb90b6634e65a21c655e9bb94c1af0…
Patch:
https://github.com/kamailio/kamailio/commit/acb90b6634e65a21c655e9bb94c1af0…
---
diff --git a/src/modules/app_jsdt/app_jsdt_api.c b/src/modules/app_jsdt/app_jsdt_api.c
index ff9f2ad19d..224d54bfe6 100644
--- a/src/modules/app_jsdt/app_jsdt_api.c
+++ b/src/modules/app_jsdt/app_jsdt_api.c
@@ -770,6 +770,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);
@@ -779,7 +780,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))
{
@@ -789,8 +791,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;
}
}
@@ -840,15 +844,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;
}