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
This commit is contained in:
parent
6f78befac9
commit
5f86cb4606
|
@ -46,17 +46,17 @@ SWITCH_MODULE_DEFINITION(mod_spidermonkey, mod_spidermonkey_load, mod_spidermonk
|
||||||
|
|
||||||
#define METHOD_SANITY_CHECK() do { \
|
#define METHOD_SANITY_CHECK() do { \
|
||||||
if (!jss || !jss->session) { \
|
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); \
|
*rval = BOOLEAN_TO_JSVAL(JS_FALSE); \
|
||||||
return JS_TRUE; \
|
return JS_FALSE; \
|
||||||
} \
|
} \
|
||||||
} while(foo == 1)
|
} while(foo == 1)
|
||||||
|
|
||||||
#define CHANNEL_SANITY_CHECK() do { \
|
#define CHANNEL_SANITY_CHECK() do { \
|
||||||
if (!switch_channel_ready(channel)) { \
|
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); \
|
*rval = BOOLEAN_TO_JSVAL(JS_FALSE); \
|
||||||
return JS_TRUE; \
|
return JS_FALSE; \
|
||||||
} \
|
} \
|
||||||
} while (foo == 1)
|
} while (foo == 1)
|
||||||
|
|
||||||
|
@ -838,6 +838,9 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
|
||||||
jsval argv[4];
|
jsval argv[4];
|
||||||
JSObject *Event = NULL;
|
JSObject *Event = NULL;
|
||||||
jsval nval , *rval = &nval;
|
jsval nval , *rval = &nval;
|
||||||
|
JSContext *cx = cb_state->cx;
|
||||||
|
JSObject *obj = cb_state->obj;
|
||||||
|
|
||||||
|
|
||||||
METHOD_SANITY_CHECK();
|
METHOD_SANITY_CHECK();
|
||||||
|
|
||||||
|
@ -2561,6 +2564,13 @@ JSClass fileio_class = {
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
static JSBool js_exit(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
|
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;
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,7 @@ struct js_session {
|
||||||
|
|
||||||
JSBool DEFAULT_SET_PROPERTY(JSContext * cx, JSObject *obj, jsval id, jsval *vp)
|
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;
|
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));
|
char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
|
||||||
|
|
||||||
if (strcmp(name, "_dB_RoW_DaTa_")) {
|
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);
|
*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
|
||||||
}
|
}
|
||||||
return JS_TRUE;
|
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));
|
char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
|
||||||
|
|
||||||
if (strcmp(name, "_oDbC_dB_RoW_DaTa_")) {
|
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);
|
*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
|
||||||
}
|
}
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
|
|
Loading…
Reference in New Issue