git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3696 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West committed 2006-12-18 18:10:31 +00:00
1 parent dee025e15e
commit b9245b3fe4
8 files changed
+52 -130

No files matched your search

@@ -76,7 +76,35 @@ SWITCH_BEGIN_EXTERN_C
#define SWITCH_SM_DECLARE(type) type
#endif
SWITCH_SM_DECLARE(int) eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval);
static int eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval)
{
JSScript *script = NULL;
char *cptr;
char *path = NULL;
int res = 0;
JS_ClearPendingException(cx);
if (code[0] == '~') {
cptr = code + 1;
script = JS_CompileScript(cx, obj, cptr, strlen(cptr), "inline", 1);
} else {
if (*code == '/') {
script = JS_CompileFile(cx, obj, code);
} else if ((path = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR, code))) {
script = JS_CompileFile(cx, obj, path);
switch_safe_free(path);
}
}
if (script) {
res = JS_ExecuteScript(cx, obj, script, rval) == JS_TRUE ? 1 : 0;
JS_DestroyScript(cx, script);
}
return res;
}
typedef switch_status_t(*spidermonkey_load_t)(JSContext *cx, JSObject *obj);