提交 5f86cb46 authored 作者: Anthony Minessale's avatar Anthony Minessale

add exceptions to js and make invalid session access fatal + exception for a try/catch

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5443 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 6f78befa
......@@ -46,17 +46,17 @@ SWITCH_MODULE_DEFINITION(mod_spidermonkey, mod_spidermonkey_load, mod_spidermonk
#define METHOD_SANITY_CHECK() do { \
if (!jss || !jss->session) { \
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "You must call the session.originate method before calling this method!\n"); \
eval_some_js("~throw new Error(\"You must call the session.originate method before calling this method!\");", cx, obj, rval); \
*rval = BOOLEAN_TO_JSVAL(JS_FALSE); \
return JS_TRUE; \
return JS_FALSE; \
} \
} while(foo == 1)
#define CHANNEL_SANITY_CHECK() do { \
if (!switch_channel_ready(channel)) { \
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session is not active!\n"); \
eval_some_js("~throw new Error(\"Session is not active!\");", cx, obj, rval); \
*rval = BOOLEAN_TO_JSVAL(JS_FALSE); \
return JS_TRUE; \
return JS_FALSE; \
} \
} while (foo == 1)
......@@ -838,6 +838,9 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
jsval argv[4];
JSObject *Event = NULL;
jsval nval , *rval = &nval;
JSContext *cx = cb_state->cx;
JSObject *obj = cb_state->obj;
METHOD_SANITY_CHECK();
......@@ -2561,6 +2564,13 @@ JSClass fileio_class = {
/*********************************************************************************/
static JSBool js_exit(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
char *supplied_error, code_buf[256] = "";
if (argc > 0 && (supplied_error = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
snprintf(code_buf, sizeof(code_buf), "~throw new Error(\"%s\");", supplied_error);
eval_some_js(code_buf, cx, obj, rval);
}
return JS_FALSE;
}
......
......@@ -145,6 +145,7 @@ struct js_session {
JSBool DEFAULT_SET_PROPERTY(JSContext * cx, JSObject *obj, jsval id, jsval *vp)
{
eval_some_js("~throw new Error(\"this property cannot be changed!\");", cx, obj, vp);
return JS_FALSE;
}
......
......@@ -247,6 +247,7 @@ static JSBool db_setProperty(JSContext * cx, JSObject * obj, jsval id, jsval *vp
char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
if (strcmp(name, "_dB_RoW_DaTa_")) {
eval_some_js("~throw new Error(\"this property cannot be changed!\");", cx, obj, vp);
*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
}
return JS_TRUE;
......
......@@ -433,6 +433,7 @@ static JSBool odbc_setProperty(JSContext * cx, JSObject * obj, jsval id, jsval *
char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
if (strcmp(name, "_oDbC_dB_RoW_DaTa_")) {
eval_some_js("~throw new Error(\"this property cannot be changed!\");", cx, obj, vp);
*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
}
return JS_TRUE;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论